_group.html.haml_spec.rb 12 KB
Newer Older
1 2
# frozen_string_literal: true

3 4
require 'spec_helper'

5
RSpec.describe 'layouts/nav/sidebar/_group' do
6
  before do
7
    assign(:group, group)
8
    allow(view).to receive(:show_trial_status_widget?).and_return(false)
9 10
  end

11
  let(:group) { create(:group) }
12
  let(:user) { create(:user) }
13

14
  describe 'trial status widget', :aggregate_failures do
15 16
    using RSpec::Parameterized::TableSyntax

17
    let(:experiment_key) { :show_trial_status_in_sidebar }
18
    let(:show_widget) { false }
19
    let(:experiment_enabled) { false }
20

21
    before do
22
      allow(view).to receive(:show_trial_status_widget?).and_return(show_widget)
23 24
      allow(view).to receive(:experiment_enabled?).with(experiment_key, subject: group).and_return(experiment_enabled)
      allow(view).to receive(:record_experiment_group)
25 26 27
      allow(view).to receive(:trial_status_widget_data_attrs)
      allow(view).to receive(:trial_status_popover_data_attrs)
      render
28 29
    end

30 31 32 33
    subject do
      render
      rendered
    end
34

35
    shared_examples 'does not render the widget & popover' do
36 37 38
      it 'does not render' do
        is_expected.not_to have_selector '#js-trial-status-widget'
        is_expected.not_to have_selector '#js-trial-status-popover'
39 40 41
      end
    end

42
    shared_examples 'renders the widget & popover' do
43 44 45 46
      it 'renders both the widget & popover component initialization elements' do
        is_expected.to have_selector '#js-trial-status-widget'
        is_expected.to have_selector '#js-trial-status-popover'
      end
47
    end
48

49 50 51
    shared_examples 'does record experiment subject' do
      it 'records the group as an experiment subject' do
        expect(view).to receive(:record_experiment_group).with(experiment_key, group)
52

53 54 55 56 57 58 59
        subject
      end
    end

    shared_examples 'does not record experiment subject' do
      it 'does not record the group as an experiment subject' do
        expect(view).not_to receive(:record_experiment_group)
60

61 62 63 64
        subject
      end
    end

65
    where :show_widget, :experiment_enabled, :examples_to_include do
66 67 68 69
      true  | true  | ['does record experiment subject', 'renders the widget & popover']
      true  | false | ['does record experiment subject', 'does not render the widget & popover']
      false | true  | ['does not record experiment subject', 'does not render the widget & popover']
      false | false | ['does not record experiment subject', 'does not render the widget & popover']
70 71
    end

72
    with_them do
73 74 75
      params[:examples_to_include].each do |example_set|
        include_examples(example_set)
      end
76
    end
77
  end
78

79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
  describe 'Epics menu' do
    let_it_be(:user) { create(:user) }
    let_it_be(:group) do
      create(:group).tap do |g|
        g.add_maintainer(user)
      end
    end

    before do
      stub_licensed_features(epics: true)

      allow(view).to receive(:current_user).and_return(user)
    end

    it 'has a link to the epic list path' do
      render

      expect(rendered).to have_link('Epics', href: group_epics_path(group))
    end

    describe 'List' do
      it 'has a link to the epic list path' do
        render

        expect(rendered).to have_link('List', href: group_epics_path(group))
      end
    end

    describe 'Boards' do
      it 'has a link to the epic boards path' do
        render

        expect(rendered).to have_link('Boards', href: group_epic_boards_path(group))
      end
    end

    describe 'Roadmap' do
      it 'has a link to the epic roadmap path' do
        render

        expect(rendered).to have_link('Roadmap', href: group_roadmap_path(group))
      end
    end
  end

124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
  describe 'Issues menu' do
    describe 'iterations link' do
      let_it_be(:current_user) { create(:user) }

      before do
        group.add_guest(current_user)

        allow(view).to receive(:current_user).and_return(current_user)
      end

      context 'with iterations licensed feature available' do
        before do
          stub_licensed_features(iterations: true)
        end

        context 'with group iterations feature flag enabled' do
          before do
            stub_feature_flags(group_iterations: true)
          end

          it 'is visible' do
            render

            expect(rendered).to have_text 'Iterations'
          end
        end

        context 'with iterations feature flag disabled' do
          before do
            stub_feature_flags(group_iterations: false)
          end

          it 'is not visible' do
            render

            expect(rendered).not_to have_text 'Iterations'
          end
        end
      end

      context 'with iterations licensed feature disabled' do
        before do
          stub_licensed_features(iterations: false)
        end

        it 'is not visible' do
          render

          expect(rendered).not_to have_text 'Iterations'
        end
      end
    end
  end

