-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy patharg.web.test.ts
71 lines (47 loc) · 1.88 KB
/
arg.web.test.ts
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
59
60
61
62
63
64
65
66
67
68
69
70
71
namespace $ {
$mol_test_mocks.push( context => {
class $mol_state_arg_mock extends $mol_state_arg {
static $ = context
@ $mol_mem
static href( next? : string ) { return next || '' }
@ $mol_action
static go( next : { [ key : string ] : string | null } ) {
this.href( this.link( next ) )
}
}
context.$mol_state_arg = $mol_state_arg_mock
} )
$mol_test({
'args as dictionary'( $ ) {
$.$mol_state_arg.href( '#!foo=bar/xxx' )
$mol_assert_equal( $.$mol_state_arg.dict() , { foo : 'bar' , xxx : '' } )
$.$mol_state_arg.dict({ foo : null , yyy : '' , lol : '123' })
$mol_assert_equal( $.$mol_state_arg.href().replace( /.*#/ , '#' ) , '#!yyy/lol=123' )
} ,
'one value from args'( $ ) {
$.$mol_state_arg.href( '#!foo=bar/xxx' )
$mol_assert_equal( $.$mol_state_arg.value( 'foo' ) , 'bar' )
$mol_assert_equal( $.$mol_state_arg.value( 'xxx' ) , '' )
$.$mol_state_arg.value( 'foo' , 'lol' )
$mol_assert_equal( $.$mol_state_arg.href().replace( /.*#/ , '#' ) , '#!foo=lol/xxx' )
$.$mol_state_arg.value( 'foo' , '' )
$mol_assert_equal( $.$mol_state_arg.href().replace( /.*#/ , '#' ) , '#!foo/xxx' )
$.$mol_state_arg.value( 'foo' , null )
$mol_assert_equal( $.$mol_state_arg.href().replace( /.*#/ , '#' ) , '#!xxx' )
} ,
'nested args'( $ ) {
const base = new $.$mol_state_arg( 'nested.' )
class Nested extends $mol_state_arg {
constructor( prefix : string ) {
super( base.prefix + prefix )
}
static value = ( key : string , next? : string )=> base.value( key , next )
}
$.$mol_state_arg.href( '#!foo=bar/nested.xxx=123' )
$mol_assert_equal( Nested.value( 'foo' ) , null )
$mol_assert_equal( Nested.value( 'xxx' ) , '123' )
Nested.value( 'foo' , 'lol' )
$mol_assert_equal( $.$mol_state_arg.href().replace( /.*#/ , '#' ) , '#!foo=bar/nested.xxx=123/nested.foo=lol' )
} ,
})
}