Skip to content
代码片段 群组 项目
提交 d3c4fe56 编辑于 作者: Artur Fedorov's avatar Artur Fedorov 提交者: GitLab Bot
浏览文件

This MR removes direct data manipulation

As part of Vue 3 migration
overriding method behavior and
direct data manipulation
should be avoided
上级 22ad42d0
No related branches found
No related tags found
无相关合并请求
import Vue, { nextTick } from 'vue'; import Vue, { nextTick } from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import { GlAlert, GlModal } from '@gitlab/ui'; import { GlAlert, GlModal, GlFormInput, GlDatepicker, GlFormTextarea } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import { stubComponent } from 'helpers/stub_component';
import { convertToGraphQLId } from '~/graphql_shared/utils'; import { convertToGraphQLId } from '~/graphql_shared/utils';
import CreateTimelogForm from '~/sidebar/components/time_tracking/create_timelog_form.vue'; import CreateTimelogForm from '~/sidebar/components/time_tracking/create_timelog_form.vue';
import createTimelogMutation from '~/sidebar/queries/create_timelog.mutation.graphql'; import createTimelogMutation from '~/sidebar/queries/create_timelog.mutation.graphql';
...@@ -49,21 +50,19 @@ describe('Create Timelog Form', () => { ...@@ -49,21 +50,19 @@ describe('Create Timelog Form', () => {
const findSaveButton = () => findModal().props('actionPrimary'); const findSaveButton = () => findModal().props('actionPrimary');
const findSaveButtonLoadingState = () => findSaveButton().attributes.loading; const findSaveButtonLoadingState = () => findSaveButton().attributes.loading;
const findSaveButtonDisabledState = () => findSaveButton().attributes.disabled; const findSaveButtonDisabledState = () => findSaveButton().attributes.disabled;
const findGlFormInput = () => wrapper.findComponent(GlFormInput);
const findGlDatepicker = () => wrapper.findComponent(GlDatepicker);
const findGlFormTextarea = () => wrapper.findComponent(GlFormTextarea);
const submitForm = () => findForm().trigger('submit'); const submitForm = () => findForm().trigger('submit');
const mountComponent = ( const mountComponent = (
{ props, data, providedProps } = {}, { props, providedProps } = {},
mutationResolverMock = rejectedMutationMock, mutationResolverMock = rejectedMutationMock,
) => { ) => {
fakeApollo = createMockApollo([[createTimelogMutation, mutationResolverMock]]); fakeApollo = createMockApollo([[createTimelogMutation, mutationResolverMock]]);
wrapper = shallowMountExtended(CreateTimelogForm, { wrapper = shallowMountExtended(CreateTimelogForm, {
data() {
return {
...data,
};
},
provide: { provide: {
issuableType: 'issue', issuableType: 'issue',
...providedProps, ...providedProps,
...@@ -73,13 +72,17 @@ describe('Create Timelog Form', () => { ...@@ -73,13 +72,17 @@ describe('Create Timelog Form', () => {
...props, ...props,
}, },
apolloProvider: fakeApollo, apolloProvider: fakeApollo,
stubs: {
GlModal: stubComponent(GlModal, {
methods: { close: modalCloseMock },
}),
},
}); });
wrapper.vm.$refs.modal.close = modalCloseMock;
}; };
afterEach(() => { afterEach(() => {
fakeApollo = null; fakeApollo = null;
modalCloseMock.mockClear();
}); });
describe('save button', () => { describe('save button', () => {
...@@ -90,15 +93,18 @@ describe('Create Timelog Form', () => { ...@@ -90,15 +93,18 @@ describe('Create Timelog Form', () => {
expect(findSaveButtonDisabledState()).toBe(true); expect(findSaveButtonDisabledState()).toBe(true);
}); });
it('is enabled and not loading when time spent is not empty', () => { it('is enabled and not loading when time spent is not empty', async () => {
mountComponent({ data: { timeSpent: '2d' } }); mountComponent();
await findGlFormInput().vm.$emit('input', '2d');
expect(findSaveButtonLoadingState()).toBe(false); expect(findSaveButtonLoadingState()).toBe(false);
expect(findSaveButtonDisabledState()).toBe(false); expect(findSaveButtonDisabledState()).toBe(false);
}); });
it('is disabled and loading when the the form is submitted', async () => { it('is disabled and loading when the the form is submitted', async () => {
mountComponent({ data: { timeSpent: '2d' } }); mountComponent();
await findGlFormInput().vm.$emit('input', '2d');
submitForm(); submitForm();
...@@ -109,7 +115,8 @@ describe('Create Timelog Form', () => { ...@@ -109,7 +115,8 @@ describe('Create Timelog Form', () => {
}); });
it('is enabled and not loading the when form is submitted but the mutation has errors', async () => { it('is enabled and not loading the when form is submitted but the mutation has errors', async () => {
mountComponent({ data: { timeSpent: '2d' } }); mountComponent();
await findGlFormInput().vm.$emit('input', '2d');
submitForm(); submitForm();
...@@ -121,7 +128,8 @@ describe('Create Timelog Form', () => { ...@@ -121,7 +128,8 @@ describe('Create Timelog Form', () => {
}); });
it('is enabled and not loading the when form is submitted but the mutation returns errors', async () => { it('is enabled and not loading the when form is submitted but the mutation returns errors', async () => {
mountComponent({ data: { timeSpent: '2d' } }, resolvedMutationWithErrorsMock); mountComponent({}, resolvedMutationWithErrorsMock);
await findGlFormInput().vm.$emit('input', '2d');
submitForm(); submitForm();
...@@ -145,7 +153,8 @@ describe('Create Timelog Form', () => { ...@@ -145,7 +153,8 @@ describe('Create Timelog Form', () => {
}); });
it('closes the modal after a successful mutation', async () => { it('closes the modal after a successful mutation', async () => {
mountComponent({ data: { timeSpent: '2d' } }, resolvedMutationWithoutErrorsMock); mountComponent({}, resolvedMutationWithoutErrorsMock);
await findGlFormInput().vm.$emit('input', '2d');
submitForm(); submitForm();
...@@ -166,7 +175,10 @@ describe('Create Timelog Form', () => { ...@@ -166,7 +175,10 @@ describe('Create Timelog Form', () => {
const spentAt = '2022-11-20T21:53:00+0000'; const spentAt = '2022-11-20T21:53:00+0000';
const summary = 'Example'; const summary = 'Example';
mountComponent({ data: { timeSpent, spentAt, summary }, providedProps: { issuableType } }); mountComponent({ providedProps: { issuableType } });
await findGlFormInput().vm.$emit('input', timeSpent);
await findGlDatepicker().vm.$emit('input', spentAt);
await findGlFormTextarea().vm.$emit('input', summary);
submitForm(); submitForm();
...@@ -187,7 +199,8 @@ describe('Create Timelog Form', () => { ...@@ -187,7 +199,8 @@ describe('Create Timelog Form', () => {
}); });
it('shows an error if the submission fails with a handled error', async () => { it('shows an error if the submission fails with a handled error', async () => {
mountComponent({ data: { timeSpent: '2d' } }, resolvedMutationWithErrorsMock); mountComponent({}, resolvedMutationWithErrorsMock);
await findGlFormInput().vm.$emit('input', '2d');
submitForm(); submitForm();
...@@ -198,7 +211,8 @@ describe('Create Timelog Form', () => { ...@@ -198,7 +211,8 @@ describe('Create Timelog Form', () => {
}); });
it('shows an error if the submission fails with an unhandled error', async () => { it('shows an error if the submission fails with an unhandled error', async () => {
mountComponent({ data: { timeSpent: '2d' } }); mountComponent();
await findGlFormInput().vm.$emit('input', '2d');
submitForm(); submitForm();
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册