2021-01-03 14:25:43 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import MetricCard from '~/analytics/shared/components/metric_card.vue';
|
2021-04-17 20:07:23 +05:30
|
|
|
import UsageCounts from '~/analytics/usage_trends/components/usage_counts.vue';
|
|
|
|
import { mockUsageCounts } from '../mock_data';
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe('UsageCounts', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const createComponent = ({ loading = false, data = {} } = {}) => {
|
|
|
|
const $apollo = {
|
|
|
|
queries: {
|
|
|
|
counts: {
|
|
|
|
loading,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
wrapper = shallowMount(UsageCounts, {
|
2021-01-03 14:25:43 +05:30
|
|
|
mocks: { $apollo },
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
...data,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
const findMetricCard = () => wrapper.find(MetricCard);
|
|
|
|
|
|
|
|
describe('while loading', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ loading: true });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the metric card with isLoading=true', () => {
|
|
|
|
expect(findMetricCard().props('isLoading')).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with data', () => {
|
|
|
|
beforeEach(() => {
|
2021-04-17 20:07:23 +05:30
|
|
|
createComponent({ data: { counts: mockUsageCounts } });
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('passes the counts data to the metric card', () => {
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(findMetricCard().props('metrics')).toEqual(mockUsageCounts);
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|