Spaces:
Running
Running
File size: 1,918 Bytes
d0878a6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | import {
VIEW_CHAT_ACTIVE,
VIEW_CHAT_STARTER,
chatActiveState,
chatStarterState,
homeState,
isLeavingChatActive,
mapPopState,
sameHistoryState,
} from './chatHistoryNav';
describe('mapPopState', () => {
test('null / missing state goes home so the original load entry is not trapped', () => {
expect(mapPopState(null)).toEqual({
currentView: 'home',
chatNavView: null,
sessionId: null,
});
expect(mapPopState({})).toEqual({
currentView: 'home',
chatNavView: null,
sessionId: null,
});
expect(mapPopState(homeState())).toEqual({
currentView: 'home',
chatNavView: null,
sessionId: null,
});
});
test('leaving chat-active maps to starter; leaving starter maps to home', () => {
expect(mapPopState(chatStarterState())).toEqual({
currentView: 'chat',
chatNavView: 'starter',
sessionId: null,
});
expect(mapPopState(chatActiveState('abc'))).toEqual({
currentView: 'chat',
chatNavView: 'active',
sessionId: 'abc',
});
expect(isLeavingChatActive(VIEW_CHAT_ACTIVE, mapPopState(chatStarterState()))).toBe(true);
expect(isLeavingChatActive(VIEW_CHAT_STARTER, mapPopState(homeState()))).toBe(false);
});
test('canvas / journey / auth states restore those views', () => {
expect(mapPopState({ view: 'canvas' }).currentView).toBe('canvas');
expect(mapPopState({ view: 'journey' }).currentView).toBe('journey');
expect(mapPopState({ view: 'auth' }).currentView).toBe('auth');
});
test('sameHistoryState compares view + session', () => {
expect(sameHistoryState(chatActiveState('a'), chatActiveState('a'))).toBe(true);
expect(sameHistoryState(chatActiveState('a'), chatActiveState('b'))).toBe(false);
expect(sameHistoryState(chatStarterState(), homeState())).toBe(false);
});
});
|