178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
  describe 'DevOps adoption link' do
    let!(:current_user) { create(:user) }

    before do
      group.add_maintainer(current_user)

      allow(view).to receive(:current_user).and_return(current_user)
    end

    context 'DevOps adoption feature is available' do
      before do
        stub_licensed_features(group_level_devops_adoption: true)
      end

      it 'is visible' do
        render

195
        expect(rendered).to have_text 'DevOps adoption'
196 197 198
      end
    end

199
    context 'DevOps adoption feature is not available' do
200 201 202 203 204 205 206
      before do
        stub_licensed_features(group_level_devops_adoption: false)
      end

      it 'is not visible' do
        render

207
        expect(rendered).not_to have_text 'DevOps adoption'
208 209 210 211
      end
    end
  end

212
  describe 'contribution analytics tab' do
213
    let!(:current_user) { create(:user) }
Tim Zallmann's avatar
Tim Zallmann committed
214

215 216
    before do
      group.add_guest(current_user)
217

218
      allow(view).to receive(:current_user).and_return(current_user)
219
    end
220

221 222 223 224 225 226 227 228
    context 'contribution analytics feature is available' do
      before do
        stub_licensed_features(contribution_analytics: true)
      end

      it 'is visible' do
        render

229
        expect(rendered).to have_text 'Contribution'
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
      end
    end

    context 'contribution analytics feature is not available' do
      before do
        stub_licensed_features(contribution_analytics: false)
      end

      context 'we do not show promotions' do
        before do
          allow(LicenseHelper).to receive(:show_promotions?).and_return(false)
        end

        it 'is not visible' do
          render

246
          expect(rendered).not_to have_text 'Contribution'
247 248 249
        end
      end
    end
250

251
    context 'no license installed' do
Tim Zallmann's avatar
Tim Zallmann committed
252 253 254
      before do
        allow(License).to receive(:current).and_return(nil)
        stub_application_setting(check_namespace_plan: false)
Tim Zallmann's avatar
Tim Zallmann committed
255

256
        allow(view).to receive(:can?) { |*args| Ability.allowed?(*args) }
Tim Zallmann's avatar
Tim Zallmann committed
257
      end
Tim Zallmann's avatar
Tim Zallmann committed
258

Tim Zallmann's avatar
Tim Zallmann committed
259 260
      it 'is visible when there is no valid license but we show promotions' do
        stub_licensed_features(contribution_analytics: false)
Tim Zallmann's avatar
Tim Zallmann committed
261

Tim Zallmann's avatar
Tim Zallmann committed
262 263
        render

264
        expect(rendered).to have_text 'Contribution'
Tim Zallmann's avatar
Tim Zallmann committed
265
      end
Tim Zallmann's avatar
Tim Zallmann committed
266 267
    end

268
    it 'is visible' do
269 270 271 272
      stub_licensed_features(contribution_analytics: true)

      render

273
      expect(rendered).to have_text 'Contribution'
274
    end
Felipe Artur's avatar
Felipe Artur committed
275 276

    describe 'group issue boards link' do
277 278 279
      context 'when multiple issue board is disabled' do
        it 'shows link text in singular' do
          render
Felipe Artur's avatar
Felipe Artur committed
280

281 282
          expect(rendered).to have_text 'Board'
        end
Felipe Artur's avatar
Felipe Artur committed
283 284
      end

285 286 287 288
      context 'when multiple issue board is enabled' do
        before do
          stub_licensed_features(multiple_group_issue_boards: true)
        end
Felipe Artur's avatar
Felipe Artur committed
289

290 291
        it 'shows link text in plural' do
          render
Felipe Artur's avatar
Felipe Artur committed
292

293 294
          expect(rendered).to have_text 'Boards'
        end
Felipe Artur's avatar
Felipe Artur committed
295 296
      end
    end
