-
-
Notifications
You must be signed in to change notification settings - Fork 2
路線切り替え時の前回データクリアに関するテストを追加 #5355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -618,3 +618,137 @@ describe('SelectLineScreenPresets - ループデータ生成', () => { | |
| expect(getAllByTestId('preset-card').length).toBe(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe('SelectLineScreen - 路線切り替え時の前回データクリア', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('路線選択時に前回の列車種別データ(fetchedTrainTypes, trainType, pendingTrainType)がクリアされる', () => { | ||
| const mockSetNavigationState = jest.fn(); | ||
| // 大江戸線を選択した後の状態を再現 | ||
| const staleNavigationState = { | ||
| headerState: 'CURRENT', | ||
| leftStations: [], | ||
| trainType: { id: 10, groupId: 500, name: '都営大江戸線' }, | ||
| pendingTrainType: { id: 10, groupId: 500, name: '都営大江戸線' }, | ||
| autoModeEnabled: true, | ||
| stationForHeader: null, | ||
| arrived: false, | ||
| approaching: false, | ||
| isLEDTheme: false, | ||
| fetchedTrainTypes: [{ id: 10, groupId: 500, name: '都営大江戸線' }], | ||
| headerTransitionDelay: false, | ||
| targetAutoModeStation: null, | ||
| firstStop: true, | ||
| presetsFetched: false, | ||
| presetRoutes: [], | ||
| }; | ||
|
|
||
| (useAtom as jest.Mock).mockReturnValue([ | ||
| staleNavigationState, | ||
| mockSetNavigationState, | ||
| ]); | ||
|
|
||
| // handleLineSelected で fetch 前に行われるリセットをシミュレート | ||
| mockSetNavigationState((prev: typeof staleNavigationState) => ({ | ||
| ...prev, | ||
| fetchedTrainTypes: [], | ||
| trainType: null, | ||
| pendingTrainType: null, | ||
| })); | ||
|
|
||
| const updateFunction = mockSetNavigationState.mock.calls[0][0]; | ||
| const updatedState = updateFunction(staleNavigationState); | ||
|
|
||
| expect(updatedState.fetchedTrainTypes).toEqual([]); | ||
| expect(updatedState.trainType).toBeNull(); | ||
| expect(updatedState.pendingTrainType).toBeNull(); | ||
| }); | ||
|
|
||
| it('路線選択時に前回のpending駅データがクリアされる', () => { | ||
| const mockSetStationState = jest.fn(); | ||
| // 大江戸線を選択した後の状態を再現 | ||
| const staleStationState = { | ||
| station: { id: 1, name: '大門' }, | ||
| stations: [], | ||
| pendingStation: { id: 2, name: '六本木' }, | ||
| pendingStations: [ | ||
| { id: 2, name: '六本木' }, | ||
| { id: 3, name: '新宿西口' }, | ||
| ], | ||
| selectedDirection: 'INBOUND', | ||
| wantedDestination: null, | ||
| selectedBound: { id: 4, name: '光が丘' }, | ||
| stationsCache: [], | ||
| }; | ||
|
|
||
| (useAtom as jest.Mock).mockReturnValue([ | ||
| staleStationState, | ||
| mockSetStationState, | ||
| ]); | ||
|
|
||
| // handleLineSelected で fetch 前に行われるリセットをシミュレート | ||
| mockSetStationState((prev: typeof staleStationState) => ({ | ||
| ...prev, | ||
| pendingStation: null, | ||
| pendingStations: [], | ||
| selectedDirection: null, | ||
| wantedDestination: null, | ||
| selectedBound: null, | ||
| })); | ||
|
|
||
| const updateFunction = mockSetStationState.mock.calls[0][0]; | ||
| const updatedState = updateFunction(staleStationState); | ||
|
|
||
| expect(updatedState.pendingStation).toBeNull(); | ||
| expect(updatedState.pendingStations).toEqual([]); | ||
| expect(updatedState.selectedDirection).toBeNull(); | ||
| expect(updatedState.wantedDestination).toBeNull(); | ||
| expect(updatedState.selectedBound).toBeNull(); | ||
| // 現在の最寄り駅は変更されないことを確認 | ||
| expect(updatedState.station).toEqual({ id: 1, name: '大門' }); | ||
| }); | ||
|
|
||
| it('リセット後に新しい路線データで上書きされる', () => { | ||
| const mockSetStationState = jest.fn(); | ||
| // リセット済みの状態 | ||
| const resetState = { | ||
| station: { id: 1, name: '大門' }, | ||
| stations: [], | ||
| pendingStation: null, | ||
| pendingStations: [], | ||
| selectedDirection: null, | ||
| wantedDestination: null, | ||
| selectedBound: null, | ||
| stationsCache: [], | ||
| }; | ||
|
|
||
| (useAtom as jest.Mock).mockReturnValue([resetState, mockSetStationState]); | ||
|
|
||
| // fetch 完了後に行われる状態更新をシミュレート | ||
| const newPendingStation = { | ||
| id: 5, | ||
| name: '大門', | ||
| line: { id: 200, name: '都営浅草線' }, | ||
| }; | ||
| const newPendingStations = [ | ||
| { id: 5, name: '大門' }, | ||
| { id: 6, name: '新橋' }, | ||
| ]; | ||
| mockSetStationState((prev: typeof resetState) => ({ | ||
| ...prev, | ||
| pendingStation: newPendingStation, | ||
| pendingStations: newPendingStations, | ||
| })); | ||
|
|
||
| const updateFunction = mockSetStationState.mock.calls[0][0]; | ||
| const updatedState = updateFunction(resetState); | ||
|
|
||
| expect(updatedState.pendingStation).toEqual(newPendingStation); | ||
| expect(updatedState.pendingStations).toEqual(newPendingStations); | ||
| // リセット済みのフィールドは null/空のまま(fetch 結果では上書きされない) | ||
| expect(updatedState.selectedDirection).toBeNull(); | ||
| expect(updatedState.selectedBound).toBeNull(); | ||
| }); | ||
|
Comment on lines
+627
to
+753
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 実装コードを実行していないため、テストが実質的に自己検証になっています
🤖 Prompt for AI Agents |
||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jest.clearAllMocks()はafterEachで呼んでくださいガイドラインに合わせて
beforeEachではなくafterEachに移してください。修正案
📝 Committable suggestion
🤖 Prompt for AI Agents