-
-
Notifications
You must be signed in to change notification settings - Fork 0
fix(split-meow): 混幣行程加入 proactive 阻擋與編輯幣別對齊 #457
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
Merged
Merged
Changes from all commits
Commits
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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@app/split-meow': patch | ||
| --- | ||
|
|
||
| 切換幣別或記帳若會使同一行程混用多種幣別,改在當下以確認對話框提示;編輯舊費用時改以行程主導幣別解析符號,避免顯示錯誤幣別。時區自動偵測幣別若會造成混幣則靜默跳過,不再覆寫使用者幣別。 |
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
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
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
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
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
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
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
68 changes: 68 additions & 0 deletions
68
apps/split-meow/src/hooks/__tests__/useCurrencyAutoDetect.test.ts
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 |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { renderHook, waitFor } from '@testing-library/react'; | ||
| import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; | ||
| import type * as CurrenciesModule from '../../config/currencies'; | ||
| import { useStore } from '../../store/useStore'; | ||
|
|
||
| vi.mock('../../lib/exchangeRate', () => ({ | ||
| fetchMoneyboxRate: vi.fn().mockResolvedValue({ krwPerTwd: 43.5, updatedAt: '2026-01-01' }), | ||
| })); | ||
|
|
||
| vi.mock('../../config/currencies', async (importOriginal) => { | ||
| const actual = await importOriginal<typeof CurrenciesModule>(); | ||
| return { | ||
| ...actual, | ||
| detectCurrencyFromTimezone: vi.fn(() => 'KRW' as const), | ||
| }; | ||
| }); | ||
|
|
||
| import { useCurrencyAutoDetect } from '../useCurrencyAutoDetect'; | ||
| import { detectCurrencyFromTimezone } from '../../config/currencies'; | ||
|
|
||
| describe('useCurrencyAutoDetect', () => { | ||
| beforeEach(() => { | ||
| vi.mocked(detectCurrencyFromTimezone).mockReturnValue('KRW'); | ||
| useStore.setState({ | ||
| currency: 'TWD', | ||
| currencyManuallySet: false, | ||
| currentTripId: 'default-trip', | ||
| expenses: [], | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('混幣風險時跳過自動切換幣別', async () => { | ||
| useStore.setState({ | ||
| expenses: [ | ||
| { | ||
| id: 'exp-1', | ||
| tripId: 'default-trip', | ||
| type: 'split_evenly', | ||
| participantIds: ['me'], | ||
| paidBy: 'me', | ||
| totalAmount: 100, | ||
| perPersonAmounts: { me: 100 }, | ||
| note: '', | ||
| createdAt: 1, | ||
| currency: 'TWD', | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| renderHook(() => useCurrencyAutoDetect()); | ||
|
|
||
| await waitFor(() => { | ||
| expect(useStore.getState().currency).toBe('TWD'); | ||
| }); | ||
| }); | ||
|
|
||
| it('無混幣風險時依時區自動切換', async () => { | ||
| renderHook(() => useCurrencyAutoDetect()); | ||
|
|
||
| await waitFor(() => { | ||
| expect(useStore.getState().currency).toBe('KRW'); | ||
| }); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.