debian-mirror-gitlab/spec/frontend/admin/statistics_panel/components/app_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2022-01-26 12:08:38 +05:30
import { shallowMount } from '@vue/test-utils';
2019-12-04 20:38:33 +05:30
import AxiosMockAdapter from 'axios-mock-adapter';
2022-01-26 12:08:38 +05:30
import Vue from 'vue';
2021-03-11 19:13:27 +05:30
import Vuex from 'vuex';
2019-12-04 20:38:33 +05:30
import StatisticsPanelApp from '~/admin/statistics_panel/components/app.vue';
import statisticsLabels from '~/admin/statistics_panel/constants';
import createStore from '~/admin/statistics_panel/store';
2021-03-11 19:13:27 +05:30
import axios from '~/lib/utils/axios_utils';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
2023-04-23 21:23:45 +05:30
import { HTTP_STATUS_OK } from '~/lib/utils/http_status';
2019-12-04 20:38:33 +05:30
import mockStatistics from '../mock_data';
2022-01-26 12:08:38 +05:30
Vue.use(Vuex);
2019-12-04 20:38:33 +05:30
describe('Admin statistics app', () => {
let wrapper;
let store;
let axiosMock;
const createComponent = () => {
wrapper = shallowMount(StatisticsPanelApp, {
store,
});
};
beforeEach(() => {
axiosMock = new AxiosMockAdapter(axios);
2023-04-23 21:23:45 +05:30
axiosMock.onGet(/api\/(.*)\/application\/statistics/).reply(HTTP_STATUS_OK);
2019-12-04 20:38:33 +05:30
store = createStore();
});
2021-03-08 18:12:59 +05:30
const findStats = (idx) => wrapper.findAll('.js-stats').at(idx);
2019-12-04 20:38:33 +05:30
describe('template', () => {
describe('when app is loading', () => {
it('renders a loading indicator', () => {
store.dispatch('requestStatistics');
createComponent();
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(true);
2019-12-04 20:38:33 +05:30
});
});
describe('when app has finished loading', () => {
const statistics = convertObjectPropsToCamelCase(mockStatistics, { deep: true });
it.each`
statistic | count | index
${'forks'} | ${12} | ${0}
${'issues'} | ${180} | ${1}
${'mergeRequests'} | ${31} | ${2}
${'notes'} | ${986} | ${3}
${'snippets'} | ${50} | ${4}
${'sshKeys'} | ${10} | ${5}
${'milestones'} | ${40} | ${6}
${'activeUsers'} | ${50} | ${7}
`('renders the count for the $statistic statistic', ({ statistic, count, index }) => {
const label = statisticsLabels[statistic];
store.dispatch('receiveStatisticsSuccess', statistics);
createComponent();
expect(findStats(index).text()).toContain(label);
2022-08-13 15:12:31 +05:30
expect(findStats(index).text()).toContain(count.toString());
2019-12-04 20:38:33 +05:30
});
});
});
});