Commit 4d7d8dde authored by jakeburden's avatar jakeburden

Make testing DRYer

parent e40e2d04
...@@ -135,11 +135,17 @@ describe('noteActions', () => { ...@@ -135,11 +135,17 @@ describe('noteActions', () => {
}); });
describe('when a user has access to edit an issue', () => { describe('when a user has access to edit an issue', () => {
beforeEach(() => { const testButtonClickTriggersAction = () => {
axiosMock.onPut(`${TEST_HOST}/api/v4/projects/group/project/issues/1`).reply(() => { axiosMock.onPut(`${TEST_HOST}/api/v4/projects/group/project/issues/1`).reply(() => {
expect(actions.updateAssignees).toHaveBeenCalled(); expect(actions.updateAssignees).toHaveBeenCalled();
}); });
const assignUserButton = wrapper.find('[data-testid="assign-user"]');
expect(assignUserButton.exists()).toBe(true);
assignUserButton.trigger('click');
};
beforeEach(() => {
store.dispatch('setUserData', userDataMock); store.dispatch('setUserData', userDataMock);
store.dispatch('setNoteableData', { store.dispatch('setNoteableData', {
current_user: { current_user: {
...@@ -157,20 +163,16 @@ describe('noteActions', () => { ...@@ -157,20 +163,16 @@ describe('noteActions', () => {
axiosMock.restore(); axiosMock.restore();
}); });
it('should be possible to assign the comment author', () => { it('should be possible to assign the comment author', testButtonClickTriggersAction);
const assignUserButton = wrapper.find('[data-testid="assign-user"]'); it('should be possible to unassign the comment author', testButtonClickTriggersAction);
expect(assignUserButton.exists()).toBe(true);
assignUserButton.trigger('click');
}); });
it('should be possible to unassign the comment author', () => { describe('when a user does not have access to edit an issue', () => {
const testButtonDoesNotRender = () => {
const assignUserButton = wrapper.find('[data-testid="assign-user"]'); const assignUserButton = wrapper.find('[data-testid="assign-user"]');
expect(assignUserButton.exists()).toBe(true); expect(assignUserButton.exists()).toBe(false);
assignUserButton.trigger('click'); };
});
});
describe('when a user does not have access to edit an issue', () => {
beforeEach(() => { beforeEach(() => {
wrapper = shallowMountNoteActions(props, { wrapper = shallowMountNoteActions(props, {
targetType: () => 'issue', targetType: () => 'issue',
...@@ -181,15 +183,8 @@ describe('noteActions', () => { ...@@ -181,15 +183,8 @@ describe('noteActions', () => {
wrapper.destroy(); wrapper.destroy();
}); });
it('should not be possible to assign the comment author', () => { it('should not be possible to assign the comment author', testButtonDoesNotRender);
const assignUserButton = wrapper.find('[data-testid="assign-user"]'); it('should not be possible to unassign the comment author', testButtonDoesNotRender);
expect(assignUserButton.exists()).toBe(false);
});
it('should not be possible to unassign the comment author', () => {
const assignUserButton = wrapper.find('[data-testid="assign-user"]');
expect(assignUserButton.exists()).toBe(false);
});
}); });
describe('user is not logged in', () => { describe('user is not logged in', () => {
......
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