Commit 5993f64e authored by Tom Quirk's avatar Tom Quirk

Test error handling for invalid design version

Adds a test for the case when we do not have a
design for the given query parameter.

Also adds all_versions mock data, and cleans
up some of the pages/design/index_spec
parent 30845ac4
export default [
{
node: {
id: 'gid://gitlab/DesignManagement::Version/1',
sha: 'b389071a06c153509e11da1f582005b316667001',
},
},
];
...@@ -8,8 +8,13 @@ import DesignReplyForm from 'ee/design_management/components/design_notes/design ...@@ -8,8 +8,13 @@ import DesignReplyForm from 'ee/design_management/components/design_notes/design
import Participants from '~/sidebar/components/participants/participants.vue'; import Participants from '~/sidebar/components/participants/participants.vue';
import createImageDiffNoteMutation from 'ee/design_management/graphql/mutations/createImageDiffNote.mutation.graphql'; import createImageDiffNoteMutation from 'ee/design_management/graphql/mutations/createImageDiffNote.mutation.graphql';
import design from '../../mock_data/design'; import design from '../../mock_data/design';
import mockResponseWithDesigns from '../../mock_data/designs';
import mockResponseNoDesigns from '../../mock_data/no_designs'; import mockResponseNoDesigns from '../../mock_data/no_designs';
import { DESIGN_NOT_FOUND_ERROR } from 'ee/design_management/utils/error_messages'; import mockAllVersions from '../../mock_data/all_versions';
import {
DESIGN_NOT_FOUND_ERROR,
DESIGN_VERSION_NOT_EXIST_ERROR,
} from 'ee/design_management/utils/error_messages';
import { DESIGNS_ROUTE_NAME } from 'ee/design_management/router/constants'; import { DESIGNS_ROUTE_NAME } from 'ee/design_management/router/constants';
jest.mock('~/flash'); jest.mock('~/flash');
...@@ -53,7 +58,7 @@ describe('Design management design index page', () => { ...@@ -53,7 +58,7 @@ describe('Design management design index page', () => {
const findDiscussionForm = () => wrapper.find(DesignReplyForm); const findDiscussionForm = () => wrapper.find(DesignReplyForm);
const findParticipants = () => wrapper.find(Participants); const findParticipants = () => wrapper.find(Participants);
function createComponent(loading = false) { function createComponent(loading = false, { routeQuery = {} } = {}) {
const $apollo = { const $apollo = {
queries: { queries: {
design: { design: {
...@@ -65,12 +70,15 @@ describe('Design management design index page', () => { ...@@ -65,12 +70,15 @@ describe('Design management design index page', () => {
const $router = { const $router = {
push: routerPush, push: routerPush,
query: {}, };
const $route = {
query: routeQuery,
}; };
wrapper = shallowMount(DesignIndex, { wrapper = shallowMount(DesignIndex, {
propsData: { id: '1' }, propsData: { id: '1' },
mocks: { $apollo, $router }, mocks: { $apollo, $router, $route },
stubs: { stubs: {
ApolloMutation, ApolloMutation,
}, },
...@@ -86,6 +94,12 @@ describe('Design management design index page', () => { ...@@ -86,6 +94,12 @@ describe('Design management design index page', () => {
wrapper.vm.$apollo.queries.design.loading = false; wrapper.vm.$apollo.queries.design.loading = false;
} }
function setDesignData() {
wrapper.setData({
design,
});
}
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
...@@ -100,10 +114,7 @@ describe('Design management design index page', () => { ...@@ -100,10 +114,7 @@ describe('Design management design index page', () => {
it('renders design index', () => { it('renders design index', () => {
setDesign(); setDesign();
setDesignData();
wrapper.setData({
design,
});
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
...@@ -113,10 +124,7 @@ describe('Design management design index page', () => { ...@@ -113,10 +124,7 @@ describe('Design management design index page', () => {
it('renders participants', () => { it('renders participants', () => {
setDesign(); setDesign();
setDesignData();
wrapper.setData({
design,
});
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(findParticipants().exists()).toBe(true); expect(findParticipants().exists()).toBe(true);
...@@ -153,10 +161,7 @@ describe('Design management design index page', () => { ...@@ -153,10 +161,7 @@ describe('Design management design index page', () => {
describe('when has discussions', () => { describe('when has discussions', () => {
beforeEach(() => { beforeEach(() => {
setDesign(); setDesign();
setDesignData();
wrapper.setData({
design,
});
}); });
it('renders correct amount of discussions', () => { it('renders correct amount of discussions', () => {
...@@ -258,18 +263,37 @@ describe('Design management design index page', () => { ...@@ -258,18 +263,37 @@ describe('Design management design index page', () => {
}); });
describe('onDesignQueryResult', () => { describe('onDesignQueryResult', () => {
describe('with no designs', () => { const mockOnQueryError = () => {
it('redirects to /designs', () => {
createComponent(true);
wrapper.setMethods({ wrapper.setMethods({
onQueryError: jest.fn(), onQueryError: jest.fn(),
}); });
};
describe('with no designs', () => {
it('redirects to /designs', () => {
createComponent(true);
mockOnQueryError();
wrapper.vm.onDesignQueryResult(mockResponseNoDesigns); wrapper.vm.onDesignQueryResult({ data: mockResponseNoDesigns, loading: false });
expect(wrapper.vm.onQueryError).toHaveBeenCalledTimes(1); expect(wrapper.vm.onQueryError).toHaveBeenCalledTimes(1);
expect(wrapper.vm.onQueryError).toHaveBeenCalledWith(DESIGN_NOT_FOUND_ERROR); expect(wrapper.vm.onQueryError).toHaveBeenCalledWith(DESIGN_NOT_FOUND_ERROR);
}); });
}); });
describe('when no design exists for given version', () => {
it('redirects to /designs', () => {
// attempt to query for a version of the design that doesn't exist
createComponent(true, { routeQuery: { version: '999' } });
mockOnQueryError();
wrapper.setData({
allVersions: mockAllVersions,
});
wrapper.vm.onDesignQueryResult({ data: mockResponseWithDesigns, loading: false });
expect(wrapper.vm.onQueryError).toHaveBeenCalledTimes(1);
expect(wrapper.vm.onQueryError).toHaveBeenCalledWith(DESIGN_VERSION_NOT_EXIST_ERROR);
});
});
}); });
describe('onQueryError', () => { describe('onQueryError', () => {
......
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