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
|
import Vue, { nextTick } from 'vue';
import VueApollo from 'vue-apollo';
import waitForPromises from 'helpers/wait_for_promises';
import createMockApollo from 'helpers/mock_apollo_helper';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import PagesPipelineWizard, { i18n } from '~/gitlab_pages/components/pages_pipeline_wizard.vue';
import PipelineWizard from '~/pipeline_wizard/pipeline_wizard.vue';
import pagesTemplate from '~/pipeline_wizard/templates/pages.yml';
import pagesMarkOnboardingComplete from '~/gitlab_pages/queries/mark_onboarding_complete.graphql';
import { redirectTo } from '~/lib/utils/url_utility'; // eslint-disable-line import/no-deprecated
Vue.use(VueApollo);
jest.mock('~/lib/utils/url_utility');
describe('PagesPipelineWizard', () => {
const markOnboardingCompleteMutationHandler = jest.fn();
let wrapper;
const props = {
projectPath: '/user/repo',
defaultBranch: 'main',
redirectToWhenDone: './',
};
const findPipelineWizardWrapper = () => wrapper.findComponent(PipelineWizard);
const createMockApolloProvider = () => {
return createMockApollo([
[
pagesMarkOnboardingComplete,
markOnboardingCompleteMutationHandler.mockResolvedValue({
data: {
pagesMarkOnboardingComplete: {
onboardingComplete: true,
errors: [],
},
},
}),
],
]);
};
const createComponent = () => {
wrapper = shallowMountExtended(PagesPipelineWizard, {
apolloProvider: createMockApolloProvider(),
propsData: props,
});
};
beforeEach(() => {
createComponent();
});
it('shows the pipeline wizard', () => {
expect(findPipelineWizardWrapper().exists()).toBe(true);
});
it('passes the appropriate props', () => {
const pipelineWizardWrapperProps = findPipelineWizardWrapper().props();
expect(pipelineWizardWrapperProps.template).toBe(pagesTemplate);
expect(pipelineWizardWrapperProps.projectPath).toBe(props.projectPath);
expect(pipelineWizardWrapperProps.defaultBranch).toBe(props.defaultBranch);
});
describe('after the steps are complete', () => {
const mockDone = () => findPipelineWizardWrapper().vm.$emit('done');
it('shows a loading screen during the update', async () => {
mockDone();
await nextTick();
const loadingScreenWrapper = wrapper.findByTestId('onboarding-mutation-loading');
expect(loadingScreenWrapper.exists()).toBe(true);
expect(loadingScreenWrapper.text()).toBe(i18n.loadingMessage);
});
it('calls pagesMarkOnboardingComplete mutation when done', async () => {
mockDone();
await waitForPromises();
expect(markOnboardingCompleteMutationHandler).toHaveBeenCalledWith({
input: {
projectPath: props.projectPath,
},
});
});
it('navigates to the path defined in redirectToWhenDone when done', async () => {
mockDone();
await waitForPromises();
expect(redirectTo).toHaveBeenCalledWith(props.redirectToWhenDone); // eslint-disable-line import/no-deprecated
});
});
});
|