297
  end
298 299

  describe 'security dashboard tab' do
300
    let(:group) { create(:group_with_plan, plan: :ultimate_plan) }
301

302 303 304 305 306
    before do
      enable_namespace_license_check!
    end

    context 'when security dashboard feature is enabled' do
307 308 309
      before do
        stub_licensed_features(security_dashboard: true)
      end
310 311 312

      it 'is visible' do
        render
313

314
        expect(rendered).to have_link 'Security & Compliance'
315
        expect(rendered).to have_link 'Security'
316
      end
317 318
    end

319 320 321 322 323
    context 'when compliance dashboard feature is enabled' do
      before do
        stub_licensed_features(group_level_compliance_dashboard: true)
      end

324 325 326
      context 'when the user does not have access to Compliance dashboard' do
        it 'is not visible' do
          render
327

328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
          expect(rendered).not_to have_link 'Security & Compliance'
          expect(rendered).not_to have_link 'Compliance'
        end
      end

      context 'when the user has access to Compliance dashboard' do
        before do
          group.add_owner(user)
          allow(view).to receive(:current_user).and_return(user)
        end

        it 'is visible' do
          render

          expect(rendered).to have_link 'Security & Compliance'
          expect(rendered).to have_link 'Compliance'
        end
      end
    end

    context 'when credentials inventory feature is enabled' do
      shared_examples_for 'Credentials tab is not visible' do
        it 'does not show the `Credentials` tab' do
          render

          expect(rendered).not_to have_link 'Security & Compliance'
          expect(rendered).not_to have_link 'Credentials'
        end
      end

      before do
        stub_licensed_features(credentials_inventory: true)
      end

      context 'when the group does not enforce managed accounts' do
        it_behaves_like 'Credentials tab is not visible'
      end

      context 'when the group enforces managed accounts' do
        before do
          allow(group).to receive(:enforced_group_managed_accounts?).and_return(true)
        end

        context 'when the user has privileges to view Credentials' do
          before do
            group.add_owner(user)
            allow(view).to receive(:current_user).and_return(user)
          end

          it 'is visible' do
            render

            expect(rendered).to have_link 'Security & Compliance'
            expect(rendered).to have_link 'Credentials'
          end
        end

        context 'when the user does not have privileges to view Credentials' do
          it_behaves_like 'Credentials tab is not visible'
        end
388 389 390
      end
    end

391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
    context 'when audit events feature is enabled' do
      before do
        stub_licensed_features(audit_events: true)
      end

      context 'when the user does not have access to Audit Events' do
        before do
          group.add_guest(user)
          allow(view).to receive(:current_user).and_return(user)
        end

        it 'is not visible' do
          render

          expect(rendered).not_to have_link 'Security & Compliance'
          expect(rendered).not_to have_link 'Audit Events'
        end
      end

      context 'when the user has access to Audit Events' do
        before do
          group.add_owner(user)
          allow(view).to receive(:current_user).and_return(user)
        end

        it 'is visible' do
          render

          expect(rendered).to have_link 'Security & Compliance'
          expect(rendered).to have_link 'Audit Events'
        end
      end
    end

425
    context 'when security dashboard feature is disabled' do
426
      let(:group) { create(:group_with_plan, plan: :bronze_plan) }
427

428 429
      it 'is not visible' do
        render
430

431
        expect(rendered).not_to have_link 'Security & Compliance'
432
      end
433 434
    end
  end
435

436 437
  describe 'wiki tab' do
    let(:can_read_wiki) { true }
438

439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
    let_it_be(:current_user) { create(:user) }

    before do
      group.add_guest(current_user)

      allow(view).to receive(:current_user).and_return(current_user)
      allow(view).to receive(:can?).with(current_user, :read_wiki, group).and_return(can_read_wiki)
    end

    describe 'when wiki is available to user' do
      it 'shows the wiki tab with the wiki internal link' do
        render

        expect(rendered).to have_link('Wiki', href: group.wiki.web_url)
      end
    end

    describe 'when wiki is unavailable to user' do
      let(:can_read_wiki) { false }

      it 'does not show the wiki tab' do
        render

        expect(rendered).not_to have_link('Wiki', href: group.wiki.web_url)
      end
    end
  end
466
end