diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-19 21:08:23 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-19 21:08:23 +0300 |
commit | 3f0db3db2ad99a74c3969bf2e930814004ccf1ec (patch) | |
tree | c8b4123b3b4b422b14211430b85556e64eb68a26 /spec/frontend/admin | |
parent | 4a721269429a178957e8ce7c6d0a75d3307c9830 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/admin')
-rw-r--r-- | spec/frontend/admin/users/components/user_actions_spec.js | 45 | ||||
-rw-r--r-- | spec/frontend/admin/users/index_spec.js | 36 | ||||
-rw-r--r-- | spec/frontend/admin/users/mock_data.js | 2 |
3 files changed, 77 insertions, 6 deletions
diff --git a/spec/frontend/admin/users/components/user_actions_spec.js b/spec/frontend/admin/users/components/user_actions_spec.js index 50471551268..43313424553 100644 --- a/spec/frontend/admin/users/components/user_actions_spec.js +++ b/spec/frontend/admin/users/components/user_actions_spec.js @@ -1,4 +1,5 @@ import { GlDropdownDivider } from '@gitlab/ui'; +import { createMockDirective, getBinding } from 'helpers/vue_mock_directive'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import Actions from '~/admin/users/components/actions'; import AdminUserActions from '~/admin/users/components/user_actions.vue'; @@ -20,7 +21,7 @@ describe('AdminUserActions component', () => { findUserActions(id).find('[data-testid="dropdown-toggle"]'); const findDropdownDivider = () => wrapper.findComponent(GlDropdownDivider); - const initComponent = ({ actions = [] } = {}) => { + const initComponent = ({ actions = [], showButtonLabels } = {}) => { wrapper = shallowMountExtended(AdminUserActions, { propsData: { user: { @@ -28,6 +29,10 @@ describe('AdminUserActions component', () => { actions, }, paths, + showButtonLabels, + }, + directives: { + GlTooltip: createMockDirective(), }, }); }; @@ -144,4 +149,42 @@ describe('AdminUserActions component', () => { }); }); }); + + describe('when `showButtonLabels` prop is `false`', () => { + beforeEach(() => { + initComponent({ actions: [EDIT, ...CONFIRMATION_ACTIONS] }); + }); + + it('does not render "Edit" button label', () => { + const tooltip = getBinding(findEditButton().element, 'gl-tooltip'); + + expect(findEditButton().text()).toBe(''); + expect(findEditButton().attributes('aria-label')).toBe(I18N_USER_ACTIONS.edit); + expect(tooltip).toBeDefined(); + expect(tooltip.value).toBe(I18N_USER_ACTIONS.edit); + }); + + it('does not render "User administration" dropdown button label', () => { + expect(findActionsDropdown().props('text')).toBe(I18N_USER_ACTIONS.userAdministration); + expect(findActionsDropdown().props('textSrOnly')).toBe(true); + }); + }); + + describe('when `showButtonLabels` prop is `true`', () => { + beforeEach(() => { + initComponent({ actions: [EDIT, ...CONFIRMATION_ACTIONS], showButtonLabels: true }); + }); + + it('renders "Edit" button label', () => { + const tooltip = getBinding(findEditButton().element, 'gl-tooltip'); + + expect(findEditButton().text()).toBe(I18N_USER_ACTIONS.edit); + expect(tooltip).not.toBeDefined(); + }); + + it('renders "User administration" dropdown button label', () => { + expect(findActionsDropdown().props('text')).toBe(I18N_USER_ACTIONS.userAdministration); + expect(findActionsDropdown().props('textSrOnly')).toBe(false); + }); + }); }); diff --git a/spec/frontend/admin/users/index_spec.js b/spec/frontend/admin/users/index_spec.js index 20b60bd8640..06dbadd6d3d 100644 --- a/spec/frontend/admin/users/index_spec.js +++ b/spec/frontend/admin/users/index_spec.js @@ -1,7 +1,8 @@ import { createWrapper } from '@vue/test-utils'; -import { initAdminUsersApp } from '~/admin/users'; +import { initAdminUsersApp, initAdminUserActions } from '~/admin/users'; import AdminUsersApp from '~/admin/users/components/app.vue'; -import { users, paths } from './mock_data'; +import UserActions from '~/admin/users/components/user_actions.vue'; +import { users, user, paths } from './mock_data'; describe('initAdminUsersApp', () => { let wrapper; @@ -14,15 +15,12 @@ describe('initAdminUsersApp', () => { el.setAttribute('data-users', JSON.stringify(users)); el.setAttribute('data-paths', JSON.stringify(paths)); - document.body.appendChild(el); - wrapper = createWrapper(initAdminUsersApp(el)); }); afterEach(() => { wrapper.destroy(); wrapper = null; - el.remove(); el = null; }); @@ -33,3 +31,31 @@ describe('initAdminUsersApp', () => { }); }); }); + +describe('initAdminUserActions', () => { + let wrapper; + let el; + + const findUserActions = () => wrapper.find(UserActions); + + beforeEach(() => { + el = document.createElement('div'); + el.setAttribute('data-user', JSON.stringify(user)); + el.setAttribute('data-paths', JSON.stringify(paths)); + + wrapper = createWrapper(initAdminUserActions(el)); + }); + + afterEach(() => { + wrapper.destroy(); + wrapper = null; + el = null; + }); + + it('parses and passes props', () => { + expect(findUserActions().props()).toMatchObject({ + user, + paths, + }); + }); +}); diff --git a/spec/frontend/admin/users/mock_data.js b/spec/frontend/admin/users/mock_data.js index e7cb4088bf1..ded3e6f7edf 100644 --- a/spec/frontend/admin/users/mock_data.js +++ b/spec/frontend/admin/users/mock_data.js @@ -18,6 +18,8 @@ export const users = [ }, ]; +export const user = users[0]; + export const paths = { edit: '/admin/users/id/edit', approve: '/admin/users/id/approve', |