2018-05-09 12:01:36 +05:30
|
|
|
import Vue from 'vue';
|
2020-04-08 14:13:33 +05:30
|
|
|
import { mountComponentWithStore } from 'helpers/vue_mount_component_helper';
|
2018-05-09 12:01:36 +05:30
|
|
|
import { GROUP_BADGE, PROJECT_BADGE } from '~/badges/constants';
|
|
|
|
import store from '~/badges/store';
|
|
|
|
import BadgeList from '~/badges/components/badge_list.vue';
|
|
|
|
import { createDummyBadge } from '../dummy_badge';
|
|
|
|
|
|
|
|
describe('BadgeList component', () => {
|
|
|
|
const Component = Vue.extend(BadgeList);
|
|
|
|
const numberOfDummyBadges = 3;
|
|
|
|
let vm;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
setFixtures('<div id="dummy-element"></div>');
|
|
|
|
const badges = [];
|
|
|
|
for (let id = 0; id < numberOfDummyBadges; id += 1) {
|
|
|
|
badges.push({ id, ...createDummyBadge() });
|
|
|
|
}
|
|
|
|
store.replaceState({
|
|
|
|
...store.state,
|
|
|
|
badges,
|
|
|
|
kind: PROJECT_BADGE,
|
|
|
|
isLoading: false,
|
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
// Can be removed once GlLoadingIcon no longer throws a warning
|
|
|
|
jest.spyOn(global.console, 'warn').mockImplementation(() => jest.fn());
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
vm = mountComponentWithStore(Component, {
|
|
|
|
el: '#dummy-element',
|
|
|
|
store,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a header with the badge count', () => {
|
2018-11-08 19:23:39 +05:30
|
|
|
const header = vm.$el.querySelector('.card-header');
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
expect(header).toHaveText(new RegExp(`Your badges\\s+${numberOfDummyBadges}`));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a row for each badge', () => {
|
|
|
|
const rows = vm.$el.querySelectorAll('.gl-responsive-table-row');
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
expect(rows).toHaveLength(numberOfDummyBadges);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a message if no badges exist', done => {
|
|
|
|
store.state.badges = [];
|
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(vm.$el.innerText).toMatch('This project has no badges');
|
2018-05-09 12:01:36 +05:30
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows a loading icon when loading', done => {
|
|
|
|
store.state.isLoading = true;
|
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
2019-10-12 21:52:04 +05:30
|
|
|
const loadingIcon = vm.$el.querySelector('.gl-spinner');
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
expect(loadingIcon).toBeVisible();
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('for group badges', () => {
|
|
|
|
beforeEach(done => {
|
|
|
|
store.state.kind = GROUP_BADGE;
|
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a message if no badges exist', done => {
|
|
|
|
store.state.badges = [];
|
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(vm.$el.innerText).toMatch('This group has no badges');
|
2018-05-09 12:01:36 +05:30
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|