Skip to content

Commit 92d916a

Browse files
Copilotnannany
andcommitted
fix: コードレビューのフィードバックに対応し、start_time更新の検出を改善
Co-authored-by: nannany <14943122+nannany@users.noreply.github.com>
1 parent 6af6419 commit 92d916a

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

ui/src/reducers/taskReducer.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,28 @@ describe("taskReducer", () => {
6767
expect(newState[2].start_time).toBe("2024-01-01T10:00:00Z");
6868
});
6969

70+
it("should re-sort tasks when start_time is set to null", () => {
71+
const task1WithStart = { ...mockTask1, start_time: "2024-01-01T10:00:00Z" };
72+
const initialState = [mockTask2, mockTask3, task1WithStart];
73+
74+
// Task1のstart_timeをnullに設定
75+
const action = {
76+
type: "UPDATE_TASK" as const,
77+
payload: {
78+
id: "1",
79+
start_time: null,
80+
},
81+
};
82+
83+
const newState = taskReducer(initialState, action);
84+
85+
// Task1がstart_time: nullになるため、task_orderに基づいて先頭に移動
86+
expect(newState[0].id).toBe("1");
87+
expect(newState[1].id).toBe("2");
88+
expect(newState[2].id).toBe("3");
89+
expect(newState[0].start_time).toBeNull();
90+
});
91+
7092
it("should sort tasks by start_time when multiple tasks have start_time", () => {
7193
const task1WithStart = { ...mockTask1, start_time: "2024-01-01T12:00:00Z" };
7294
const task2WithStart = { ...mockTask2, start_time: "2024-01-01T10:00:00Z" };

ui/src/reducers/taskReducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const taskReducer = (state: Task[], action: TaskAction): Task[] => {
3838
task.id === action.payload.id ? { ...task, ...action.payload } : task,
3939
);
4040
// start_timeが更新された場合、タスクを再ソート
41-
if (action.payload.start_time !== undefined) {
41+
if ("start_time" in action.payload) {
4242
return sortTasks(updatedTasks);
4343
}
4444
return updatedTasks;

0 commit comments

Comments
 (0)