/
githubmirror
/
client
Обзор
Документация
Войти
/
githubmirror
/
client
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
shared/stores/tests/config.test.ts
122 строки
3 KB
chrisnojima
build(mobile): harden gobuild.sh and go bind pipeline 2 (#29364)
08 июл 2026, 15:25
Не верифицирован
08 июл 2026, 15:25
19b55b3
Код
Авторство
О чём код?
/// <reference types="jest" /> import {noConversationIDKey} from '../../constants/types/chat/common' import {useConfigState} from '../config' const resetConfigState = () => { const {dispatch} = useConfigState.getState() useConfigState.setState({ configuredAccounts: [], defaultUsername: '', globalError: undefined, outOfDate: { critical: false, message: '', outOfDate: false, updating: false, }, startup: { conversation: noConversationIDKey, followUser: '', link: '', loaded: false, }, userSwitching: false, } as any) dispatch.resetState() } beforeEach(() => { resetConfigState() }) afterEach(() => { resetConfigState() }) test('setStartupDetails only records the first startup payload', () => { const {dispatch} = useConfigState.getState() dispatch.setStartupDetails({ conversation: 'first-convo' as any, followUser: 'alice', link: 'keybase://first', tab: undefined, }) dispatch.setStartupDetails({ conversation: 'second-convo' as any, followUser: 'bob', link: 'keybase://second', tab: undefined, }) expect(useConfigState.getState().startup).toEqual({ conversation: 'first-convo', followUser: 'alice', link: 'keybase://first', loaded: true, tab: undefined, }) }) test('setOutOfDate merges fields and setGlobalError normalizes unknown input', () => { const {dispatch} = useConfigState.getState() dispatch.setOutOfDate({critical: true, message: 'upgrade required', outOfDate: true, updating: false}) dispatch.setUpdating() dispatch.setGlobalError('boom') const state = useConfigState.getState() expect(state.outOfDate).toEqual({ critical: true, message: 'upgrade required', outOfDate: true, updating: true, }) expect(state.globalError?.message).toBe('Unknown error: "boom"') }) test('onEngineIncoming owns audit errors and badge state', () => { const {dispatch} = useConfigState.getState() const badgeState = {inboxVers: 7} as any dispatch.onEngineIncoming({ payload: {params: {badgeState}}, type: 'keybase.1.NotifyBadges.badgeState', } as any) expect(useConfigState.getState().badgeState).toEqual(badgeState) dispatch.onEngineIncoming({ payload: {params: {message: 'root bad'}}, type: 'keybase.1.NotifyAudit.rootAuditError', } as any) expect(useConfigState.getState().globalError?.message).toBe( 'Keybase is buggy, please report this: root bad' ) dispatch.onEngineIncoming({ payload: {params: {message: 'box bad'}}, type: 'keybase.1.NotifyAudit.boxAuditError', } as any) expect(useConfigState.getState().globalError?.message).toBe( 'Keybase had a problem loading a team, please report this with `keybase log send`: box bad' ) }) test('custom resetState preserves the fields config intentionally carries across resets', () => { const {dispatch} = useConfigState.getState() dispatch.setAccounts([{hasStoredSecret: true, uid: 'alice-uid', username: 'alice'}]) dispatch.setDefaultUsername('alice') useConfigState.setState({ globalError: new Error('transient'), userSwitching: true, } as any) dispatch.resetState() const state = useConfigState.getState() expect(state.configuredAccounts).toEqual([{hasStoredSecret: true, uid: 'alice-uid', username: 'alice'}]) expect(state.defaultUsername).toBe('alice') expect(state.userSwitching).toBe(true) expect(state.globalError).toBeUndefined() })