-
-
Notifications
You must be signed in to change notification settings - Fork 2
TTS機能のリモートキルスイッチ(tts_enabled)を追加し、無効時は設定画面のトグルを無効化してサービスステータスへのリンクを表示 #6427
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
Show all changes
3 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import { act, render } from '@testing-library/react-native'; | ||
| import { createStore, Provider } from 'jotai'; | ||
| import { useTTS } from '~/hooks/useTTS'; | ||
| import { isTTSFeatureEnabled } from '~/lib/remoteConfig'; | ||
| import speechState from '~/store/atoms/speech'; | ||
| import { FxTTS } from './FxTTS'; | ||
|
|
||
| jest.mock('~/utils/isDevApp', () => ({ | ||
| isDevApp: false, | ||
| })); | ||
|
|
||
| jest.mock('~/hooks/useTTS', () => ({ | ||
| useTTS: jest.fn(), | ||
| })); | ||
|
|
||
| // useTTSFeatureEnabled(useSyncExternalStore) が購読するリスナーを捕捉し、 | ||
| // Remote Config 取得完了(キャッシュ更新)をテストから擬似的に発火できるようにする。 | ||
| const mockRemoteConfigListeners = new Set<() => void>(); | ||
| jest.mock('~/lib/remoteConfig', () => ({ | ||
| isTTSFeatureEnabled: jest.fn(() => true), | ||
| subscribeRemoteConfig: jest.fn((listener: () => void) => { | ||
| mockRemoteConfigListeners.add(listener); | ||
| return () => { | ||
| mockRemoteConfigListeners.delete(listener); | ||
| }; | ||
| }), | ||
| })); | ||
|
|
||
| const mockedIsTTSFeatureEnabled = jest.mocked(isTTSFeatureEnabled); | ||
| const mockedUseTTS = jest.mocked(useTTS); | ||
|
|
||
| const emitRemoteConfigUpdate = () => { | ||
| act(() => { | ||
| for (const listener of mockRemoteConfigListeners) { | ||
| listener(); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| const renderFxTTS = (enabled: boolean) => { | ||
| const store = createStore(); | ||
| store.set(speechState, { | ||
| enabled, | ||
| backgroundEnabled: false, | ||
| ttsEnabledLanguages: ['JA', 'EN'], | ||
| monetizedPlanEnabled: false, | ||
| }); | ||
|
|
||
| return render( | ||
| <Provider store={store}> | ||
| <FxTTS /> | ||
| </Provider> | ||
| ); | ||
| }; | ||
|
|
||
| describe('FxTTS', () => { | ||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| mockRemoteConfigListeners.clear(); | ||
| }); | ||
|
|
||
| it.each` | ||
| userEnabled | featureEnabled | shouldMount | ||
| ${true} | ${true} | ${true} | ||
| ${true} | ${false} | ${false} | ||
| ${false} | ${true} | ${false} | ||
| ${false} | ${false} | ${false} | ||
| `( | ||
| 'ユーザー設定=$userEnabled / Remote Config=$featureEnabled のときマウント=$shouldMount', | ||
| ({ userEnabled, featureEnabled, shouldMount }) => { | ||
| mockedIsTTSFeatureEnabled.mockReturnValue(featureEnabled); | ||
|
|
||
| renderFxTTS(userEnabled); | ||
|
|
||
| if (shouldMount) { | ||
| expect(mockedUseTTS).toHaveBeenCalled(); | ||
| } else { | ||
| expect(mockedUseTTS).not.toHaveBeenCalled(); | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| it('マウント後にRemote Configで無効化されるとアンマウントされる', () => { | ||
| mockedIsTTSFeatureEnabled.mockReturnValue(true); | ||
|
|
||
| renderFxTTS(true); | ||
|
|
||
| expect(mockedUseTTS).toHaveBeenCalled(); | ||
| mockedUseTTS.mockClear(); | ||
|
|
||
| // 起動時の非同期取得が後から tts_enabled=false を返したケースを再現する | ||
| mockedIsTTSFeatureEnabled.mockReturnValue(false); | ||
| emitRemoteConfigUpdate(); | ||
|
|
||
| expect(mockedUseTTS).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('マウント後にRemote Configで有効化されるとマウントされる', () => { | ||
| mockedIsTTSFeatureEnabled.mockReturnValue(false); | ||
|
|
||
| renderFxTTS(true); | ||
|
|
||
| expect(mockedUseTTS).not.toHaveBeenCalled(); | ||
|
|
||
| mockedIsTTSFeatureEnabled.mockReturnValue(true); | ||
| emitRemoteConfigUpdate(); | ||
|
|
||
| expect(mockedUseTTS).toHaveBeenCalled(); | ||
| }); | ||
| }); |
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,21 @@ | ||
| import { useAtomValue } from 'jotai'; | ||
| import type React from 'react'; | ||
| import { useTTS } from '~/hooks/useTTS'; | ||
| import { useTTSFeatureEnabled } from '~/hooks/useTTSFeatureEnabled'; | ||
| import speechState from '~/store/atoms/speech'; | ||
|
|
||
| const FxTTSInner: React.FC = () => { | ||
| useTTS(); | ||
| return null; | ||
| }; | ||
|
|
||
| // TTS無効時は useTTSText のテキスト構築(毎tick約19ms)ごとスキップする。 | ||
| // 有効化時にマウントされ直し、行先選択直後と同じ初回発話抑止から始まる。 | ||
| // Remote Config のキルスイッチ(tts_enabled=false)時は、ユーザー設定が有効でも | ||
| // 再生を止める。設定画面のトグル表示(無効化)と実挙動を一致させるため。 | ||
| // 起動時の非同期取得完了後に false が届いたケースでも購読経由で確実にアンマウントする。 | ||
| export const FxTTS: React.FC = () => { | ||
| const { enabled } = useAtomValue(speechState); | ||
| const ttsFeatureEnabled = useTTSFeatureEnabled(); | ||
| return enabled && ttsFeatureEnabled ? <FxTTSInner /> : null; | ||
| }; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { useSyncExternalStore } from 'react'; | ||
| import { isTTSFeatureEnabled, subscribeRemoteConfig } from '~/lib/remoteConfig'; | ||
|
|
||
| // TTS機能キルスイッチ(tts_enabled)のリアクティブ版。setupRemoteConfig は起動時に | ||
| // 非同期で完了するため、同期読みだけではコールドスタート時にフォールバック(true)で | ||
| // 描画された後、false 到着時の再レンダーが保証されない。キャッシュ更新を購読して | ||
| // 確実に再評価させる。 | ||
| export const useTTSFeatureEnabled = (): boolean => | ||
| useSyncExternalStore(subscribeRemoteConfig, isTTSFeatureEnabled); |
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
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.