* #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,99 +1,99 @@
|
||||
import { RootState } from "@/app/store";
|
||||
import { Calendar } from "@/features/Calendars/CalendarTypes";
|
||||
import { findCalendarById } from "@/utils";
|
||||
import { RootState } from '@/app/store'
|
||||
import { Calendar } from '@/features/Calendars/CalendarTypes'
|
||||
import { findCalendarById } from '@/utils'
|
||||
|
||||
describe("findCalendarById", () => {
|
||||
describe('findCalendarById', () => {
|
||||
const mockCalendar1: Calendar = {
|
||||
id: "cal1",
|
||||
name: "Personal",
|
||||
color: { light: "#FF0000" },
|
||||
} as unknown as Calendar;
|
||||
id: 'cal1',
|
||||
name: 'Personal',
|
||||
color: { light: '#FF0000' }
|
||||
} as unknown as Calendar
|
||||
|
||||
const mockCalendar2: Calendar = {
|
||||
id: "cal2",
|
||||
name: "Work",
|
||||
color: { light: "#0000FF" },
|
||||
} as unknown as Calendar;
|
||||
id: 'cal2',
|
||||
name: 'Work',
|
||||
color: { light: '#0000FF' }
|
||||
} as unknown as Calendar
|
||||
|
||||
const mockTempCalendar: Calendar = {
|
||||
id: "temp1",
|
||||
name: "Temporary",
|
||||
color: { light: "#00FF00" },
|
||||
} as unknown as Calendar;
|
||||
id: 'temp1',
|
||||
name: 'Temporary',
|
||||
color: { light: '#00FF00' }
|
||||
} as unknown as Calendar
|
||||
|
||||
const mockState = {
|
||||
calendars: {
|
||||
list: {
|
||||
cal1: mockCalendar1,
|
||||
cal2: mockCalendar2,
|
||||
cal2: mockCalendar2
|
||||
},
|
||||
templist: {
|
||||
temp1: mockTempCalendar,
|
||||
},
|
||||
},
|
||||
} as unknown as Partial<RootState>;
|
||||
temp1: mockTempCalendar
|
||||
}
|
||||
}
|
||||
} as unknown as Partial<RootState>
|
||||
|
||||
it("should find calendar in main list", () => {
|
||||
const result = findCalendarById(mockState, "cal1");
|
||||
it('should find calendar in main list', () => {
|
||||
const result = findCalendarById(mockState, 'cal1')
|
||||
|
||||
expect(result?.calendar).toEqual(mockCalendar1);
|
||||
expect(result?.type).toBeUndefined();
|
||||
});
|
||||
expect(result?.calendar).toEqual(mockCalendar1)
|
||||
expect(result?.type).toBeUndefined()
|
||||
})
|
||||
|
||||
it("should find calendar in temp list", () => {
|
||||
const result = findCalendarById(mockState, "temp1");
|
||||
it('should find calendar in temp list', () => {
|
||||
const result = findCalendarById(mockState, 'temp1')
|
||||
|
||||
expect(result?.calendar).toEqual(mockTempCalendar);
|
||||
expect(result?.type).toBe("temp");
|
||||
});
|
||||
expect(result?.calendar).toEqual(mockTempCalendar)
|
||||
expect(result?.type).toBe('temp')
|
||||
})
|
||||
|
||||
it("should not return calendar for non-existent id", () => {
|
||||
const result = findCalendarById(mockState, "nonexistent");
|
||||
it('should not return calendar for non-existent id', () => {
|
||||
const result = findCalendarById(mockState, 'nonexistent')
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
expect(result).toBeUndefined()
|
||||
})
|
||||
|
||||
it("should not return calendar for empty string", () => {
|
||||
const result = findCalendarById(mockState, "");
|
||||
it('should not return calendar for empty string', () => {
|
||||
const result = findCalendarById(mockState, '')
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
expect(result).toBeUndefined()
|
||||
})
|
||||
|
||||
it("should prioritize temp list over main list", () => {
|
||||
it('should prioritize temp list over main list', () => {
|
||||
const stateWithDuplicate = {
|
||||
calendars: {
|
||||
list: {
|
||||
dup1: mockCalendar1,
|
||||
dup1: mockCalendar1
|
||||
},
|
||||
templist: {
|
||||
dup1: mockTempCalendar,
|
||||
},
|
||||
},
|
||||
} as unknown as Partial<RootState>;
|
||||
dup1: mockTempCalendar
|
||||
}
|
||||
}
|
||||
} as unknown as Partial<RootState>
|
||||
|
||||
const result = findCalendarById(stateWithDuplicate, "dup1");
|
||||
const result = findCalendarById(stateWithDuplicate, 'dup1')
|
||||
|
||||
expect(result?.calendar).toEqual(mockTempCalendar);
|
||||
expect(result?.type).toBe("temp");
|
||||
});
|
||||
expect(result?.calendar).toEqual(mockTempCalendar)
|
||||
expect(result?.type).toBe('temp')
|
||||
})
|
||||
|
||||
it("should handle undefined list or templist", () => {
|
||||
it('should handle undefined list or templist', () => {
|
||||
const stateWithPartialCalendars = {
|
||||
calendars: {
|
||||
list: undefined,
|
||||
templist: { temp1: mockTempCalendar },
|
||||
},
|
||||
} as unknown as Partial<RootState>;
|
||||
templist: { temp1: mockTempCalendar }
|
||||
}
|
||||
} as unknown as Partial<RootState>
|
||||
|
||||
const result = findCalendarById(stateWithPartialCalendars, "temp1");
|
||||
expect(result?.calendar).toEqual(mockTempCalendar);
|
||||
});
|
||||
const result = findCalendarById(stateWithPartialCalendars, 'temp1')
|
||||
expect(result?.calendar).toEqual(mockTempCalendar)
|
||||
})
|
||||
|
||||
it("should handle missing calendars state", () => {
|
||||
const emptyState = {};
|
||||
it('should handle missing calendars state', () => {
|
||||
const emptyState = {}
|
||||
|
||||
const result = findCalendarById(emptyState, "cal1");
|
||||
const result = findCalendarById(emptyState, 'cal1')
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
});
|
||||
expect(result).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user