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/sidebar/components')
-rw-r--r--spec/frontend/sidebar/components/assignees/collapsed_assignee_spec.js8
-rw-r--r--spec/frontend/sidebar/components/assignees/sidebar_assignees_widget_spec.js44
-rw-r--r--spec/frontend/sidebar/components/assignees/user_name_with_status_spec.js44
-rw-r--r--spec/frontend/sidebar/components/sidebar_dropdown_widget_spec.js6
-rw-r--r--spec/frontend/sidebar/components/todo_toggle/sidebar_todo_widget_spec.js126
5 files changed, 197 insertions, 31 deletions
diff --git a/spec/frontend/sidebar/components/assignees/collapsed_assignee_spec.js b/spec/frontend/sidebar/components/assignees/collapsed_assignee_spec.js
index b49e6255923..2d5a3653631 100644
--- a/spec/frontend/sidebar/components/assignees/collapsed_assignee_spec.js
+++ b/spec/frontend/sidebar/components/assignees/collapsed_assignee_spec.js
@@ -1,7 +1,6 @@
-import { shallowMount } from '@vue/test-utils';
+import { mount } from '@vue/test-utils';
import AssigneeAvatar from '~/sidebar/components/assignees/assignee_avatar.vue';
import CollapsedAssignee from '~/sidebar/components/assignees/collapsed_assignee.vue';
-import UserNameWithStatus from '~/sidebar/components/assignees/user_name_with_status.vue';
import userDataMock from '../../user_data_mock';
const TEST_USER = userDataMock();
@@ -17,11 +16,8 @@ describe('CollapsedAssignee assignee component', () => {
...props,
};
- wrapper = shallowMount(CollapsedAssignee, {
+ wrapper = mount(CollapsedAssignee, {
propsData,
- stubs: {
- UserNameWithStatus,
- },
});
}
diff --git a/spec/frontend/sidebar/components/assignees/sidebar_assignees_widget_spec.js b/spec/frontend/sidebar/components/assignees/sidebar_assignees_widget_spec.js
index 0e052abffeb..8504684d23a 100644
--- a/spec/frontend/sidebar/components/assignees/sidebar_assignees_widget_spec.js
+++ b/spec/frontend/sidebar/components/assignees/sidebar_assignees_widget_spec.js
@@ -176,7 +176,7 @@ describe('Sidebar assignees widget', () => {
).toBe(true);
});
- it('emits an event with assignees list on successful mutation', async () => {
+ it('emits an event with assignees list and issuable id on successful mutation', async () => {
createComponent();
await waitForPromises();
@@ -193,18 +193,21 @@ describe('Sidebar assignees widget', () => {
expect(wrapper.emitted('assignees-updated')).toEqual([
[
- [
- {
- __typename: 'User',
- avatarUrl:
- 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
- id: 'gid://gitlab/User/1',
- name: 'Administrator',
- username: 'root',
- webUrl: '/root',
- status: null,
- },
- ],
+ {
+ assignees: [
+ {
+ __typename: 'User',
+ avatarUrl:
+ 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
+ id: 'gid://gitlab/User/1',
+ name: 'Administrator',
+ username: 'root',
+ webUrl: '/root',
+ status: null,
+ },
+ ],
+ id: 1,
+ },
],
]);
});
@@ -285,6 +288,21 @@ describe('Sidebar assignees widget', () => {
expect(updateIssueAssigneesMutationSuccess).not.toHaveBeenCalled();
expect(findUserSelect().isVisible()).toBe(true);
});
+
+ it('calls the mutation old issuable id if `iid` prop was changed', async () => {
+ findUserSelect().vm.$emit('input', [{ username: 'francina.skiles' }]);
+ wrapper.setProps({
+ iid: '2',
+ });
+ await nextTick();
+ findEditableItem().vm.$emit('close');
+
+ expect(updateIssueAssigneesMutationSuccess).toHaveBeenCalledWith({
+ assigneeUsernames: ['francina.skiles'],
+ fullPath: '/mygroup/myProject',
+ iid: '1',
+ });
+ });
});
it('shows an error if update assignees mutation is rejected', async () => {
diff --git a/spec/frontend/sidebar/components/assignees/user_name_with_status_spec.js b/spec/frontend/sidebar/components/assignees/user_name_with_status_spec.js
index 9483c6624c5..4dbf3d426bb 100644
--- a/spec/frontend/sidebar/components/assignees/user_name_with_status_spec.js
+++ b/spec/frontend/sidebar/components/assignees/user_name_with_status_spec.js
@@ -1,25 +1,21 @@
-import { GlSprintf } from '@gitlab/ui';
-import { shallowMount } from '@vue/test-utils';
+import { mount } from '@vue/test-utils';
import { AVAILABILITY_STATUS } from '~/set_status_modal/utils';
import UserNameWithStatus from '~/sidebar/components/assignees/user_name_with_status.vue';
-const name = 'Goku';
+const name = 'Administrator';
const containerClasses = 'gl-cool-class gl-over-9000';
describe('UserNameWithStatus', () => {
let wrapper;
function createComponent(props = {}) {
- return shallowMount(UserNameWithStatus, {
+ wrapper = mount(UserNameWithStatus, {
propsData: { name, containerClasses, ...props },
- stubs: {
- GlSprintf,
- },
});
}
beforeEach(() => {
- wrapper = createComponent();
+ createComponent();
});
afterEach(() => {
@@ -41,11 +37,39 @@ describe('UserNameWithStatus', () => {
describe(`with availability="${AVAILABILITY_STATUS.BUSY}"`, () => {
beforeEach(() => {
- wrapper = createComponent({ availability: AVAILABILITY_STATUS.BUSY });
+ createComponent({ availability: AVAILABILITY_STATUS.BUSY });
});
it('will render "Busy"', () => {
- expect(wrapper.html()).toContain('Goku (Busy)');
+ expect(wrapper.text()).toContain('(Busy)');
+ });
+ });
+
+ describe('when user has pronouns set', () => {
+ const pronouns = 'they/them';
+
+ beforeEach(() => {
+ createComponent({ pronouns });
+ });
+
+ it("renders user's name with pronouns", () => {
+ expect(wrapper.text()).toMatchInterpolatedText(`${name} (${pronouns})`);
+ });
+ });
+
+ describe('when user does not have pronouns set', () => {
+ describe.each`
+ pronouns
+ ${undefined}
+ ${null}
+ ${''}
+ ${' '}
+ `('when `pronouns` prop is $pronouns', ({ pronouns }) => {
+ it("renders only the user's name", () => {
+ createComponent({ pronouns });
+
+ expect(wrapper.text()).toMatchInterpolatedText(name);
+ });
});
});
});
diff --git a/spec/frontend/sidebar/components/sidebar_dropdown_widget_spec.js b/spec/frontend/sidebar/components/sidebar_dropdown_widget_spec.js
index 8d58854b013..f5e5ab4a984 100644
--- a/spec/frontend/sidebar/components/sidebar_dropdown_widget_spec.js
+++ b/spec/frontend/sidebar/components/sidebar_dropdown_widget_spec.js
@@ -451,8 +451,9 @@ describe('SidebarDropdownWidget', () => {
expect(projectMilestonesSpy).toHaveBeenNthCalledWith(1, {
fullPath: mockIssue.projectPath,
- title: '',
+ sort: null,
state: 'active',
+ title: '',
});
});
@@ -477,8 +478,9 @@ describe('SidebarDropdownWidget', () => {
expect(projectMilestonesSpy).toHaveBeenNthCalledWith(2, {
fullPath: mockIssue.projectPath,
- title: mockSearchTerm,
+ sort: null,
state: 'active',
+ title: mockSearchTerm,
});
});
});
diff --git a/spec/frontend/sidebar/components/todo_toggle/sidebar_todo_widget_spec.js b/spec/frontend/sidebar/components/todo_toggle/sidebar_todo_widget_spec.js
new file mode 100644
index 00000000000..23f1753c4bf
--- /dev/null
+++ b/spec/frontend/sidebar/components/todo_toggle/sidebar_todo_widget_spec.js
@@ -0,0 +1,126 @@
+import { GlIcon } from '@gitlab/ui';
+import { shallowMount } from '@vue/test-utils';
+import Vue from 'vue';
+import VueApollo from 'vue-apollo';
+import createMockApollo from 'helpers/mock_apollo_helper';
+import waitForPromises from 'helpers/wait_for_promises';
+import createFlash from '~/flash';
+import SidebarTodoWidget from '~/sidebar/components/todo_toggle/sidebar_todo_widget.vue';
+import epicTodoQuery from '~/sidebar/queries/epic_todo.query.graphql';
+import TodoButton from '~/vue_shared/components/sidebar/todo_toggle/todo_button.vue';
+import { todosResponse, noTodosResponse } from '../../mock_data';
+
+jest.mock('~/flash');
+
+Vue.use(VueApollo);
+
+describe('Sidebar Todo Widget', () => {
+ let wrapper;
+ let fakeApollo;
+
+ const findTodoButton = () => wrapper.findComponent(TodoButton);
+
+ const createComponent = ({
+ todosQueryHandler = jest.fn().mockResolvedValue(noTodosResponse),
+ } = {}) => {
+ fakeApollo = createMockApollo([[epicTodoQuery, todosQueryHandler]]);
+
+ wrapper = shallowMount(SidebarTodoWidget, {
+ apolloProvider: fakeApollo,
+ provide: {
+ canUpdate: true,
+ isClassicSidebar: true,
+ },
+ propsData: {
+ fullPath: 'group',
+ issuableIid: '1',
+ issuableId: 'gid://gitlab/Epic/4',
+ issuableType: 'epic',
+ },
+ });
+ };
+
+ afterEach(() => {
+ wrapper.destroy();
+ fakeApollo = null;
+ });
+
+ describe('when user does not have a todo for the issuable', () => {
+ beforeEach(() => {
+ createComponent();
+ return waitForPromises();
+ });
+
+ it('passes false isTodo prop to Todo button component', () => {
+ expect(findTodoButton().props('isTodo')).toBe(false);
+ });
+
+ it('emits `todoUpdated` event with a `false` payload', () => {
+ expect(wrapper.emitted('todoUpdated')).toEqual([[false]]);
+ });
+ });
+
+ describe('when user has a todo for the issuable', () => {
+ beforeEach(() => {
+ createComponent({
+ todosQueryHandler: jest.fn().mockResolvedValue(todosResponse),
+ });
+ return waitForPromises();
+ });
+
+ it('passes true isTodo prop to Todo button component', () => {
+ expect(findTodoButton().props('isTodo')).toBe(true);
+ });
+
+ it('emits `todoUpdated` event with a `true` payload', () => {
+ expect(wrapper.emitted('todoUpdated')).toEqual([[true]]);
+ });
+ });
+
+ it('displays a flash message when query is rejected', async () => {
+ createComponent({
+ todosQueryHandler: jest.fn().mockRejectedValue('Houston, we have a problem'),
+ });
+ await waitForPromises();
+
+ expect(createFlash).toHaveBeenCalled();
+ });
+
+ describe('collapsed', () => {
+ const event = { stopPropagation: jest.fn(), preventDefault: jest.fn() };
+
+ beforeEach(() => {
+ createComponent({
+ todosQueryHandler: jest.fn().mockResolvedValue(noTodosResponse),
+ });
+ return waitForPromises();
+ });
+
+ it('shows add todo icon', () => {
+ expect(wrapper.find(GlIcon).exists()).toBe(true);
+
+ expect(wrapper.find(GlIcon).props('name')).toBe('todo-add');
+ });
+
+ it('sets default tooltip title', () => {
+ expect(wrapper.find(GlIcon).attributes('title')).toBe('Add a to do');
+ });
+
+ it('when user has a to do', async () => {
+ createComponent({
+ todosQueryHandler: jest.fn().mockResolvedValue(todosResponse),
+ });
+
+ await waitForPromises();
+ expect(wrapper.find(GlIcon).props('name')).toBe('todo-done');
+ expect(wrapper.find(GlIcon).attributes('title')).toBe('Mark as done');
+ });
+
+ it('emits `todoUpdated` event on click on icon', async () => {
+ wrapper.find(GlIcon).vm.$emit('click', event);
+
+ await wrapper.vm.$nextTick();
+ expect(wrapper.emitted('todoUpdated')).toEqual([[false]]);
+ });
+ });
+});