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
52
53
54
55
56
57
58
59
60
61
62
|
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 bannerDissmisedKey = 'terraform_notification_dismissed_for_project_1';
describe('TerraformNotificationBanner', () => {
let wrapper;
const propsData = {
projectId: 1,
};
const findBanner = () => wrapper.findComponent(GlBanner);
beforeEach(() => {
wrapper = shallowMount(TerraformNotification, {
propsData,
stubs: { GlBanner },
});
});
afterEach(() => {
wrapper.destroy();
parseBoolean.mockReturnValue(false);
});
describe('when the dismiss cookie is set', () => {
beforeEach(() => {
parseBoolean.mockReturnValue(true);
wrapper = shallowMount(TerraformNotification, {
propsData,
});
});
it('should not render the banner', () => {
expect(findBanner().exists()).toBe(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 bannerDissmisedKey', () => {
expect(setCookie).toHaveBeenCalledWith(bannerDissmisedKey, true);
});
it('should remove the banner', () => {
expect(findBanner().exists()).toBe(false);
});
});
});
|