debian-mirror-gitlab/spec/frontend/users_select/index_spec.js

96 lines
2.3 KiB
JavaScript
Raw Normal View History

2021-06-08 01:23:25 +05:30
import {
createInputsModelExpectation,
createUnassignedExpectation,
createAssignedExpectation,
createTestContext,
findDropdownItemsModel,
findDropdownItem,
findAssigneesInputsModel,
getUsersFixtureAt,
setAssignees,
toggleDropdown,
waitForDropdownItems,
} from './test_helper';
2021-04-29 21:17:54 +05:30
describe('~/users_select/index', () => {
2021-06-08 01:23:25 +05:30
const context = createTestContext({
fixturePath: 'merge_requests/merge_request_with_single_assignee_feature.html',
});
2021-04-29 21:17:54 +05:30
beforeEach(() => {
2021-06-08 01:23:25 +05:30
context.setup();
2021-04-29 21:17:54 +05:30
});
afterEach(() => {
2021-06-08 01:23:25 +05:30
context.teardown();
2021-04-29 21:17:54 +05:30
});
describe('when opened', () => {
beforeEach(async () => {
2021-06-08 01:23:25 +05:30
context.createSubject();
2021-04-29 21:17:54 +05:30
toggleDropdown();
await waitForDropdownItems();
});
it('shows users', () => {
expect(findDropdownItemsModel()).toEqual(createUnassignedExpectation());
});
describe('when users are selected', () => {
2021-06-08 01:23:25 +05:30
const selectedUsers = [getUsersFixtureAt(2), getUsersFixtureAt(4)];
const lastSelected = selectedUsers[selectedUsers.length - 1];
const expectation = createAssignedExpectation({
header: 'Assignee',
assigned: [lastSelected],
});
2021-04-29 21:17:54 +05:30
beforeEach(() => {
selectedUsers.forEach((user) => {
findDropdownItem(user).click();
});
});
it('shows assignee', () => {
expect(findDropdownItemsModel()).toEqual(expectation);
});
it('updates field', () => {
2021-06-08 01:23:25 +05:30
expect(findAssigneesInputsModel()).toEqual(createInputsModelExpectation([lastSelected]));
2021-04-29 21:17:54 +05:30
});
});
});
describe('with preselected user and opened', () => {
2021-06-08 01:23:25 +05:30
const expectation = createAssignedExpectation({
header: 'Assignee',
assigned: [getUsersFixtureAt(0)],
});
2021-04-29 21:17:54 +05:30
beforeEach(async () => {
2021-06-08 01:23:25 +05:30
setAssignees(getUsersFixtureAt(0));
2021-04-29 21:17:54 +05:30
2021-06-08 01:23:25 +05:30
context.createSubject();
2021-04-29 21:17:54 +05:30
toggleDropdown();
await waitForDropdownItems();
});
it('shows users', () => {
expect(findDropdownItemsModel()).toEqual(expectation);
});
// Regression test for https://gitlab.com/gitlab-org/gitlab/-/issues/325991
describe('when closed and reopened', () => {
beforeEach(() => {
toggleDropdown();
toggleDropdown();
});
it('shows users', () => {
expect(findDropdownItemsModel()).toEqual(expectation);
});
});
});
});