Skip to content

Commit f716264

Browse files
committed
test(locale): add unit tests for normalizeStartOfWeek function
1 parent 124976b commit f716264

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { normalizeStartOfWeek } from '../normalize-start-of-week';
5+
6+
// Mock the weekstart module
7+
jest.mock('weekstart', () => ({
8+
getWeekStartByLocale: jest.fn(),
9+
}));
10+
11+
import { getWeekStartByLocale } from 'weekstart';
12+
13+
const mockGetWeekStartByLocale = getWeekStartByLocale as jest.MockedFunction<typeof getWeekStartByLocale>;
14+
15+
describe('normalizeStartOfWeek', () => {
16+
beforeEach(() => {
17+
mockGetWeekStartByLocale.mockReset();
18+
});
19+
20+
describe('when startOfWeek is undefined', () => {
21+
test('should call getWeekStartByLocale with the provided locale', () => {
22+
mockGetWeekStartByLocale.mockReturnValue(0);
23+
const result = normalizeStartOfWeek(undefined, 'en-US');
24+
25+
expect(mockGetWeekStartByLocale).toHaveBeenCalledWith('en-US');
26+
expect(mockGetWeekStartByLocale).toHaveBeenCalledTimes(1);
27+
expect(result).toBe(0);
28+
});
29+
30+
test('should return Sunday (0) for US locale', () => {
31+
mockGetWeekStartByLocale.mockReturnValue(0);
32+
expect(normalizeStartOfWeek(undefined, 'en-US')).toBe(0);
33+
});
34+
35+
test('should return Monday (1) for French locale', () => {
36+
mockGetWeekStartByLocale.mockReturnValue(1);
37+
expect(normalizeStartOfWeek(undefined, 'fr-FR')).toBe(1);
38+
});
39+
});
40+
41+
test('should prioritize provided number over locale', () => {
42+
mockGetWeekStartByLocale.mockReturnValue(0);
43+
expect(normalizeStartOfWeek(1, 'en-US')).toBe(1);
44+
expect(mockGetWeekStartByLocale).not.toHaveBeenCalled();
45+
});
46+
});

0 commit comments

Comments
 (0)