debian-mirror-gitlab/spec/frontend/ci_lint/components/ci_lint_spec.js

116 lines
3.3 KiB
JavaScript
Raw Normal View History

2021-01-29 00:20:46 +05:30
import { GlAlert } from '@gitlab/ui';
2021-01-03 14:25:43 +05:30
import { shallowMount } from '@vue/test-utils';
2021-01-29 00:20:46 +05:30
import waitForPromises from 'helpers/wait_for_promises';
2021-01-03 14:25:43 +05:30
import CiLint from '~/ci_lint/components/ci_lint.vue';
2021-02-22 17:27:13 +05:30
import CiLintResults from '~/pipeline_editor/components/lint/ci_lint_results.vue';
import lintCIMutation from '~/pipeline_editor/graphql/mutations/lint_ci.mutation.graphql';
2021-09-30 23:02:18 +05:30
import SourceEditor from '~/vue_shared/components/source_editor.vue';
2021-01-29 00:20:46 +05:30
import { mockLintDataValid } from '../mock_data';
2021-01-03 14:25:43 +05:30
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 ";
2021-01-29 00:20:46 +05:30
const mockMutate = jest.fn().mockResolvedValue(mockLintDataValid);
2021-01-03 14:25:43 +05:30
const createComponent = () => {
wrapper = shallowMount(CiLint, {
data() {
return {
content,
};
},
propsData: {
endpoint,
2021-01-29 00:20:46 +05:30
pipelineSimulationHelpPagePath: '/help/ci/lint#pipeline-simulation',
lintHelpPagePath: '/help/ci/lint#anchor',
2021-01-03 14:25:43 +05:30
},
mocks: {
$apollo: {
2021-01-29 00:20:46 +05:30
mutate: mockMutate,
2021-01-03 14:25:43 +05:30
},
},
});
};
2021-09-30 23:02:18 +05:30
const findEditor = () => wrapper.find(SourceEditor);
2021-01-29 00:20:46 +05:30
const findAlert = () => wrapper.find(GlAlert);
const findCiLintResults = () => wrapper.find(CiLintResults);
2021-01-03 14:25:43 +05:30
const findValidateBtn = () => wrapper.find('[data-testid="ci-lint-validate"]');
const findClearBtn = () => wrapper.find('[data-testid="ci-lint-clear"]');
beforeEach(() => {
createComponent();
});
afterEach(() => {
2021-01-29 00:20:46 +05:30
mockMutate.mockClear();
2021-01-03 14:25:43 +05:30
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 },
});
});
2021-01-29 00:20:46 +05:30
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);
});
2021-01-03 14:25:43 +05:30
it('content is cleared on clear action', async () => {
expect(findEditor().props('value')).toBe(content);
await findClearBtn().vm.$emit('click');
expect(findEditor().props('value')).toBe('');
});
});