Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,47 @@
import { QuotaUsageBar } from './QuotaUsageBar';

describe('QuotaUsageBanner', () => {
it('should display quota usage in proper units', () => {
const { getByText } = renderWithTheme(
<QuotaUsageBar limit={10} resourceMetric="byte" usage={1} />
);

const quotaUsageText = getByText('1 of 10 Bytes used');
expect(quotaUsageText).toBeVisible();
});

it.each([1000000000, 100000000, 10000000, 1000000])(
'should display content usage in proper format',
(usage) => {
it.each([
{ usage: 1, limit: 10, expectedText: '1 of 10 Bytes used' },
{ usage: 0, limit: 109951162777600, expectedText: '0 of 100 TB used' },
{
usage: 1000000,
limit: 109951162777600,
expectedText: '<0.01 of 100 TB used',

Check warning on line 14 in packages/manager/src/components/QuotaUsageBar/QuotaUsageBar.test.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Define a constant instead of duplicating this literal 4 times. Raw Output: {"ruleId":"sonarjs/no-duplicate-string","severity":1,"message":"Define a constant instead of duplicating this literal 4 times.","line":14,"column":21,"nodeType":"Literal","endLine":14,"endColumn":43}
},
{
usage: 10000000,
limit: 109951162777600,
expectedText: '<0.01 of 100 TB used',
},
{
usage: 100000000,
limit: 109951162777600,
expectedText: '<0.01 of 100 TB used',
},
{
usage: 1000000000,
limit: 109951162777600,
expectedText: '<0.01 of 100 TB used',
},
{ usage: 1, limit: 107374182400, expectedText: '<0.01 of 100 GB used' },
{
usage: 10737419,
limit: 107374182400,
expectedText: '0.01 of 100 GB used',
},
{
usage: 5368709,
limit: 107374182400,
expectedText: '<0.01 of 100 GB used',
},
])(
'should display correct byte quota usage text for $usage bytes used out of $limit bytes',
({ usage, limit, expectedText }) => {
const { getByText } = renderWithTheme(
<QuotaUsageBar
limit={109951162777600}
resourceMetric="byte"
usage={usage}
/>
<QuotaUsageBar limit={limit} resourceMetric="byte" usage={usage} />
);

const quotaUsageText = getByText('<0.01 of 100 TB used');
const quotaUsageText = getByText(expectedText);
expect(quotaUsageText).toBeVisible();
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export const QuotaUsageBar = ({ limit, usage, resourceMetric }: Props) => {
const convertedLimitString = convertedLimit.toLocaleString();

// Special case to display storage usage
if (convertedUsage === 0 && convertedResourceMetric === 'TB') {
if (convertedUsage === 0 && usage > 0) {
// assumes that the minimum converted non-zero value is expressed with an accuracy of 2 decimal places
convertedUsageString = '<0.01';
}

Expand Down