Commit ed5794dd authored by Ragnar Hardarson's avatar Ragnar Hardarson Committed by Jose Ivan Vargas

Render purchase box if link to purchase storage is provided

We might want to turn this off if we discover any issues
with CustomersDot
parent b1f75a22
...@@ -110,7 +110,10 @@ export default { ...@@ -110,7 +110,10 @@ export default {
:actual-repository-size-limit="namespace.actualRepositorySizeLimit" :actual-repository-size-limit="namespace.actualRepositorySizeLimit"
/> />
<div v-if="isAdditionalStorageFlagEnabled && storageStatistics"> <div v-if="isAdditionalStorageFlagEnabled && storageStatistics">
<usage-statistics :root-storage-statistics="storageStatistics" /> <usage-statistics
:root-storage-statistics="storageStatistics"
:purchase-storage-url="purchaseStorageUrl"
/>
</div> </div>
<div v-else class="gl-py-4 gl-px-2 gl-m-0"> <div v-else class="gl-py-4 gl-px-2 gl-m-0">
<div class="gl-display-flex gl-align-items-center"> <div class="gl-display-flex gl-align-items-center">
......
...@@ -15,6 +15,11 @@ export default { ...@@ -15,6 +15,11 @@ export default {
required: true, required: true,
type: Object, type: Object,
}, },
purchaseStorageUrl: {
required: false,
type: String,
default: '',
},
}, },
computed: { computed: {
formattedActualRepoSizeLimit() { formattedActualRepoSizeLimit() {
...@@ -43,17 +48,19 @@ export default { ...@@ -43,17 +48,19 @@ export default {
totalRepositorySizeExcess, totalRepositorySizeExcess,
additionalPurchasedStorageSize, additionalPurchasedStorageSize,
} = this.rootStorageStatistics; } = this.rootStorageStatistics;
return { return this.purchaseStorageUrl
usage: this.formatSizeAndSplit( ? {
Math.max(0, additionalPurchasedStorageSize - totalRepositorySizeExcess), usage: this.formatSizeAndSplit(
), Math.max(0, additionalPurchasedStorageSize - totalRepositorySizeExcess),
usageTotal: this.formatSizeAndSplit(additionalPurchasedStorageSize), ),
description: s__('UsageQuota|Purchased storage available'), usageTotal: this.formatSizeAndSplit(additionalPurchasedStorageSize),
link: { description: s__('UsageQuota|Purchased storage available'),
text: s__('UsageQuota|Purchase more storage'), link: {
url: '#', text: s__('UsageQuota|Purchase more storage'),
}, url: this.purchaseStorageUrl,
}; },
}
: null;
}, },
}, },
methods: { methods: {
...@@ -106,6 +113,7 @@ export default { ...@@ -106,6 +113,7 @@ export default {
</template> </template>
</usage-statistics-card> </usage-statistics-card>
<usage-statistics-card <usage-statistics-card
v-if="purchasedUsage"
data-testid="purchasedUsage" data-testid="purchasedUsage"
:usage="purchasedUsage.usage" :usage="purchasedUsage.usage"
:usage-total="purchasedUsage.usageTotal" :usage-total="purchasedUsage.usageTotal"
......
...@@ -7,7 +7,7 @@ import { withRootStorageStatistics } from '../mock_data'; ...@@ -7,7 +7,7 @@ import { withRootStorageStatistics } from '../mock_data';
describe('Usage Statistics component', () => { describe('Usage Statistics component', () => {
let wrapper; let wrapper;
const createComponent = () => { const createComponent = (props = {}) => {
wrapper = shallowMount(UsageStatistics, { wrapper = shallowMount(UsageStatistics, {
propsData: { propsData: {
rootStorageStatistics: { rootStorageStatistics: {
...@@ -16,6 +16,7 @@ describe('Usage Statistics component', () => { ...@@ -16,6 +16,7 @@ describe('Usage Statistics component', () => {
totalRepositorySizeExcess: withRootStorageStatistics.totalRepositorySizeExcess, totalRepositorySizeExcess: withRootStorageStatistics.totalRepositorySizeExcess,
additionalPurchasedStorageSize: withRootStorageStatistics.additionalPurchasedStorageSize, additionalPurchasedStorageSize: withRootStorageStatistics.additionalPurchasedStorageSize,
}, },
...props,
}, },
stubs: { stubs: {
UsageStatisticsCard, UsageStatisticsCard,
...@@ -27,43 +28,58 @@ describe('Usage Statistics component', () => { ...@@ -27,43 +28,58 @@ describe('Usage Statistics component', () => {
const getStatisticsCards = () => wrapper.findAll(UsageStatisticsCard); const getStatisticsCards = () => wrapper.findAll(UsageStatisticsCard);
const getStatisticsCard = testId => wrapper.find(`[data-testid="${testId}"]`); const getStatisticsCard = testId => wrapper.find(`[data-testid="${testId}"]`);
beforeEach(() => { describe('with purchaseStorageUrl passed', () => {
createComponent(); beforeEach(() => {
}); createComponent({
purchaseStorageUrl: 'some-fancy-url',
});
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
it('renders three statistics cards', () => { it('renders three statistics cards', () => {
expect(getStatisticsCards()).toHaveLength(3); expect(getStatisticsCards()).toHaveLength(3);
}); });
it('renders text in total usage card footer', () => { it('renders text in total usage card footer', () => {
expect( expect(
getStatisticsCard('totalUsage') getStatisticsCard('totalUsage')
.find('[data-testid="statisticsCardFooter"]') .find('[data-testid="statisticsCardFooter"]')
.text(), .text(),
).toMatchInterpolatedText( ).toMatchInterpolatedText(
'This is the total amount of storage used across your projects within this namespace.', 'This is the total amount of storage used across your projects within this namespace.',
); );
}); });
it('renders text in excess usage card footer', () => {
expect(
getStatisticsCard('excessUsage')
.find('[data-testid="statisticsCardFooter"]')
.text(),
).toMatchInterpolatedText(
'This is the total amount of storage used by projects above the free 978.8KiB storage limit.',
);
});
it('renders text in excess usage card footer', () => { it('renders button in purchased usage card footer', () => {
expect( expect(
getStatisticsCard('excessUsage') getStatisticsCard('purchasedUsage')
.find('[data-testid="statisticsCardFooter"]') .find(GlButton)
.text(), .exists(),
).toMatchInterpolatedText( ).toBe(true);
'This is the total amount of storage used by projects above the free 978.8KiB storage limit.', });
);
}); });
it('renders button in purchased usage card footer', () => { describe('with no purchaseStorageUrl', () => {
expect( beforeEach(() => {
getStatisticsCard('purchasedUsage') createComponent({
.find(GlButton) purchaseStorageUrl: null,
.exists(), });
).toBe(true); });
it('does not render purchased usage card if purchaseStorageUrl is not provided', () => {
expect(getStatisticsCard('purchasedUsage').exists()).toBe(false);
});
}); });
}); });
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