Commit edaeb2eb authored by Frédéric Caplette's avatar Frédéric Caplette

Update validation segment tests for apollo

Instead of using the data property in tests,
which is discouraged, we use apollo to write
a default store value which simulate
the application in a more realistic manner.
parent eecf15b9
import VueApollo from 'vue-apollo';
import { GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import { escape } from 'lodash';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import createMockApollo from 'helpers/mock_apollo_helper';
import { sprintf } from '~/locale';
import ValidationSegment, {
i18n,
} from '~/pipeline_editor/components/header/validation_segment.vue';
import getAppStatus from '~/pipeline_editor/graphql/queries/client/app_status.query.graphql';
import {
CI_CONFIG_STATUS_INVALID,
EDITOR_APP_STATUS_EMPTY,
......@@ -21,12 +24,29 @@ import {
mockYmlHelpPagePath,
} from '../../mock_data';
const localVue = createLocalVue();
localVue.use(VueApollo);
describe('Validation segment component', () => {
let wrapper;
const createComponent = ({ props = {}, appStatus }) => {
const mockApollo = createMockApollo();
const createComponent = ({ props = {}, appStatus = EDITOR_APP_STATUS_INVALID }) => {
mockApollo.clients.defaultClient.cache.writeQuery({
query: getAppStatus,
data: {
app: {
__typename: 'PipelineEditorApp',
status: appStatus,
},
},
});
wrapper = extendedWrapper(
shallowMount(ValidationSegment, {
localVue,
apolloProvider: mockApollo,
provide: {
ymlHelpPagePath: mockYmlHelpPagePath,
lintUnavailableHelpPagePath: mockLintUnavailableHelpPagePath,
......@@ -36,12 +56,6 @@ describe('Validation segment component', () => {
ciFileContent: mockCiYml,
...props,
},
// Simulate graphQL client query result
data() {
return {
appStatus,
};
},
}),
);
};
......@@ -99,6 +113,7 @@ describe('Validation segment component', () => {
appStatus: EDITOR_APP_STATUS_INVALID,
});
});
it('has warning icon', () => {
expect(findIcon().props('name')).toBe('warning-solid');
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment