Welcome to mirror list, hosted at ThFree Co, Russian Federation.

terraform_notification_spec.js « terraform_notification « projects « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 71c22998b08d47aee26466526b962130e53478a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { GlBanner } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { setCookie, parseBoolean } from '~/lib/utils/common_utils';
import TerraformNotification from '~/projects/terraform_notification/components/terraform_notification.vue';

jest.mock('~/lib/utils/common_utils');

const terraformImagePath = '/path/to/image';
const bannerDismissedKey = 'terraform_notification_dismissed';

describe('TerraformNotificationBanner', () => {
  let wrapper;

  const provideData = {
    terraformImagePath,
    bannerDismissedKey,
  };
  const findBanner = () => wrapper.findComponent(GlBanner);

  beforeEach(() => {
    wrapper = shallowMount(TerraformNotification, {
      provide: provideData,
      stubs: { GlBanner },
    });
  });

  afterEach(() => {
    wrapper.destroy();
    parseBoolean.mockReturnValue(false);
  });

  describe('when the dismiss cookie is not set', () => {
    it('should render the banner', () => {
      expect(findBanner().exists()).toBe(true);
    });
  });

  describe('when close button is clicked', () => {
    beforeEach(async () => {
      await findBanner().vm.$emit('close');
    });

    it('should set the cookie with the bannerDismissedKey', () => {
      expect(setCookie).toHaveBeenCalledWith(bannerDismissedKey, true);
    });

    it('should remove the banner', () => {
      expect(findBanner().exists()).toBe(false);
    });
  });
});