Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/issues/show/components/incidents/timeline_events_form_spec.js')
-rw-r--r--spec/frontend/issues/show/components/incidents/timeline_events_form_spec.js117
1 files changed, 19 insertions, 98 deletions
diff --git a/spec/frontend/issues/show/components/incidents/timeline_events_form_spec.js b/spec/frontend/issues/show/components/incidents/timeline_events_form_spec.js
index 620cdfc53b0..cd2cbb63246 100644
--- a/spec/frontend/issues/show/components/incidents/timeline_events_form_spec.js
+++ b/spec/frontend/issues/show/components/incidents/timeline_events_form_spec.js
@@ -3,49 +3,33 @@ import Vue, { nextTick } from 'vue';
import { GlDatepicker } from '@gitlab/ui';
import { shallowMountExtended, mountExtended } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises';
-import IncidentTimelineEventForm from '~/issues/show/components/incidents/timeline_events_form.vue';
-import createTimelineEventMutation from '~/issues/show/components/incidents/graphql/queries/create_timeline_event.mutation.graphql';
-import createMockApollo from 'helpers/mock_apollo_helper';
+import TimelineEventsForm from '~/issues/show/components/incidents/timeline_events_form.vue';
import { createAlert } from '~/flash';
import { useFakeDate } from 'helpers/fake_date';
-import { timelineEventsCreateEventResponse, timelineEventsCreateEventError } from './mock_data';
Vue.use(VueApollo);
jest.mock('~/flash');
-const addEventResponse = jest.fn().mockResolvedValue(timelineEventsCreateEventResponse);
-
-function createMockApolloProvider(response = addEventResponse) {
- const requestHandlers = [[createTimelineEventMutation, response]];
- return createMockApollo(requestHandlers);
-}
+const fakeDate = '2020-07-08T00:00:00.000Z';
describe('Timeline events form', () => {
// July 8 2020
- useFakeDate(2020, 6, 8);
+ useFakeDate(fakeDate);
let wrapper;
- const mountComponent = ({ mockApollo, mountMethod = shallowMountExtended, stubs }) => {
- wrapper = mountMethod(IncidentTimelineEventForm, {
+ const mountComponent = ({ mountMethod = shallowMountExtended }) => {
+ wrapper = mountMethod(TimelineEventsForm, {
propsData: {
hasTimelineEvents: true,
+ isEventProcessed: false,
},
- provide: {
- fullPath: 'group/project',
- issuableId: '1',
- },
- apolloProvider: mockApollo,
- stubs,
});
};
afterEach(() => {
- addEventResponse.mockReset();
createAlert.mockReset();
- if (wrapper) {
- wrapper.destroy();
- }
+ wrapper.destroy();
});
const findSubmitButton = () => wrapper.findByText('Save');
@@ -75,24 +59,28 @@ describe('Timeline events form', () => {
};
describe('form button behaviour', () => {
- const closeFormEvent = { 'hide-incident-timeline-event-form': [[]] };
beforeEach(() => {
- mountComponent({ mockApollo: createMockApolloProvider(), mountMethod: mountExtended });
+ mountComponent({ mountMethod: mountExtended });
});
- it('should close the form on submit', async () => {
+ it('should save event on submit', async () => {
await submitForm();
- expect(wrapper.emitted()).toEqual(closeFormEvent);
+
+ expect(wrapper.emitted()).toEqual({
+ 'save-event': [[{ note: '', occurredAt: fakeDate }, false]],
+ });
});
- it('should not close the form on "submit and add another"', async () => {
+ it('should save event on "submit and add another"', async () => {
await submitFormAndAddAnother();
- expect(wrapper.emitted()).toEqual({});
+ expect(wrapper.emitted()).toEqual({
+ 'save-event': [[{ note: '', occurredAt: fakeDate }, true]],
+ });
});
- it('should close the form on cancel', async () => {
+ it('should emit cancel on cancel', async () => {
await cancelForm();
- expect(wrapper.emitted()).toEqual(closeFormEvent);
+ expect(wrapper.emitted()).toEqual({ cancel: [[]] });
});
it('should clear the form', async () => {
@@ -111,71 +99,4 @@ describe('Timeline events form', () => {
expect(findMinuteInput().element.value).toBe('0');
});
});
-
- describe('addTimelineEventQuery', () => {
- const expectedData = {
- input: {
- incidentId: 'gid://gitlab/Issue/1',
- note: '',
- occurredAt: '2020-07-08T00:00:00.000Z',
- },
- };
-
- let mockApollo;
-
- beforeEach(() => {
- mockApollo = createMockApolloProvider();
- mountComponent({ mockApollo, mountMethod: mountExtended });
- });
-
- it('should call the mutation with the right variables', async () => {
- await submitForm();
-
- expect(addEventResponse).toHaveBeenCalledWith(expectedData);
- });
-
- it('should call the mutation with user selected variables', async () => {
- const expectedUserSelectedData = {
- input: {
- ...expectedData.input,
- occurredAt: '2021-08-12T05:45:00.000Z',
- },
- };
-
- setDatetime();
-
- await nextTick();
- await submitForm();
-
- expect(addEventResponse).toHaveBeenCalledWith(expectedUserSelectedData);
- });
- });
-
- describe('error handling', () => {
- it('should show an error when submission returns an error', async () => {
- const expectedAlertArgs = {
- message: 'Error creating incident timeline event: Create error',
- };
- addEventResponse.mockResolvedValueOnce(timelineEventsCreateEventError);
- mountComponent({ mockApollo: createMockApolloProvider(), mountMethod: mountExtended });
-
- await submitForm();
-
- expect(createAlert).toHaveBeenCalledWith(expectedAlertArgs);
- });
-
- it('should show an error when submission fails', async () => {
- const expectedAlertArgs = {
- captureError: true,
- error: new Error(),
- message: 'Something went wrong while creating the incident timeline event.',
- };
- addEventResponse.mockRejectedValueOnce();
- mountComponent({ mockApollo: createMockApolloProvider(), mountMethod: mountExtended });
-
- await submitForm();
-
- expect(createAlert).toHaveBeenCalledWith(expectedAlertArgs);
- });
- });
});