Commit d510f5fc authored by Martin Wortschack's avatar Martin Wortschack Committed by Brandon Labuschagne

Replace metric card with GlSingleStat on admin usage trends

parent 1773fffa
<script> <script>
import MetricCard from '~/analytics/shared/components/metric_card.vue'; import { GlDeprecatedSkeletonLoading as GlSkeletonLoading } from '@gitlab/ui';
import { GlSingleStat } from '@gitlab/ui/dist/charts';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { number } from '~/lib/utils/unit_format'; import { number } from '~/lib/utils/unit_format';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
...@@ -10,7 +11,8 @@ const defaultPrecision = 0; ...@@ -10,7 +11,8 @@ const defaultPrecision = 0;
export default { export default {
name: 'UsageCounts', name: 'UsageCounts',
components: { components: {
MetricCard, GlSkeletonLoading,
GlSingleStat,
}, },
data() { data() {
return { return {
...@@ -56,10 +58,24 @@ export default { ...@@ -56,10 +58,24 @@ export default {
</script> </script>
<template> <template>
<metric-card <div>
:title="__('Usage Trends')" <h2>
:metrics="counts" {{ __('Usage Trends') }}
:is-loading="$apollo.queries.counts.loading" </h2>
class="gl-mt-4" <div
/> class="gl-display-flex gl-flex-direction-column gl-md-flex-direction-row gl-my-6 gl-align-items-flex-start"
>
<gl-skeleton-loading v-if="$apollo.queries.counts.loading" />
<template v-else>
<gl-single-stat
v-for="count in counts"
:key="count.key"
class="gl-pr-9 gl-my-4 gl-md-mt-0 gl-md-mb-0"
:value="`${count.value}`"
:title="count.label"
:should-animate="true"
/>
</template>
</div>
</div>
</template> </template>
import { GlDeprecatedSkeletonLoading as GlSkeletonLoading } from '@gitlab/ui';
import { GlSingleStat } from '@gitlab/ui/dist/charts';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import MetricCard from '~/analytics/shared/components/metric_card.vue';
import UsageCounts from '~/analytics/usage_trends/components/usage_counts.vue'; import UsageCounts from '~/analytics/usage_trends/components/usage_counts.vue';
import { mockUsageCounts } from '../mock_data'; import { mockUsageCounts } from '../mock_data';
...@@ -27,18 +28,18 @@ describe('UsageCounts', () => { ...@@ -27,18 +28,18 @@ describe('UsageCounts', () => {
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
}); });
const findMetricCard = () => wrapper.find(MetricCard); const findSkeletonLoader = () => wrapper.findComponent(GlSkeletonLoading);
const findAllSingleStats = () => wrapper.findAllComponents(GlSingleStat);
describe('while loading', () => { describe('while loading', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ loading: true }); createComponent({ loading: true });
}); });
it('displays the metric card with isLoading=true', () => { it('displays a loading indicator', () => {
expect(findMetricCard().props('isLoading')).toBe(true); expect(findSkeletonLoader().exists()).toBe(true);
}); });
}); });
...@@ -47,8 +48,15 @@ describe('UsageCounts', () => { ...@@ -47,8 +48,15 @@ describe('UsageCounts', () => {
createComponent({ data: { counts: mockUsageCounts } }); createComponent({ data: { counts: mockUsageCounts } });
}); });
it('passes the counts data to the metric card', () => { it.each`
expect(findMetricCard().props('metrics')).toEqual(mockUsageCounts); index | value | title
${0} | ${mockUsageCounts[0].value} | ${mockUsageCounts[0].label}
${1} | ${mockUsageCounts[1].value} | ${mockUsageCounts[1].label}
`('renders a GlSingleStat for "$title"', ({ index, value, title }) => {
const singleStat = findAllSingleStats().at(index);
expect(singleStat.props('value')).toBe(`${value}`);
expect(singleStat.props('title')).toBe(title);
}); });
}); });
}); });
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