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
63
64
65
66
67
|
import { GlBanner } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import DevopsScoreCallout from '~/analytics/devops_reports/components/devops_score_callout.vue';
import { INTRO_COOKIE_KEY } from '~/analytics/devops_reports/constants';
import * as utils from '~/lib/utils/common_utils';
import { devopsReportDocsPath, devopsScoreIntroImagePath } from '../mock_data';
describe('DevopsScoreCallout', () => {
let wrapper;
const createComponent = () => {
wrapper = shallowMount(DevopsScoreCallout, {
provide: {
devopsReportDocsPath,
devopsScoreIntroImagePath,
},
});
};
const findBanner = () => wrapper.findComponent(GlBanner);
afterEach(() => {
wrapper.destroy();
});
describe('with no cookie set', () => {
beforeEach(() => {
utils.setCookie = jest.fn();
createComponent();
});
it('displays the banner', () => {
expect(findBanner().exists()).toBe(true);
});
it('does not call setCookie', () => {
expect(utils.setCookie).not.toHaveBeenCalled();
});
describe('when the close button is clicked', () => {
beforeEach(() => {
findBanner().vm.$emit('close');
});
it('sets the dismissed cookie', () => {
expect(utils.setCookie).toHaveBeenCalledWith(INTRO_COOKIE_KEY, 'true');
});
it('hides the banner', () => {
expect(findBanner().exists()).toBe(false);
});
});
});
describe('with the dismissed cookie set', () => {
beforeEach(() => {
jest.spyOn(utils, 'getCookie').mockReturnValue('true');
createComponent();
});
it('hides the banner', () => {
expect(findBanner().exists()).toBe(false);
});
});
});
|