Commit 7f7de4eb authored by Vitaly Slobodin's avatar Vitaly Slobodin

Migrate ee/group_member_contributions to Jest

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/194287
parent d0ce09be
...@@ -43,7 +43,7 @@ export default { ...@@ -43,7 +43,7 @@ export default {
<gl-loading-icon <gl-loading-icon
v-if="isLoading" v-if="isLoading"
:label="__('Loading contribution stats for group members')" :label="__('Loading contribution stats for group members')"
:size="2" size="md"
class="loading-animation prepend-top-20 append-bottom-20" class="loading-animation prepend-top-20 append-bottom-20"
/> />
<table v-else class="table gl-sortable"> <table v-else class="table gl-sortable">
......
import Vue from 'vue'; import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import mountComponent from 'helpers/vue_mount_component_helper';
import AppComponent from 'ee/group_member_contributions/components/app.vue'; import AppComponent from 'ee/group_member_contributions/components/app.vue';
import GroupMemberStore from 'ee/group_member_contributions/store/group_member_store'; import GroupMemberStore from 'ee/group_member_contributions/store/group_member_store';
...@@ -30,7 +30,7 @@ describe('AppComponent', () => { ...@@ -30,7 +30,7 @@ describe('AppComponent', () => {
describe('methods', () => { describe('methods', () => {
describe('handleColumnClick', () => { describe('handleColumnClick', () => {
it('calls store.sortMembers with columnName param', () => { it('calls store.sortMembers with columnName param', () => {
spyOn(vm.store, 'sortMembers'); jest.spyOn(vm.store, 'sortMembers').mockImplementation(() => {});
const columnName = 'fullname'; const columnName = 'fullname';
vm.handleColumnClick(columnName); vm.handleColumnClick(columnName);
...@@ -49,29 +49,25 @@ describe('AppComponent', () => { ...@@ -49,29 +49,25 @@ describe('AppComponent', () => {
expect(vm.$el.querySelector('h3').innerText.trim()).toBe('Contributions per group member'); expect(vm.$el.querySelector('h3').innerText.trim()).toBe('Contributions per group member');
}); });
it('shows loading icon when isLoading prop is true', done => { it('shows loading icon when isLoading prop is true', () => {
vm.store.state.isLoading = true; vm.store.state.isLoading = true;
vm.$nextTick()
.then(() => { return vm.$nextTick().then(() => {
const loadingEl = vm.$el.querySelector('.loading-animation'); const loadingEl = vm.$el.querySelector('.loading-animation');
expect(loadingEl).not.toBeNull(); expect(loadingEl).not.toBeNull();
expect(loadingEl.querySelector('span').getAttribute('aria-label')).toBe( expect(loadingEl.querySelector('span').getAttribute('aria-label')).toBe(
'Loading contribution stats for group members', 'Loading contribution stats for group members',
); );
}) });
.then(done)
.catch(done.fail);
}); });
it('renders table container element', done => { it('renders table container element', () => {
vm.store.state.isLoading = false; vm.store.state.isLoading = false;
vm.$nextTick()
.then(() => { return vm.$nextTick().then(() => {
expect(vm.$el.querySelector('table.table.gl-sortable')).not.toBeNull(); expect(vm.$el.querySelector('table.table.gl-sortable')).not.toBeNull();
}) });
.then(done)
.catch(done.fail);
}); });
}); });
}); });
import Vue from 'vue'; import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import mountComponent from 'helpers/vue_mount_component_helper';
import TableBodyComponent from 'ee/group_member_contributions/components/table_body.vue'; import TableBodyComponent from 'ee/group_member_contributions/components/table_body.vue';
import GroupMemberStore from 'ee/group_member_contributions/store/group_member_store'; import GroupMemberStore from 'ee/group_member_contributions/store/group_member_store';
......
import Vue from 'vue'; import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import mountComponent from 'helpers/vue_mount_component_helper';
import TableHeaderComponent from 'ee/group_member_contributions/components/table_header.vue'; import TableHeaderComponent from 'ee/group_member_contributions/components/table_header.vue';
import defaultColumns from 'ee/group_member_contributions/constants'; import defaultColumns from 'ee/group_member_contributions/constants';
...@@ -66,14 +66,14 @@ describe('TableHeaderComponent', () => { ...@@ -66,14 +66,14 @@ describe('TableHeaderComponent', () => {
describe('onColumnClick', () => { describe('onColumnClick', () => {
it('emits `onColumnClick` event with columnName param on component instance', () => { it('emits `onColumnClick` event with columnName param on component instance', () => {
spyOn(vm, '$emit'); jest.spyOn(vm, '$emit').mockImplementation(() => {});
vm.onColumnClick(columnName); vm.onColumnClick(columnName);
expect(vm.$emit).toHaveBeenCalledWith('onColumnClick', columnName); expect(vm.$emit).toHaveBeenCalledWith('onColumnClick', columnName);
}); });
it('updates columnIconMeta prop for provided columnName', () => { it('updates columnIconMeta prop for provided columnName', () => {
spyOn(vm, 'getColumnIconMeta'); jest.spyOn(vm, 'getColumnIconMeta');
vm.onColumnClick(columnName); vm.onColumnClick(columnName);
expect(vm.getColumnIconMeta).toHaveBeenCalledWith(columnName, vm.sortOrders); expect(vm.getColumnIconMeta).toHaveBeenCalledWith(columnName, vm.sortOrders);
......
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import createFlash from '~/flash';
import GroupMemberStore from 'ee/group_member_contributions/store/group_member_store'; import GroupMemberStore from 'ee/group_member_contributions/store/group_member_store';
import defaultColumns from 'ee/group_member_contributions/constants'; import defaultColumns from 'ee/group_member_contributions/constants';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { rawMembers, contributionsPath } from '../mock_data'; import { rawMembers, contributionsPath } from '../mock_data';
jest.mock('~/flash');
describe('GroupMemberStore', () => { describe('GroupMemberStore', () => {
let store; let store;
...@@ -13,6 +15,10 @@ describe('GroupMemberStore', () => { ...@@ -13,6 +15,10 @@ describe('GroupMemberStore', () => {
store = new GroupMemberStore(contributionsPath); store = new GroupMemberStore(contributionsPath);
}); });
afterEach(() => {
createFlash.mockClear();
});
describe('setColumns', () => { describe('setColumns', () => {
beforeEach(() => { beforeEach(() => {
store.setColumns(defaultColumns); store.setColumns(defaultColumns);
...@@ -58,7 +64,6 @@ describe('GroupMemberStore', () => { ...@@ -58,7 +64,6 @@ describe('GroupMemberStore', () => {
beforeEach(() => { beforeEach(() => {
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
setFixtures('<div class="flash-container"></div>');
}); });
afterEach(() => { afterEach(() => {
...@@ -67,8 +72,8 @@ describe('GroupMemberStore', () => { ...@@ -67,8 +72,8 @@ describe('GroupMemberStore', () => {
it('calls service.getContributedMembers and sets response to the store on success', done => { it('calls service.getContributedMembers and sets response to the store on success', done => {
mock.onGet(contributionsPath).reply(200, rawMembers); mock.onGet(contributionsPath).reply(200, rawMembers);
spyOn(store, 'setColumns'); jest.spyOn(store, 'setColumns').mockImplementation(() => {});
spyOn(store, 'setMembers'); jest.spyOn(store, 'setMembers').mockImplementation(() => {});
store store
.fetchContributedMembers() .fetchContributedMembers()
...@@ -92,7 +97,7 @@ describe('GroupMemberStore', () => { ...@@ -92,7 +97,7 @@ describe('GroupMemberStore', () => {
.catch(e => { .catch(e => {
expect(e.message).toBe('Request failed with status code 500'); expect(e.message).toBe('Request failed with status code 500');
expect(store.isLoading).toBe(false); expect(store.isLoading).toBe(false);
expect(document.querySelector('.flash-text').innerText.trim()).toBe( expect(createFlash).toHaveBeenCalledWith(
'Something went wrong while fetching group member contributions', 'Something went wrong while fetching group member contributions',
); );
}) })
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment