2020-11-03 04:09:07 -05:00
|
|
|
import { GlAlert } from '@gitlab/ui';
|
2020-10-16 17:09:08 -04:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-11-03 04:09:07 -05:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2020-10-16 17:09:08 -04:00
|
|
|
import EditorLite from '~/vue_shared/components/editor_lite.vue';
|
|
|
|
import CiLint from '~/ci_lint/components/ci_lint.vue';
|
2020-11-27 07:09:14 -05:00
|
|
|
import CiLintResults from '~/pipeline_editor/components/lint/ci_lint_results.vue';
|
|
|
|
import lintCIMutation from '~/pipeline_editor/graphql/mutations/lint_ci.mutation.graphql';
|
2020-11-03 04:09:07 -05:00
|
|
|
import { mockLintDataValid } from '../mock_data';
|
2020-10-16 17:09:08 -04:00
|
|
|
|
|
|
|
describe('CI Lint', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const endpoint = '/namespace/project/-/ci/lint';
|
|
|
|
const content =
|
|
|
|
"test_job:\n stage: build\n script: echo 'Building'\n only:\n - web\n - chat\n - pushes\n allow_failure: true ";
|
2020-11-03 04:09:07 -05:00
|
|
|
const mockMutate = jest.fn().mockResolvedValue(mockLintDataValid);
|
2020-10-16 17:09:08 -04:00
|
|
|
|
|
|
|
const createComponent = () => {
|
|
|
|
wrapper = shallowMount(CiLint, {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
content,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
propsData: {
|
|
|
|
endpoint,
|
2020-11-13 10:09:24 -05:00
|
|
|
pipelineSimulationHelpPagePath: '/help/ci/lint#pipeline-simulation',
|
|
|
|
lintHelpPagePath: '/help/ci/lint#anchor',
|
2020-10-16 17:09:08 -04:00
|
|
|
},
|
|
|
|
mocks: {
|
|
|
|
$apollo: {
|
2020-11-03 04:09:07 -05:00
|
|
|
mutate: mockMutate,
|
2020-10-16 17:09:08 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const findEditor = () => wrapper.find(EditorLite);
|
2020-11-03 04:09:07 -05:00
|
|
|
const findAlert = () => wrapper.find(GlAlert);
|
|
|
|
const findCiLintResults = () => wrapper.find(CiLintResults);
|
2020-10-16 17:09:08 -04:00
|
|
|
const findValidateBtn = () => wrapper.find('[data-testid="ci-lint-validate"]');
|
|
|
|
const findClearBtn = () => wrapper.find('[data-testid="ci-lint-clear"]');
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2020-11-03 04:09:07 -05:00
|
|
|
mockMutate.mockClear();
|
2020-10-16 17:09:08 -04:00
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the editor', () => {
|
|
|
|
expect(findEditor().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('validate action calls mutation correctly', () => {
|
|
|
|
findValidateBtn().vm.$emit('click');
|
|
|
|
|
|
|
|
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
|
|
|
|
mutation: lintCIMutation,
|
|
|
|
variables: { content, dry: false, endpoint },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('validate action calls mutation with dry run', async () => {
|
|
|
|
const dryRunEnabled = true;
|
|
|
|
|
|
|
|
await wrapper.setData({ dryRun: dryRunEnabled });
|
|
|
|
|
|
|
|
findValidateBtn().vm.$emit('click');
|
|
|
|
|
|
|
|
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
|
|
|
|
mutation: lintCIMutation,
|
|
|
|
variables: { content, dry: dryRunEnabled, endpoint },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-03 04:09:07 -05:00
|
|
|
it('validation displays results', async () => {
|
|
|
|
findValidateBtn().vm.$emit('click');
|
|
|
|
|
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
|
|
|
|
expect(findValidateBtn().props('loading')).toBe(true);
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(findCiLintResults().exists()).toBe(true);
|
|
|
|
expect(findValidateBtn().props('loading')).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('validation displays error', async () => {
|
|
|
|
mockMutate.mockRejectedValue('Error!');
|
|
|
|
|
|
|
|
findValidateBtn().vm.$emit('click');
|
|
|
|
|
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
|
|
|
|
expect(findValidateBtn().props('loading')).toBe(true);
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(findCiLintResults().exists()).toBe(false);
|
|
|
|
expect(findAlert().text()).toBe('Error!');
|
|
|
|
expect(findValidateBtn().props('loading')).toBe(false);
|
|
|
|
});
|
|
|
|
|
2020-10-16 17:09:08 -04:00
|
|
|
it('content is cleared on clear action', async () => {
|
|
|
|
expect(findEditor().props('value')).toBe(content);
|
|
|
|
|
|
|
|
await findClearBtn().vm.$emit('click');
|
|
|
|
|
|
|
|
expect(findEditor().props('value')).toBe('');
|
|
|
|
});
|
|
|
|
});
|