Commit fbfc2404 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch '334888-use-usage-graph-in-project-storage' into 'master'

Replace projects storage placeholder with usage-graph

See merge request gitlab-org/gitlab!68866
parents b5744cd1 6651bc38
<script> <script>
import { GlAlert } from '@gitlab/ui'; import { GlAlert } from '@gitlab/ui';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import UsageGraph from '~/vue_shared/components/storage_counter/usage_graph.vue';
import getProjectStorageCount from '../queries/project_storage.query.graphql'; import getProjectStorageCount from '../queries/project_storage.query.graphql';
import { parseGetProjectStorageResults } from '../utils'; import { parseGetProjectStorageResults } from '../utils';
...@@ -8,6 +9,7 @@ export default { ...@@ -8,6 +9,7 @@ export default {
name: 'StorageCounterApp', name: 'StorageCounterApp',
components: { components: {
GlAlert, GlAlert,
UsageGraph,
}, },
inject: ['projectPath'], inject: ['projectPath'],
apollo: { apollo: {
...@@ -43,8 +45,13 @@ export default { ...@@ -43,8 +45,13 @@ export default {
}; };
</script> </script>
<template> <template>
<gl-alert v-if="error" variant="danger" @dismiss="clearError"> <div>
{{ error }} <gl-alert v-if="error" variant="danger" @dismiss="clearError">
</gl-alert> {{ error }}
<div v-else>{{ $options.i18n.placeholder }}</div> </gl-alert>
<div v-else>{{ $options.i18n.placeholder }}</div>
<div v-if="project.statistics" class="gl-w-full">
<usage-graph :root-storage-statistics="project.statistics" :limit="0" />
</div>
</div>
</template> </template>
...@@ -60,5 +60,6 @@ export const parseGetProjectStorageResults = (data) => { ...@@ -60,5 +60,6 @@ export const parseGetProjectStorageResults = (data) => {
totalUsage: numberToHumanSize(storageSize), totalUsage: numberToHumanSize(storageSize),
storageTypes, storageTypes,
}, },
statistics: projectStatistics,
}; };
}; };
...@@ -4,18 +4,18 @@ import VueApollo from 'vue-apollo'; ...@@ -4,18 +4,18 @@ import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
import StorageCounterApp from '~/projects/storage_counter/components/app.vue'; import StorageCounterApp from '~/projects/storage_counter/components/app.vue';
import getProjectStorageCount from '~/projects/storage_counter/queries/project_storage.query.graphql'; import getProjectStorageCount from '~/projects/storage_counter/queries/project_storage.query.graphql';
import UsageGraph from '~/vue_shared/components/storage_counter/usage_graph.vue';
import { projectStorageCountResponse } from './mock_data';
const localVue = createLocalVue(); const localVue = createLocalVue();
describe('Storage counter app', () => { describe('Storage counter app', () => {
let wrapper; let wrapper;
const createMockApolloProvider = () => { const createMockApolloProvider = ({ mutationMock }) => {
localVue.use(VueApollo); localVue.use(VueApollo);
const requestHandlers = [ const requestHandlers = [[getProjectStorageCount, mutationMock]];
[getProjectStorageCount, jest.fn().mockRejectedValue(new Error('GraphQL error'))],
];
return createMockApollo(requestHandlers); return createMockApollo(requestHandlers);
}; };
...@@ -36,6 +36,7 @@ describe('Storage counter app', () => { ...@@ -36,6 +36,7 @@ describe('Storage counter app', () => {
}; };
const findAlert = () => wrapper.findComponent(GlAlert); const findAlert = () => wrapper.findComponent(GlAlert);
const findUsageGraph = () => wrapper.findComponent(UsageGraph);
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
...@@ -50,10 +51,10 @@ describe('Storage counter app', () => { ...@@ -50,10 +51,10 @@ describe('Storage counter app', () => {
}); });
describe('handling apollo fetching error', () => { describe('handling apollo fetching error', () => {
let mockApollo; const mutationMock = jest.fn().mockRejectedValue(new Error('GraphQL error'));
beforeEach(() => { beforeEach(() => {
mockApollo = createMockApolloProvider(); const mockApollo = createMockApolloProvider({ mutationMock });
createComponent({ mockApollo }); createComponent({ mockApollo });
}); });
...@@ -61,4 +62,22 @@ describe('Storage counter app', () => { ...@@ -61,4 +62,22 @@ describe('Storage counter app', () => {
expect(findAlert().exists()).toBe(true); expect(findAlert().exists()).toBe(true);
}); });
}); });
describe('rendering <usage-graph />', () => {
const mutationMock = jest.fn().mockResolvedValue(projectStorageCountResponse);
beforeEach(() => {
const mockApollo = createMockApolloProvider({ mutationMock });
createComponent({ mockApollo });
});
it('renders usage-graph component if project.statistics exists', () => {
expect(findUsageGraph().exists()).toBe(true);
});
it('passes project.statistics to usage-graph component', () => {
const { __typename, ...statistics } = projectStorageCountResponse.data.project.statistics;
expect(findUsageGraph().props('rootStorageStatistics')).toMatchObject(statistics);
});
});
}); });
export const projectStorageCountResponse = {
data: {
project: {
id: 'gid://gitlab/Project/20',
statistics: {
buildArtifactsSize: 400000,
lfsObjectsSize: 4800000,
packagesSize: 3800000,
repositorySize: 39000000,
snippetsSize: 0,
storageSize: 39930000,
uploadsSize: 0,
wikiSize: 300000,
__typename: 'ProjectStatistics',
},
__typename: 'Project',
},
},
};
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