forked from CredenceOrg/Credence-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmartBack.test.ts
More file actions
57 lines (45 loc) · 1.52 KB
/
Copy pathsmartBack.test.ts
File metadata and controls
57 lines (45 loc) · 1.52 KB
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
import { describe, expect, it } from 'vitest'
import { resolveSmartBackDestination } from './smartBack'
describe('resolveSmartBackDestination', () => {
it('honours_prior_route_path_when_from_state_is_present', () => {
const result = resolveSmartBackDestination({ from: '/trust' }, true)
expect(result).toEqual({
type: 'state',
path: '/trust',
})
})
it('trims_and_honours_prior_route_path_with_whitespace', () => {
const result = resolveSmartBackDestination({ from: ' /settings ' }, true)
expect(result).toEqual({
type: 'state',
path: '/settings',
})
})
it('uses_history_back_when_history_exists_and_from_state_is_missing', () => {
const result = resolveSmartBackDestination(null, true)
expect(result).toEqual({
type: 'history',
})
})
it('falls_back_to_dashboard_when_history_is_missing_and_from_state_is_missing', () => {
const result = resolveSmartBackDestination(null, false)
expect(result).toEqual({
type: 'fallback',
path: '/dashboard',
})
})
it('uses_custom_fallback_route_when_provided_and_history_is_missing', () => {
const result = resolveSmartBackDestination(null, false, '/bond')
expect(result).toEqual({
type: 'fallback',
path: '/bond',
})
})
it('prioritises_from_state_over_history_and_fallback', () => {
const result = resolveSmartBackDestination({ from: '/attestations' }, true, '/custom-fallback')
expect(result).toEqual({
type: 'state',
path: '/attestations',
})
})
})