debian-mirror-gitlab/spec/frontend/vue_shared/alert_details/alert_management_sidebar_todo_spec.js

113 lines
3.2 KiB
JavaScript
Raw Normal View History

2020-07-28 23:09:34 +05:30
import { mount } from '@vue/test-utils';
2020-11-24 15:15:51 +05:30
import todoMarkDoneMutation from '~/graphql_shared/mutations/todo_mark_done.mutation.graphql';
2021-03-11 19:13:27 +05:30
import SidebarTodo from '~/vue_shared/alert_details/components/sidebar/sidebar_todo.vue';
import createAlertTodoMutation from '~/vue_shared/alert_details/graphql/mutations/alert_todo_create.mutation.graphql';
import mockAlerts from './mocks/alerts.json';
2020-07-28 23:09:34 +05:30
const mockAlert = mockAlerts[0];
describe('Alert Details Sidebar To Do', () => {
let wrapper;
function mountComponent({ data, sidebarCollapsed = true, loading = false, stubs = {} } = {}) {
wrapper = mount(SidebarTodo, {
propsData: {
alert: { ...mockAlert },
...data,
sidebarCollapsed,
projectPath: 'projectPath',
},
mocks: {
$apollo: {
mutate: jest.fn(),
queries: {
alert: {
loading,
},
},
},
},
stubs,
});
}
afterEach(() => {
wrapper.destroy();
});
2020-10-24 23:57:45 +05:30
const findToDoButton = () => wrapper.find('[data-testid="alert-todo-button"]');
2020-07-28 23:09:34 +05:30
describe('updating the alert to do', () => {
const mockUpdatedMutationResult = {
data: {
updateAlertTodo: {
errors: [],
alert: {},
},
},
};
2020-10-24 23:57:45 +05:30
describe('adding a todo', () => {
beforeEach(() => {
mountComponent({
data: { alert: mockAlert },
sidebarCollapsed: false,
loading: false,
});
2020-07-28 23:09:34 +05:30
});
2020-10-24 23:57:45 +05:30
it('renders a button for adding a To-Do', async () => {
await wrapper.vm.$nextTick();
2021-03-11 19:13:27 +05:30
expect(findToDoButton().text()).toBe('Add a to do');
2020-07-28 23:09:34 +05:30
});
2020-11-24 15:15:51 +05:30
it('calls `$apollo.mutate` with `createAlertTodoMutation` mutation and variables containing `iid`, `todoEvent`, & `projectPath`', async () => {
2020-10-24 23:57:45 +05:30
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValue(mockUpdatedMutationResult);
findToDoButton().trigger('click');
await wrapper.vm.$nextTick();
2020-07-28 23:09:34 +05:30
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
2020-11-24 15:15:51 +05:30
mutation: createAlertTodoMutation,
2020-07-28 23:09:34 +05:30
variables: {
iid: '1527542',
projectPath: 'projectPath',
},
});
});
});
2020-11-24 15:15:51 +05:30
2020-10-24 23:57:45 +05:30
describe('removing a todo', () => {
beforeEach(() => {
mountComponent({
data: { alert: { ...mockAlert, todos: { nodes: [{ id: '1234' }] } } },
sidebarCollapsed: false,
loading: false,
});
});
it('renders a Mark As Done button when todo is present', async () => {
await wrapper.vm.$nextTick();
expect(findToDoButton().text()).toBe('Mark as done');
});
2020-11-24 15:15:51 +05:30
it('calls `$apollo.mutate` with `todoMarkDoneMutation` mutation and variables containing `id`', async () => {
2020-10-24 23:57:45 +05:30
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValue(mockUpdatedMutationResult);
findToDoButton().trigger('click');
await wrapper.vm.$nextTick();
2020-11-24 15:15:51 +05:30
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
mutation: todoMarkDoneMutation,
update: expect.anything(),
variables: {
id: '1234',
},
});
2020-10-24 23:57:45 +05:30
});
});
2020-07-28 23:09:34 +05:30
});
});