diff options
Diffstat (limited to 'spec/frontend/admin')
5 files changed, 80 insertions, 9 deletions
diff --git a/spec/frontend/admin/statistics_panel/components/app_spec.js b/spec/frontend/admin/statistics_panel/components/app_spec.js index dda0c2b857c..a4dcfa1a480 100644 --- a/spec/frontend/admin/statistics_panel/components/app_spec.js +++ b/spec/frontend/admin/statistics_panel/components/app_spec.js @@ -34,7 +34,7 @@ describe('Admin statistics app', () => { wrapper.destroy(); }); - const findStats = idx => wrapper.findAll('.js-stats').at(idx); + const findStats = (idx) => wrapper.findAll('.js-stats').at(idx); describe('template', () => { describe('when app is loading', () => { diff --git a/spec/frontend/admin/statistics_panel/store/actions_spec.js b/spec/frontend/admin/statistics_panel/store/actions_spec.js index 9b18b1aebda..ecbc823be12 100644 --- a/spec/frontend/admin/statistics_panel/store/actions_spec.js +++ b/spec/frontend/admin/statistics_panel/store/actions_spec.js @@ -22,7 +22,7 @@ describe('Admin statistics panel actions', () => { mock.onGet(/api\/(.*)\/application\/statistics/).replyOnce(200, mockStatistics); }); - it('dispatches success with received data', done => + it('dispatches success with received data', (done) => testAction( actions.fetchStatistics, null, @@ -46,7 +46,7 @@ describe('Admin statistics panel actions', () => { mock.onGet(/api\/(.*)\/application\/statistics/).replyOnce(500); }); - it('dispatches error', done => + it('dispatches error', (done) => testAction( actions.fetchStatistics, null, @@ -67,7 +67,7 @@ describe('Admin statistics panel actions', () => { }); describe('requestStatistic', () => { - it('should commit the request mutation', done => + it('should commit the request mutation', (done) => testAction( actions.requestStatistics, null, @@ -79,7 +79,7 @@ describe('Admin statistics panel actions', () => { }); describe('receiveStatisticsSuccess', () => { - it('should commit received data', done => + it('should commit received data', (done) => testAction( actions.receiveStatisticsSuccess, mockStatistics, @@ -96,7 +96,7 @@ describe('Admin statistics panel actions', () => { }); describe('receiveStatisticsError', () => { - it('should commit error', done => { + it('should commit error', (done) => { testAction( actions.receiveStatisticsError, 500, diff --git a/spec/frontend/admin/users/components/user_avatar_spec.js b/spec/frontend/admin/users/components/user_avatar_spec.js new file mode 100644 index 00000000000..ba4e83690d0 --- /dev/null +++ b/spec/frontend/admin/users/components/user_avatar_spec.js @@ -0,0 +1,63 @@ +import { GlAvatarLink, GlAvatarLabeled, GlBadge } from '@gitlab/ui'; +import { mount } from '@vue/test-utils'; + +import AdminUserAvatar from '~/admin/users/components/user_avatar.vue'; +import { users, paths } from '../mock_data'; + +describe('AdminUserAvatar component', () => { + let wrapper; + const user = users[0]; + const adminUserPath = paths.adminUser; + + const findAvatar = () => wrapper.find(GlAvatarLabeled); + const findAvatarLink = () => wrapper.find(GlAvatarLink); + const findAllBadges = () => wrapper.findAll(GlBadge); + + const initComponent = (props = {}) => { + wrapper = mount(AdminUserAvatar, { + propsData: { + user, + adminUserPath, + ...props, + }, + }); + }; + + afterEach(() => { + wrapper.destroy(); + wrapper = null; + }); + + describe('when initialized', () => { + beforeEach(() => { + initComponent(); + }); + + it("links to the user's admin path", () => { + expect(findAvatarLink().attributes()).toMatchObject({ + href: adminUserPath.replace('id', user.username), + 'data-user-id': user.id.toString(), + 'data-username': user.username, + }); + }); + + it("renders the user's name", () => { + expect(findAvatar().props('label')).toBe(user.name); + }); + + it("renders the user's email", () => { + expect(findAvatar().props('subLabel')).toBe(user.email); + }); + + it("renders the user's avatar image", () => { + expect(findAvatar().attributes('src')).toBe(user.avatarUrl); + }); + + it("renders the user's badges", () => { + findAllBadges().wrappers.forEach((badge, idx) => { + expect(badge.text()).toBe(user.badges[idx].text); + expect(badge.props('variant')).toBe(user.badges[idx].variant); + }); + }); + }); +}); diff --git a/spec/frontend/admin/users/components/users_table_spec.js b/spec/frontend/admin/users/components/users_table_spec.js index ba36e1e32ef..b79d2d4d39d 100644 --- a/spec/frontend/admin/users/components/users_table_spec.js +++ b/spec/frontend/admin/users/components/users_table_spec.js @@ -2,6 +2,7 @@ import { GlTable } from '@gitlab/ui'; import { mount } from '@vue/test-utils'; import AdminUsersTable from '~/admin/users/components/users_table.vue'; +import AdminUserAvatar from '~/admin/users/components/user_avatar.vue'; import { users, paths } from '../mock_data'; describe('AdminUsersTable component', () => { @@ -44,8 +45,12 @@ describe('AdminUsersTable component', () => { ${'projectsCount'} | ${'Projects'} ${'createdAt'} | ${'Created on'} ${'lastActivityOn'} | ${'Last activity'} - `('renders users.$key for $label', ({ key, label }) => { - expect(getCellByLabel(0, label).text()).toBe(`${user[key]}`); + `('renders users.$key in column $label', ({ key, label }) => { + expect(getCellByLabel(0, label).text()).toContain(`${user[key]}`); + }); + + it('renders an AdminUserAvatar component', () => { + expect(getCellByLabel(0, 'Name').find(AdminUserAvatar).exists()).toBe(true); }); }); diff --git a/spec/frontend/admin/users/mock_data.js b/spec/frontend/admin/users/mock_data.js index 62fa9469638..860994a9152 100644 --- a/spec/frontend/admin/users/mock_data.js +++ b/spec/frontend/admin/users/mock_data.js @@ -8,7 +8,10 @@ export const users = [ lastActivityOn: '2020-12-09', avatarUrl: 'https://secure.gravatar.com/avatar/054f062d8b1a42b123f17e13a173cda8?s=80\\u0026d=identicon', - badges: [], + badges: [ + { text: 'Admin', variant: 'success' }, + { text: "It's you!", variant: null }, + ], projectsCount: 0, actions: [], }, |