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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
import { GlBanner } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { makeMockUserCalloutDismisser } from 'helpers/mock_user_callout_dismisser';
import { mockTracking } from 'helpers/tracking_helper';
import TerraformNotification from '~/projects/terraform_notification/components/terraform_notification.vue';
import {
EVENT_LABEL,
DISMISS_EVENT,
CLICK_EVENT,
} from '~/projects/terraform_notification/constants';
const terraformImagePath = '/path/to/image';
describe('TerraformNotificationBanner', () => {
let wrapper;
let trackingSpy;
let userCalloutDismissSpy;
const provideData = {
terraformImagePath,
};
const findBanner = () => wrapper.findComponent(GlBanner);
const createComponent = ({ shouldShowCallout = true } = {}) => {
userCalloutDismissSpy = jest.fn();
wrapper = shallowMount(TerraformNotification, {
provide: provideData,
stubs: {
GlBanner,
UserCalloutDismisser: makeMockUserCalloutDismisser({
dismiss: userCalloutDismissSpy,
shouldShowCallout,
}),
},
});
};
beforeEach(() => {
createComponent();
trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn);
});
afterEach(() => {
wrapper.destroy();
});
describe('when user has already dismissed the banner', () => {
beforeEach(() => {
createComponent({
shouldShowCallout: false,
});
});
it('should not render the banner', () => {
expect(findBanner().exists()).toBe(false);
});
});
describe("when user hasn't yet dismissed the banner", () => {
it('should render the banner', () => {
expect(findBanner().exists()).toBe(true);
});
});
describe('when close button is clicked', () => {
beforeEach(() => {
wrapper.vm.$refs.calloutDismisser.dismiss = userCalloutDismissSpy;
findBanner().vm.$emit('close');
});
it('should send the dismiss event', () => {
expect(trackingSpy).toHaveBeenCalledWith(undefined, DISMISS_EVENT, {
label: EVENT_LABEL,
});
});
it('should call the dismiss callback', () => {
expect(userCalloutDismissSpy).toHaveBeenCalledTimes(1);
});
});
describe('when docs link is clicked', () => {
beforeEach(() => {
findBanner().vm.$emit('primary');
});
it('should send button click event', () => {
expect(trackingSpy).toHaveBeenCalledWith(undefined, CLICK_EVENT, {
label: EVENT_LABEL,
});
});
});
});
|