mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
modifing yyy label, spy reset after each test gets finished
This commit is contained in:
parent
85d89de072
commit
42739c660e
2 changed files with 11 additions and 7 deletions
|
|
@ -41,19 +41,23 @@ describe('renderNumberLabels', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// test for renderDateLabels
|
||||
|
||||
jest.spyOn(require('lib/date'), 'formatDate'); // Spy on formatDate but use real implementation
|
||||
|
||||
describe('renderDateLabels', () => {
|
||||
const mockValues = [{ value: '2024-03-23T10:00:00Z' }, { value: '2024-03-24T15:30:00Z' }];
|
||||
|
||||
beforeEach(() => {
|
||||
jest.spyOn(require('lib/date'), 'formatDate');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks(); // Reset spy to prevent interference
|
||||
});
|
||||
|
||||
test.each([
|
||||
['minute', 'h:mm', 'en-US'],
|
||||
['hour', 'p', 'en-US'],
|
||||
['day', 'MMM d', 'en-US'],
|
||||
['month', 'MMM', 'en-US'],
|
||||
['year', 'YYY', 'en-US'],
|
||||
['year', 'yyyy', 'en-US'],
|
||||
])('formats date correctly for unit: %s', (unit, expectedFormat, locale) => {
|
||||
const formatLabel = renderDateLabels(unit, locale);
|
||||
const formatted = formatLabel('label', 0, mockValues);
|
||||
|
|
@ -67,7 +71,7 @@ describe('renderDateLabels', () => {
|
|||
expect(formatLabel('original-label', 0, mockValues)).toBe('original-label');
|
||||
});
|
||||
|
||||
test('handles invalid date gracefully', () => {
|
||||
test('throws error for invalid date input', () => {
|
||||
const invalidValues = [{ value: 'invalid-date' }];
|
||||
const formatLabel = renderDateLabels('day', 'en-US');
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ export function renderDateLabels(unit: string, locale: string) {
|
|||
case 'month':
|
||||
return formatDate(d, 'MMM', locale);
|
||||
case 'year':
|
||||
return formatDate(d, 'YYY', locale);
|
||||
return formatDate(d, 'yyyy', locale);
|
||||
default:
|
||||
return label;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue