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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

119 lines
3.5 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';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
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';
2022-01-26 12:08:38 +05:30
import lintCIMutation from '~/pipeline_editor/graphql/mutations/client/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
},
},
});
};
2022-10-11 01:57:18 +05:30
const findEditor = () => wrapper.findComponent(SourceEditor);
const findAlert = () => wrapper.findComponent(GlAlert);
const findCiLintResults = () => wrapper.findComponent(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;
2022-03-02 08:16:31 +05:30
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
2021-01-03 14:25:43 +05:30
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');
2022-04-04 11:22:00 +05:30
await nextTick();
2021-01-29 00:20:46 +05:30
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');
2022-04-04 11:22:00 +05:30
await nextTick();
2021-01-29 00:20:46 +05:30
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('');
});
});