Commit 5a7eb3af authored by Miguel Rincon's avatar Miguel Rincon

Add improvements from maintainer review

- Change form tests
- Swap mount and shallowMount
parent 727e4c33
...@@ -225,11 +225,11 @@ export default { ...@@ -225,11 +225,11 @@ export default {
v-if="showFailureAlert" v-if="showFailureAlert"
:variant="failure.variant" :variant="failure.variant"
:dismissible="true" :dismissible="true"
@dismiss="dismissFailure()" @dismiss="dismissFailure"
> >
{{ failure.text }} {{ failure.text }}
<ul v-if="failureReasons && failureReasons.length" class="gl-mb-0"> <ul v-if="failureReasons.length" class="gl-mb-0">
<li v-for="(reason, i) in failureReasons" :key="i">{{ reason }}</li> <li v-for="reason in failureReasons" :key="reason">{{ reason }}</li>
</ul> </ul>
</gl-alert> </gl-alert>
<div class="gl-mt-4"> <div class="gl-mt-4">
......
...@@ -79,7 +79,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -79,7 +79,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
}); });
}); });
describe('when users inputs values', () => { describe('when user inputs values', () => {
const anotherMessage = 'Another commit message'; const anotherMessage = 'Another commit message';
const anotherBranch = 'my-branch'; const anotherBranch = 'my-branch';
......
import { nextTick } from 'vue'; import { nextTick } from 'vue';
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { mount, shallowMount, createLocalVue } from '@vue/test-utils';
import { GlButton, GlAlert, GlLoadingIcon, GlTabs, GlTab } from '@gitlab/ui'; import {
GlAlert,
GlButton,
GlFormInput,
GlFormTextarea,
GlLoadingIcon,
GlTabs,
GlTab,
} from '@gitlab/ui';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import createMockApollo from 'jest/helpers/mock_apollo_helper'; import createMockApollo from 'jest/helpers/mock_apollo_helper';
...@@ -17,7 +25,6 @@ import { ...@@ -17,7 +25,6 @@ import {
} from './mock_data'; } from './mock_data';
import TextEditor from '~/pipeline_editor/components/text_editor.vue'; import TextEditor from '~/pipeline_editor/components/text_editor.vue';
import EditorLite from '~/vue_shared/components/editor_lite.vue';
import PipelineGraph from '~/pipelines/components/pipeline_graph/pipeline_graph.vue'; import PipelineGraph from '~/pipelines/components/pipeline_graph/pipeline_graph.vue';
import PipelineEditorApp from '~/pipeline_editor/pipeline_editor_app.vue'; import PipelineEditorApp from '~/pipeline_editor/pipeline_editor_app.vue';
import CommitForm from '~/pipeline_editor/components/commit/commit_form.vue'; import CommitForm from '~/pipeline_editor/components/commit/commit_form.vue';
...@@ -39,10 +46,12 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -39,10 +46,12 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
let mockApollo; let mockApollo;
let mockBlobContentData; let mockBlobContentData;
const createComponent = ( const createComponent = ({
{ props = {}, loading = false, options = {} } = {}, props = {},
loading = false,
options = {},
mountFn = shallowMount, mountFn = shallowMount,
) => { } = {}) => {
mockMutate = jest.fn().mockResolvedValue({ mockMutate = jest.fn().mockResolvedValue({
data: { data: {
commitCreate: { commitCreate: {
...@@ -64,8 +73,11 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -64,8 +73,11 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
stubs: { stubs: {
GlTabs, GlTabs,
GlButton, GlButton,
TextEditor,
CommitForm, CommitForm,
EditorLite: {
template: '<div/>',
},
TextEditor,
}, },
mocks: { mocks: {
$apollo: { $apollo: {
...@@ -77,11 +89,13 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -77,11 +89,13 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
mutate: mockMutate, mutate: mockMutate,
}, },
}, },
// attachToDocument is required for input/submit events
attachToDocument: mountFn === mount,
...options, ...options,
}); });
}; };
const createComponentWithApollo = ({ props = {} } = {}, mountFn = shallowMount) => { const createComponentWithApollo = ({ props = {}, mountFn = shallowMount } = {}) => {
mockApollo = createMockApollo([], { mockApollo = createMockApollo([], {
Query: { Query: {
blobContent() { blobContent() {
...@@ -105,7 +119,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -105,7 +119,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
const findLoadingIcon = () => wrapper.find(GlLoadingIcon); const findLoadingIcon = () => wrapper.find(GlLoadingIcon);
const findAlert = () => wrapper.find(GlAlert); const findAlert = () => wrapper.find(GlAlert);
const findTabAt = i => wrapper.findAll(GlTab).at(i); const findTabAt = i => wrapper.findAll(GlTab).at(i);
const findEditorLite = () => wrapper.find(EditorLite); const findTextEditor = () => wrapper.find(TextEditor);
const findCommitForm = () => wrapper.find(CommitForm); const findCommitForm = () => wrapper.find(CommitForm);
const findCommitBtnLoadingIcon = () => wrapper.find('[type="submit"]').find(GlLoadingIcon); const findCommitBtnLoadingIcon = () => wrapper.find('[type="submit"]').find(GlLoadingIcon);
...@@ -127,7 +141,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -127,7 +141,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
createComponent({ loading: true }); createComponent({ loading: true });
expect(findLoadingIcon().exists()).toBe(true); expect(findLoadingIcon().exists()).toBe(true);
expect(findEditorLite().exists()).toBe(false); expect(findTextEditor().exists()).toBe(false);
}); });
describe('tabs', () => { describe('tabs', () => {
...@@ -138,7 +152,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -138,7 +152,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
it('displays tabs and their content', async () => { it('displays tabs and their content', async () => {
expect( expect(
findTabAt(0) findTabAt(0)
.find(EditorLite) .find(TextEditor)
.exists(), .exists(),
).toBe(true); ).toBe(true);
expect( expect(
...@@ -151,7 +165,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -151,7 +165,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
it('displays editor tab lazily, until editor is ready', async () => { it('displays editor tab lazily, until editor is ready', async () => {
expect(findTabAt(0).attributes('lazy')).toBe('true'); expect(findTabAt(0).attributes('lazy')).toBe('true');
findEditorLite().vm.$emit('editor-ready'); findTextEditor().vm.$emit('editor-ready');
await nextTick(); await nextTick();
...@@ -161,7 +175,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -161,7 +175,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
describe('when data is set', () => { describe('when data is set', () => {
beforeEach(async () => { beforeEach(async () => {
createComponent(); createComponent({ mountFn: mount });
wrapper.setData({ wrapper.setData({
content: mockCiYml, content: mockCiYml,
...@@ -173,7 +187,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -173,7 +187,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
it('displays content after the query loads', () => { it('displays content after the query loads', () => {
expect(findLoadingIcon().exists()).toBe(false); expect(findLoadingIcon().exists()).toBe(false);
expect(findEditorLite().props('value')).toBe(mockCiYml); expect(findTextEditor().attributes('value')).toBe(mockCiYml);
}); });
describe('commit form', () => { describe('commit form', () => {
...@@ -186,19 +200,29 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -186,19 +200,29 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
startBranch: mockDefaultBranch, startBranch: mockDefaultBranch,
}; };
const emitSubmit = event => { const findInForm = selector => findCommitForm().find(selector);
findCommitForm().vm.$emit('submit', {
message: mockCommitMessage, const submitCommit = async ({
branch: mockDefaultBranch, message = mockCommitMessage,
openMergeRequest: false, branch = mockDefaultBranch,
...event, openMergeRequest = false,
}); } = {}) => {
await findInForm(GlFormTextarea).setValue(message);
await findInForm(GlFormInput).setValue(branch);
if (openMergeRequest) {
await findInForm('[data-testid="new-mr-checkbox"]').setChecked(openMergeRequest);
}
await findInForm('[type="submit"]').trigger('click');
};
const cancelCommitForm = async () => {
const findCancelBtn = () => wrapper.find('[type="reset"]');
await findCancelBtn().trigger('click');
}; };
describe('when the user commits changes to the current branch', () => { describe('when the user commits changes to the current branch', () => {
beforeEach(async () => { beforeEach(async () => {
emitSubmit(); await submitCommit();
await nextTick();
}); });
it('calls the mutation with the default branch', () => { it('calls the mutation with the default branch', () => {
...@@ -212,7 +236,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -212,7 +236,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
}); });
it('refreshes the page', () => { it('refreshes the page', () => {
expect(refreshCurrentPage).toHaveBeenCalledWith(); expect(refreshCurrentPage).toHaveBeenCalled();
}); });
it('shows no saving state', () => { it('shows no saving state', () => {
...@@ -223,8 +247,8 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -223,8 +247,8 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
describe('when the user commits changes to a new branch', () => { describe('when the user commits changes to a new branch', () => {
const newBranch = 'new-branch'; const newBranch = 'new-branch';
beforeEach(() => { beforeEach(async () => {
emitSubmit({ await submitCommit({
branch: newBranch, branch: newBranch,
}); });
}); });
...@@ -247,8 +271,8 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -247,8 +271,8 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
describe('when the user commits changes to open a new merge request', () => { describe('when the user commits changes to open a new merge request', () => {
const newBranch = 'new-branch'; const newBranch = 'new-branch';
beforeEach(() => { beforeEach(async () => {
emitSubmit({ await submitCommit({
branch: newBranch, branch: newBranch,
openMergeRequest: true, openMergeRequest: true,
}); });
...@@ -271,7 +295,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -271,7 +295,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
return Promise.resolve(); return Promise.resolve();
}); });
findCommitForm().vm.$emit('submit', { await submitCommit({
message: mockCommitMessage, message: mockCommitMessage,
branch: mockDefaultBranch, branch: mockDefaultBranch,
openMergeRequest: false, openMergeRequest: false,
...@@ -283,7 +307,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -283,7 +307,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
it('shows a the error message', async () => { it('shows a the error message', async () => {
mockMutate.mockRejectedValueOnce(new Error('commit failed')); mockMutate.mockRejectedValueOnce(new Error('commit failed'));
emitSubmit(); await submitCommit();
await waitForPromises(); await waitForPromises();
...@@ -295,7 +319,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -295,7 +319,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
it('shows an unkown error', async () => { it('shows an unkown error', async () => {
mockMutate.mockRejectedValueOnce(); mockMutate.mockRejectedValueOnce();
emitSubmit(); await submitCommit();
await waitForPromises(); await waitForPromises();
...@@ -309,16 +333,14 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -309,16 +333,14 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
const otherContent = 'other content'; const otherContent = 'other content';
beforeEach(async () => { beforeEach(async () => {
findEditorLite().vm.$emit('input', otherContent); findTextEditor().vm.$emit('input', otherContent);
await nextTick(); await nextTick();
}); });
it('content is restored after cancel is called', async () => { it('content is restored after cancel is called', async () => {
findCommitForm().vm.$emit('cancel'); await cancelCommitForm();
await nextTick();
expect(findEditorLite().props('value')).toBe(mockCiYml); expect(findTextEditor().attributes('value')).toBe(mockCiYml);
}); });
}); });
}); });
...@@ -332,7 +354,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -332,7 +354,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
await waitForPromises(); await waitForPromises();
expect(findAlert().exists()).toBe(false); expect(findAlert().exists()).toBe(false);
expect(findEditorLite().props('value')).toBe(mockCiYml); expect(findTextEditor().attributes('value')).toBe(mockCiYml);
}); });
it('shows a 404 error message', async () => { it('shows a 404 error message', async () => {
......
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