Skip to content

Commit

Permalink
fix(delivery-schedule): correct weekday mapping for cut-off times (#252)
Browse files Browse the repository at this point in the history
INT-502

---------

Co-authored-by: Clerise Swart <[email protected]>
  • Loading branch information
MPClerise and Clerise Swart authored Oct 10, 2024
1 parent 7f303e3 commit 62fd354
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
33 changes: 33 additions & 0 deletions apps/sandbox/src/composables/useWeekdays.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {nextTick} from 'vue';
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
import {createPinia, setActivePinia} from 'pinia';

/**
* @vitest-environment happy-dom
*/

describe('useWeekdays', () => {
beforeEach(() => {
setActivePinia(createPinia());
});

afterEach(() => {
vi.resetModules();
vi.restoreAllMocks();
});

it('returns weekdays in English for en-US', async () => {
vi.mock('./useLanguage', () => ({
useLanguage: vi.fn(() => ({
language: {value: {code: 'en-US'}},
})),
}));

const {useWeekdays} = await import('./useWeekdays');
await nextTick();

const weekdays = useWeekdays();

expect(weekdays.value).toEqual(['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']);
});
});
4 changes: 2 additions & 2 deletions apps/sandbox/src/composables/useWeekdays.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {computed, type ComputedRef} from 'vue';
import {setDay} from 'date-fns';
import {useLanguage} from './useLanguage';

export const useWeekdays = (): ComputedRef<string[]> => {
const language = useLanguage();

return computed(() => {
return Array.from({length: 7}, (_, i) => {
const date = new Date(0);
date.setDate(i + 5);
const date = setDay(new Date(), i, {weekStartsOn: 0});

return date.toLocaleDateString(language.language.value.code, {weekday: 'long'});
});
Expand Down

0 comments on commit 62fd354

Please sign in to comment.