diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-10 00:09:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-10 00:09:43 +0300 |
commit | 03d56c8af04d2982aff573b78f08192b07107c5b (patch) | |
tree | 6c9d2a9ffe63565d074a41397f06be0d22f9a8f4 /spec/frontend/admin | |
parent | 9b09561f47159655d05171b4bee980c669859864 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/admin')
-rw-r--r-- | spec/frontend/admin/users/components/app_spec.js | 37 | ||||
-rw-r--r-- | spec/frontend/admin/users/components/users_table_spec.js | 61 | ||||
-rw-r--r-- | spec/frontend/admin/users/mock_data.js | 2 |
3 files changed, 99 insertions, 1 deletions
diff --git a/spec/frontend/admin/users/components/app_spec.js b/spec/frontend/admin/users/components/app_spec.js new file mode 100644 index 00000000000..65b13e3a40d --- /dev/null +++ b/spec/frontend/admin/users/components/app_spec.js @@ -0,0 +1,37 @@ +import { shallowMount } from '@vue/test-utils'; + +import AdminUsersApp from '~/admin/users/components/app.vue'; +import AdminUsersTable from '~/admin/users/components/users_table.vue'; +import { users, paths } from '../mock_data'; + +describe('AdminUsersApp component', () => { + let wrapper; + + const initComponent = (props = {}) => { + wrapper = shallowMount(AdminUsersApp, { + propsData: { + users, + paths, + ...props, + }, + }); + }; + + afterEach(() => { + wrapper.destroy(); + wrapper = null; + }); + + describe('when initialized', () => { + beforeEach(() => { + initComponent(); + }); + + it('renders the admin users table with props', () => { + expect(wrapper.find(AdminUsersTable).props()).toEqual({ + users, + paths, + }); + }); + }); +}); diff --git a/spec/frontend/admin/users/components/users_table_spec.js b/spec/frontend/admin/users/components/users_table_spec.js new file mode 100644 index 00000000000..ba36e1e32ef --- /dev/null +++ b/spec/frontend/admin/users/components/users_table_spec.js @@ -0,0 +1,61 @@ +import { GlTable } from '@gitlab/ui'; +import { mount } from '@vue/test-utils'; + +import AdminUsersTable from '~/admin/users/components/users_table.vue'; +import { users, paths } from '../mock_data'; + +describe('AdminUsersTable component', () => { + let wrapper; + + const getCellByLabel = (trIdx, label) => { + return wrapper + .find(GlTable) + .find('tbody') + .findAll('tr') + .at(trIdx) + .find(`[data-label="${label}"][role="cell"]`); + }; + + const initComponent = (props = {}) => { + wrapper = mount(AdminUsersTable, { + propsData: { + users, + paths, + ...props, + }, + }); + }; + + afterEach(() => { + wrapper.destroy(); + wrapper = null; + }); + + describe('when there are users', () => { + const user = users[0]; + + beforeEach(() => { + initComponent(); + }); + + it.each` + key | label + ${'name'} | ${'Name'} + ${'projectsCount'} | ${'Projects'} + ${'createdAt'} | ${'Created on'} + ${'lastActivityOn'} | ${'Last activity'} + `('renders users.$key for $label', ({ key, label }) => { + expect(getCellByLabel(0, label).text()).toBe(`${user[key]}`); + }); + }); + + describe('when users is an empty array', () => { + beforeEach(() => { + initComponent({ users: [] }); + }); + + it('renders a "No users found" message', () => { + expect(wrapper.text()).toContain('No users found'); + }); + }); +}); diff --git a/spec/frontend/admin/users/mock_data.js b/spec/frontend/admin/users/mock_data.js index b80d04454b0..62fa9469638 100644 --- a/spec/frontend/admin/users/mock_data.js +++ b/spec/frontend/admin/users/mock_data.js @@ -5,7 +5,7 @@ export const users = [ createdAt: '2020-11-13T12:26:54.177Z', email: 'nikki@example.com', username: 'nikki', - lastActivityOn: null, + lastActivityOn: '2020-12-09', avatarUrl: 'https://secure.gravatar.com/avatar/054f062d8b1a42b123f17e13a173cda8?s=80\\u0026d=identicon', badges: [], |