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
92
93
94
95
96
97
98
99
100
101
102
103
|
import { GlBanner, GlButton } from '@gitlab/ui';
import { useLocalStorageSpy } from 'helpers/local_storage_helper';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import CatalogHeader from '~/ci/catalog/components/list/catalog_header.vue';
import { CATALOG_FEEDBACK_DISMISSED_KEY } from '~/ci/catalog/constants';
describe('CatalogHeader', () => {
useLocalStorageSpy();
let wrapper;
const defaultProps = {};
const customProvide = {
pageTitle: 'Catalog page',
pageDescription: 'This is a nice catalog page',
};
const findBanner = () => wrapper.findComponent(GlBanner);
const findFeedbackButton = () => findBanner().findComponent(GlButton);
const findTitle = () => wrapper.find('h1');
const findDescription = () => wrapper.findByTestId('description');
const createComponent = ({ props = {}, provide = {}, stubs = {} } = {}) => {
wrapper = shallowMountExtended(CatalogHeader, {
propsData: {
...defaultProps,
...props,
},
provide,
stubs: {
...stubs,
},
});
};
describe('title and description', () => {
describe('when there are no values provided', () => {
beforeEach(() => {
createComponent();
});
it('renders the default values', () => {
expect(findTitle().text()).toBe('CI/CD Catalog');
expect(findDescription().text()).toBe(
'Discover CI configuration resources for a seamless CI/CD experience.',
);
});
});
describe('when custom values are provided', () => {
beforeEach(() => {
createComponent({ provide: customProvide });
});
it('renders the custom values', () => {
expect(findTitle().text()).toBe(customProvide.pageTitle);
expect(findDescription().text()).toBe(customProvide.pageDescription);
});
});
});
describe('Feedback banner', () => {
describe('when user has never dismissed', () => {
beforeEach(() => {
createComponent({ stubs: { GlBanner } });
});
it('is visible', () => {
expect(findBanner().exists()).toBe(true);
});
it('has link to feedback issue', () => {
expect(findFeedbackButton().attributes().href).toBe(
'https://gitlab.com/gitlab-org/gitlab/-/issues/407556',
);
});
});
describe('when user dismisses it', () => {
beforeEach(() => {
createComponent();
});
it('sets the local storage and removes the banner', async () => {
expect(findBanner().exists()).toBe(true);
await findBanner().vm.$emit('close');
expect(localStorage.setItem).toHaveBeenCalledWith(CATALOG_FEEDBACK_DISMISSED_KEY, 'true');
expect(findBanner().exists()).toBe(false);
});
});
describe('when user has dismissed it before', () => {
beforeEach(() => {
localStorage.setItem(CATALOG_FEEDBACK_DISMISSED_KEY, 'true');
createComponent();
});
it('does not show the banner', () => {
expect(findBanner().exists()).toBe(false);
});
});
});
});
|