summaryrefslogtreecommitdiff
path: root/spec/frontend/ci_lint
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-11-19 08:27:35 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-11-19 08:27:35 +0000
commit7e9c479f7de77702622631cff2628a9c8dcbc627 (patch)
treec8f718a08e110ad7e1894510980d2155a6549197 /spec/frontend/ci_lint
parente852b0ae16db4052c1c567d9efa4facc81146e88 (diff)
downloadgitlab-ce-7e9c479f7de77702622631cff2628a9c8dcbc627.tar.gz
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/frontend/ci_lint')
-rw-r--r--spec/frontend/ci_lint/components/ci_lint_results_spec.js35
-rw-r--r--spec/frontend/ci_lint/components/ci_lint_spec.js42
-rw-r--r--spec/frontend/ci_lint/graphql/__snapshots__/resolvers_spec.js.snap73
-rw-r--r--spec/frontend/ci_lint/graphql/resolvers_spec.js38
-rw-r--r--spec/frontend/ci_lint/mock_data.js45
5 files changed, 221 insertions, 12 deletions
diff --git a/spec/frontend/ci_lint/components/ci_lint_results_spec.js b/spec/frontend/ci_lint/components/ci_lint_results_spec.js
index 37575a988c5..93c2d2dbcf3 100644
--- a/spec/frontend/ci_lint/components/ci_lint_results_spec.js
+++ b/spec/frontend/ci_lint/components/ci_lint_results_spec.js
@@ -1,20 +1,24 @@
import { shallowMount, mount } from '@vue/test-utils';
-import { GlTable } from '@gitlab/ui';
+import { GlTable, GlLink } from '@gitlab/ui';
import CiLintResults from '~/ci_lint/components/ci_lint_results.vue';
import { capitalizeFirstCharacter } from '~/lib/utils/text_utility';
import { mockJobs, mockErrors, mockWarnings } from '../mock_data';
describe('CI Lint Results', () => {
let wrapper;
+ const defaultProps = {
+ valid: true,
+ jobs: mockJobs,
+ errors: [],
+ warnings: [],
+ dryRun: false,
+ lintHelpPagePath: '/help',
+ };
const createComponent = (props = {}, mountFn = shallowMount) => {
wrapper = mountFn(CiLintResults, {
propsData: {
- valid: true,
- jobs: mockJobs,
- errors: [],
- warnings: [],
- dryRun: false,
+ ...defaultProps,
...props,
},
});
@@ -23,6 +27,7 @@ describe('CI Lint Results', () => {
const findTable = () => wrapper.find(GlTable);
const findByTestId = selector => () => wrapper.find(`[data-testid="ci-lint-${selector}"]`);
const findAllByTestId = selector => () => wrapper.findAll(`[data-testid="ci-lint-${selector}"]`);
+ const findLinkToDoc = () => wrapper.find(GlLink);
const findErrors = findByTestId('errors');
const findWarnings = findByTestId('warnings');
const findStatus = findByTestId('status');
@@ -48,10 +53,15 @@ describe('CI Lint Results', () => {
});
it('displays the invalid status', () => {
- expect(findStatus().text()).toBe(`Status: ${wrapper.vm.$options.incorrect.text}`);
+ expect(findStatus().text()).toContain(`Status: ${wrapper.vm.$options.incorrect.text}`);
expect(findStatus().props('variant')).toBe(wrapper.vm.$options.incorrect.variant);
});
+ it('contains the link to documentation', () => {
+ expect(findLinkToDoc().text()).toBe('More information');
+ expect(findLinkToDoc().attributes('href')).toBe(defaultProps.lintHelpPagePath);
+ });
+
it('displays the error message', () => {
const [expectedError] = mockErrors;
@@ -66,9 +76,9 @@ describe('CI Lint Results', () => {
});
});
- describe('Valid results', () => {
+ describe('Valid results with dry run', () => {
beforeEach(() => {
- createComponent();
+ createComponent({ dryRun: true }, mount);
});
it('displays table', () => {
@@ -76,13 +86,18 @@ describe('CI Lint Results', () => {
});
it('displays the valid status', () => {
- expect(findStatus().text()).toBe(wrapper.vm.$options.correct.text);
+ expect(findStatus().text()).toContain(wrapper.vm.$options.correct.text);
expect(findStatus().props('variant')).toBe(wrapper.vm.$options.correct.variant);
});
it('does not display only/expect values with dry run', () => {
expect(findOnlyExcept().exists()).toBe(false);
});
+
+ it('contains the link to documentation', () => {
+ expect(findLinkToDoc().text()).toBe('More information');
+ expect(findLinkToDoc().attributes('href')).toBe(defaultProps.lintHelpPagePath);
+ });
});
describe('Lint results', () => {
diff --git a/spec/frontend/ci_lint/components/ci_lint_spec.js b/spec/frontend/ci_lint/components/ci_lint_spec.js
index e617cca499d..b353da5910d 100644
--- a/spec/frontend/ci_lint/components/ci_lint_spec.js
+++ b/spec/frontend/ci_lint/components/ci_lint_spec.js
@@ -1,7 +1,11 @@
+import { GlAlert } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
+import waitForPromises from 'helpers/wait_for_promises';
import EditorLite from '~/vue_shared/components/editor_lite.vue';
import CiLint from '~/ci_lint/components/ci_lint.vue';
+import CiLintResults from '~/ci_lint/components/ci_lint_results.vue';
import lintCIMutation from '~/ci_lint/graphql/mutations/lint_ci.mutation.graphql';
+import { mockLintDataValid } from '../mock_data';
describe('CI Lint', () => {
let wrapper;
@@ -9,6 +13,7 @@ describe('CI Lint', () => {
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 ";
+ const mockMutate = jest.fn().mockResolvedValue(mockLintDataValid);
const createComponent = () => {
wrapper = shallowMount(CiLint, {
@@ -19,17 +24,20 @@ describe('CI Lint', () => {
},
propsData: {
endpoint,
- helpPagePath: '/help/ci/lint#pipeline-simulation',
+ pipelineSimulationHelpPagePath: '/help/ci/lint#pipeline-simulation',
+ lintHelpPagePath: '/help/ci/lint#anchor',
},
mocks: {
$apollo: {
- mutate: jest.fn(),
+ mutate: mockMutate,
},
},
});
};
const findEditor = () => wrapper.find(EditorLite);
+ const findAlert = () => wrapper.find(GlAlert);
+ const findCiLintResults = () => wrapper.find(CiLintResults);
const findValidateBtn = () => wrapper.find('[data-testid="ci-lint-validate"]');
const findClearBtn = () => wrapper.find('[data-testid="ci-lint-clear"]');
@@ -38,6 +46,7 @@ describe('CI Lint', () => {
});
afterEach(() => {
+ mockMutate.mockClear();
wrapper.destroy();
});
@@ -67,6 +76,35 @@ describe('CI Lint', () => {
});
});
+ 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);
+ });
+
it('content is cleared on clear action', async () => {
expect(findEditor().props('value')).toBe(content);
diff --git a/spec/frontend/ci_lint/graphql/__snapshots__/resolvers_spec.js.snap b/spec/frontend/ci_lint/graphql/__snapshots__/resolvers_spec.js.snap
new file mode 100644
index 00000000000..87bec82e350
--- /dev/null
+++ b/spec/frontend/ci_lint/graphql/__snapshots__/resolvers_spec.js.snap
@@ -0,0 +1,73 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`~/ci_lint/graphql/resolvers Mutation lintCI resolves lint data with type names 1`] = `
+Object {
+ "__typename": "CiLintContent",
+ "errors": Array [],
+ "jobs": Array [
+ Object {
+ "__typename": "CiLintJob",
+ "afterScript": Array [
+ "echo 'after script 1",
+ ],
+ "allowFailure": false,
+ "beforeScript": Array [
+ "echo 'before script 1'",
+ ],
+ "environment": "prd",
+ "except": Object {
+ "refs": Array [
+ "master@gitlab-org/gitlab",
+ "/^release/.*$/@gitlab-org/gitlab",
+ ],
+ },
+ "name": "job_1",
+ "only": null,
+ "script": Array [
+ "echo 'script 1'",
+ ],
+ "stage": "test",
+ "tagList": Array [
+ "tag 1",
+ ],
+ "when": "on_success",
+ },
+ Object {
+ "__typename": "CiLintJob",
+ "afterScript": Array [
+ "echo 'after script 2",
+ ],
+ "allowFailure": true,
+ "beforeScript": Array [
+ "echo 'before script 2'",
+ ],
+ "environment": "stg",
+ "except": Object {
+ "refs": Array [
+ "master@gitlab-org/gitlab",
+ "/^release/.*$/@gitlab-org/gitlab",
+ ],
+ },
+ "name": "job_2",
+ "only": Object {
+ "__typename": "CiLintJobOnlyPolicy",
+ "refs": Array [
+ "web",
+ "chat",
+ "pushes",
+ ],
+ },
+ "script": Array [
+ "echo 'script 2'",
+ ],
+ "stage": "test",
+ "tagList": Array [
+ "tag 2",
+ ],
+ "when": "on_success",
+ },
+ ],
+ "valid": true,
+ "warnings": Array [],
+}
+`;
diff --git a/spec/frontend/ci_lint/graphql/resolvers_spec.js b/spec/frontend/ci_lint/graphql/resolvers_spec.js
new file mode 100644
index 00000000000..437c52cf6b4
--- /dev/null
+++ b/spec/frontend/ci_lint/graphql/resolvers_spec.js
@@ -0,0 +1,38 @@
+import MockAdapter from 'axios-mock-adapter';
+import axios from '~/lib/utils/axios_utils';
+import httpStatus from '~/lib/utils/http_status';
+
+import resolvers from '~/ci_lint/graphql/resolvers';
+import { mockLintResponse } from '../mock_data';
+
+describe('~/ci_lint/graphql/resolvers', () => {
+ let mock;
+
+ beforeEach(() => {
+ mock = new MockAdapter(axios);
+ });
+
+ afterEach(() => {
+ mock.restore();
+ });
+
+ describe('Mutation', () => {
+ describe('lintCI', () => {
+ const endpoint = '/ci/lint';
+
+ beforeEach(() => {
+ mock.onPost(endpoint).reply(httpStatus.OK, mockLintResponse);
+ });
+
+ it('resolves lint data with type names', async () => {
+ const result = resolvers.Mutation.lintCI(null, {
+ endpoint,
+ content: 'content',
+ dry_run: true,
+ });
+
+ await expect(result).resolves.toMatchSnapshot();
+ });
+ });
+ });
+});
diff --git a/spec/frontend/ci_lint/mock_data.js b/spec/frontend/ci_lint/mock_data.js
index cf7d69dcad3..b87c9f8413b 100644
--- a/spec/frontend/ci_lint/mock_data.js
+++ b/spec/frontend/ci_lint/mock_data.js
@@ -1,3 +1,37 @@
+export const mockLintResponse = {
+ valid: true,
+ errors: [],
+ warnings: [],
+ jobs: [
+ {
+ name: 'job_1',
+ stage: 'test',
+ before_script: ["echo 'before script 1'"],
+ script: ["echo 'script 1'"],
+ after_script: ["echo 'after script 1"],
+ tag_list: ['tag 1'],
+ environment: 'prd',
+ when: 'on_success',
+ allow_failure: false,
+ only: null,
+ except: { refs: ['master@gitlab-org/gitlab', '/^release/.*$/@gitlab-org/gitlab'] },
+ },
+ {
+ name: 'job_2',
+ stage: 'test',
+ before_script: ["echo 'before script 2'"],
+ script: ["echo 'script 2'"],
+ after_script: ["echo 'after script 2"],
+ tag_list: ['tag 2'],
+ environment: 'stg',
+ when: 'on_success',
+ allow_failure: true,
+ only: { refs: ['web', 'chat', 'pushes'] },
+ except: { refs: ['master@gitlab-org/gitlab', '/^release/.*$/@gitlab-org/gitlab'] },
+ },
+ ],
+};
+
export const mockJobs = [
{
name: 'job_1',
@@ -47,3 +81,14 @@ export const mockErrors = [
export const mockWarnings = [
'"jobs:multi_project_job may allow multiple pipelines to run for a single action due to `rules:when` clause with no `workflow:rules` - read more: https://docs.gitlab.com/ee/ci/troubleshooting.html#pipeline-warnings"',
];
+
+export const mockLintDataValid = {
+ data: {
+ lintCI: {
+ errors: [],
+ warnings: [],
+ valid: true,
+ jobs: mockJobs,
+ },
+ },
+};