* #708 apply strictier linting rules and fix simple eslint bugs * #708 fix eslint errors relate to promise * #708 fix eslint import/no-extraneous-dependencies * #708 fix eslint errors of react-hook * #708 enable eslint check for typescript --------- Co-authored-by: lethemanh <lethemanh@lethemanhs-MacBook-Pro.local>
This commit is contained in:
@@ -1,157 +1,157 @@
|
||||
import { makeRecurrenceString } from "@/features/Events/EventPreview/utils/makeRecurrenceString";
|
||||
import { RepetitionObject } from "@/features/Events/EventsTypes";
|
||||
import { makeRecurrenceString } from '@/features/Events/EventPreview/utils/makeRecurrenceString'
|
||||
import { RepetitionObject } from '@/features/Events/EventsTypes'
|
||||
|
||||
describe("makeRecurrenceString", () => {
|
||||
describe('makeRecurrenceString', () => {
|
||||
const mockT = jest.fn((key: string, params?: any) => {
|
||||
if (params) {
|
||||
if (key === "eventPreview.everyInterval") {
|
||||
return `Every ${params.interval} ${params.unit}`;
|
||||
if (key === 'eventPreview.everyInterval') {
|
||||
return `Every ${params.interval} ${params.unit}`
|
||||
}
|
||||
if (key === "eventPreview.recurrenceOnDays") {
|
||||
return `on ${params.days}`;
|
||||
if (key === 'eventPreview.recurrenceOnDays') {
|
||||
return `on ${params.days}`
|
||||
}
|
||||
if (key === "eventPreview.forOccurrences") {
|
||||
return `for ${params.count} times`;
|
||||
if (key === 'eventPreview.forOccurrences') {
|
||||
return `for ${params.count} times`
|
||||
}
|
||||
if (key === "eventPreview.until") {
|
||||
return `until ${params.date}`;
|
||||
if (key === 'eventPreview.until') {
|
||||
return `until ${params.date}`
|
||||
}
|
||||
}
|
||||
|
||||
const translations: Record<string, string> = {
|
||||
"event.repeat.frequency.days": "days",
|
||||
"event.repeat.frequency.weeks": "weeks",
|
||||
"event.repeat.frequency.months": "months",
|
||||
"event.repeat.frequency.years": "years",
|
||||
"eventPreview.onDays.MO": "Monday",
|
||||
"eventPreview.onDays.TU": "Tuesday",
|
||||
"eventPreview.onDays.WE": "Wednesday",
|
||||
"eventPreview.onDays.TH": "Thursday",
|
||||
"eventPreview.onDays.FR": "Friday",
|
||||
"eventPreview.onDays.SA": "Saturday",
|
||||
"eventPreview.onDays.SU": "Sunday",
|
||||
locale: "en-US",
|
||||
};
|
||||
'event.repeat.frequency.days': 'days',
|
||||
'event.repeat.frequency.weeks': 'weeks',
|
||||
'event.repeat.frequency.months': 'months',
|
||||
'event.repeat.frequency.years': 'years',
|
||||
'eventPreview.onDays.MO': 'Monday',
|
||||
'eventPreview.onDays.TU': 'Tuesday',
|
||||
'eventPreview.onDays.WE': 'Wednesday',
|
||||
'eventPreview.onDays.TH': 'Thursday',
|
||||
'eventPreview.onDays.FR': 'Friday',
|
||||
'eventPreview.onDays.SA': 'Saturday',
|
||||
'eventPreview.onDays.SU': 'Sunday',
|
||||
locale: 'en-US'
|
||||
}
|
||||
|
||||
return translations[key] || key;
|
||||
});
|
||||
return translations[key] || key
|
||||
})
|
||||
|
||||
const startText = "Repeats";
|
||||
const startText = 'Repeats'
|
||||
|
||||
beforeEach(() => {
|
||||
mockT.mockClear();
|
||||
});
|
||||
mockT.mockClear()
|
||||
})
|
||||
|
||||
it("formats string for interval === 1 when enableStrForOneTimeInterval is true", () => {
|
||||
const repetition: RepetitionObject = { freq: "daily", interval: 1 };
|
||||
it('formats string for interval === 1 when enableStrForOneTimeInterval is true', () => {
|
||||
const repetition: RepetitionObject = { freq: 'daily', interval: 1 }
|
||||
const result = makeRecurrenceString({
|
||||
repetition,
|
||||
t: mockT,
|
||||
startText,
|
||||
enableStrForOneTimeInterval: true,
|
||||
});
|
||||
enableStrForOneTimeInterval: true
|
||||
})
|
||||
|
||||
expect(result).toBe("Repeats, days");
|
||||
});
|
||||
expect(result).toBe('Repeats, days')
|
||||
})
|
||||
|
||||
it("formats string when interval is undefined", () => {
|
||||
const repetition: RepetitionObject = { freq: "daily" };
|
||||
it('formats string when interval is undefined', () => {
|
||||
const repetition: RepetitionObject = { freq: 'daily' }
|
||||
const result = makeRecurrenceString({
|
||||
repetition,
|
||||
t: mockT,
|
||||
startText,
|
||||
enableStrForOneTimeInterval: true,
|
||||
});
|
||||
enableStrForOneTimeInterval: true
|
||||
})
|
||||
|
||||
expect(result).toBe("Repeats, days");
|
||||
});
|
||||
expect(result).toBe('Repeats, days')
|
||||
})
|
||||
|
||||
it("formats string for interval > 1", () => {
|
||||
const repetition: RepetitionObject = { freq: "weekly", interval: 2 };
|
||||
const result = makeRecurrenceString({ repetition, t: mockT, startText });
|
||||
it('formats string for interval > 1', () => {
|
||||
const repetition: RepetitionObject = { freq: 'weekly', interval: 2 }
|
||||
const result = makeRecurrenceString({ repetition, t: mockT, startText })
|
||||
|
||||
expect(result).toBe("Repeats, Every 2 weeks");
|
||||
expect(mockT).toHaveBeenCalledWith("eventPreview.everyInterval", {
|
||||
expect(result).toBe('Repeats, Every 2 weeks')
|
||||
expect(mockT).toHaveBeenCalledWith('eventPreview.everyInterval', {
|
||||
interval: 2,
|
||||
unit: "weeks",
|
||||
});
|
||||
});
|
||||
unit: 'weeks'
|
||||
})
|
||||
})
|
||||
|
||||
it("formats string with specific days and sorts them according to WEEK_DAYS order", () => {
|
||||
it('formats string with specific days and sorts them according to WEEK_DAYS order', () => {
|
||||
const repetition: RepetitionObject = {
|
||||
freq: "weekly",
|
||||
freq: 'weekly',
|
||||
interval: 1,
|
||||
byday: ["WE", "MO", "FR"],
|
||||
};
|
||||
const result = makeRecurrenceString({ repetition, t: mockT, startText });
|
||||
byday: ['WE', 'MO', 'FR']
|
||||
}
|
||||
const result = makeRecurrenceString({ repetition, t: mockT, startText })
|
||||
|
||||
// Expected order: MO, WE, FR
|
||||
expect(result).toBe("Repeats, on Monday, Wednesday, Friday");
|
||||
});
|
||||
expect(result).toBe('Repeats, on Monday, Wednesday, Friday')
|
||||
})
|
||||
|
||||
it("formats string with occurrences count", () => {
|
||||
it('formats string with occurrences count', () => {
|
||||
const repetition: RepetitionObject = {
|
||||
freq: "daily",
|
||||
freq: 'daily',
|
||||
interval: 1,
|
||||
occurrences: 5,
|
||||
};
|
||||
const result = makeRecurrenceString({ repetition, t: mockT, startText });
|
||||
occurrences: 5
|
||||
}
|
||||
const result = makeRecurrenceString({ repetition, t: mockT, startText })
|
||||
|
||||
expect(result).toBe("Repeats, for 5 times");
|
||||
});
|
||||
expect(result).toBe('Repeats, for 5 times')
|
||||
})
|
||||
|
||||
it("formats string with end date", () => {
|
||||
const endDate = "2025-12-31T00:00:00.000Z";
|
||||
it('formats string with end date', () => {
|
||||
const endDate = '2025-12-31T00:00:00.000Z'
|
||||
const repetition: RepetitionObject = {
|
||||
freq: "daily",
|
||||
freq: 'daily',
|
||||
interval: 1,
|
||||
endDate,
|
||||
};
|
||||
const result = makeRecurrenceString({ repetition, t: mockT, startText });
|
||||
endDate
|
||||
}
|
||||
const result = makeRecurrenceString({ repetition, t: mockT, startText })
|
||||
|
||||
const formattedDate = new Date(endDate).toLocaleDateString("en-US", {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
});
|
||||
const formattedDate = new Date(endDate).toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric'
|
||||
})
|
||||
|
||||
expect(result).toBe(`Repeats, until ${formattedDate}`);
|
||||
});
|
||||
expect(result).toBe(`Repeats, until ${formattedDate}`)
|
||||
})
|
||||
|
||||
it("combines multiple properties", () => {
|
||||
const endDate = "2025-12-31T00:00:00.000Z";
|
||||
it('combines multiple properties', () => {
|
||||
const endDate = '2025-12-31T00:00:00.000Z'
|
||||
const repetition: RepetitionObject = {
|
||||
freq: "monthly",
|
||||
freq: 'monthly',
|
||||
interval: 3,
|
||||
byday: ["TU", "TH"],
|
||||
endDate,
|
||||
};
|
||||
const result = makeRecurrenceString({ repetition, t: mockT, startText });
|
||||
byday: ['TU', 'TH'],
|
||||
endDate
|
||||
}
|
||||
const result = makeRecurrenceString({ repetition, t: mockT, startText })
|
||||
|
||||
const formattedDate = new Date(endDate).toLocaleDateString("en-US", {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
});
|
||||
const formattedDate = new Date(endDate).toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric'
|
||||
})
|
||||
|
||||
expect(result).toBe(
|
||||
`Repeats, Every 3 months, on Tuesday, Thursday, until ${formattedDate}`
|
||||
);
|
||||
});
|
||||
)
|
||||
})
|
||||
|
||||
it("uses custom joinChar when provided", () => {
|
||||
it('uses custom joinChar when provided', () => {
|
||||
const repetition: RepetitionObject = {
|
||||
freq: "weekly",
|
||||
freq: 'weekly',
|
||||
interval: 2,
|
||||
occurrences: 10,
|
||||
};
|
||||
occurrences: 10
|
||||
}
|
||||
const result = makeRecurrenceString({
|
||||
repetition,
|
||||
t: mockT,
|
||||
startText,
|
||||
joinChar: ";",
|
||||
});
|
||||
joinChar: ';'
|
||||
})
|
||||
|
||||
expect(result).toBe("Repeats; Every 2 weeks; for 10 times");
|
||||
});
|
||||
});
|
||||
expect(result).toBe('Repeats; Every 2 weeks; for 10 times')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user