File tree Expand file tree Collapse file tree 15 files changed +436
-49
lines changed Expand file tree Collapse file tree 15 files changed +436
-49
lines changed Original file line number Diff line number Diff line change
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports [` components/fields/radiogroup.tsx should render 1` ] = `
4
+ <fieldset
5
+ className = " mb-1"
6
+ id = " appearance"
7
+ >
8
+ <div >
9
+ <legend
10
+ className = " mb-1 text-base font-medium dark:text-white"
11
+ >
12
+ Appearance
13
+ </legend >
14
+ <p
15
+ className = " text-sm text-gray-500"
16
+ >
17
+ This is some helper text
18
+ </p >
19
+ </div >
20
+ <div
21
+ aria-labelledby = " appearance"
22
+ className = " flex items-center space-x-4 py-2"
23
+ role = " group"
24
+ >
25
+ <div
26
+ className = " flex items-center mt-1"
27
+ >
28
+ <input
29
+ checked = { false }
30
+ className = " focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300"
31
+ id = " appearance_one"
32
+ name = " appearance"
33
+ onChange = { [MockFunction ]}
34
+ type = " radio"
35
+ value = " one"
36
+ />
37
+ <label
38
+ className = " ml-3 block text-sm font-medium text-gray-700 dark:text-white"
39
+ htmlFor = " appearance_one"
40
+ >
41
+ Value 1
42
+ </label >
43
+ </div >
44
+ <div
45
+ className = " flex items-center mt-1"
46
+ >
47
+ <input
48
+ checked = { true }
49
+ className = " focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300"
50
+ id = " appearance_two"
51
+ name = " appearance"
52
+ onChange = { [MockFunction ]}
53
+ type = " radio"
54
+ value = " two"
55
+ />
56
+ <label
57
+ className = " ml-3 block text-sm font-medium text-gray-700 dark:text-white"
58
+ htmlFor = " appearance_two"
59
+ >
60
+ Value 2
61
+ </label >
62
+ </div >
63
+ </div >
64
+ </fieldset >
65
+ ` ;
Original file line number Diff line number Diff line change
1
+ import * as React from 'react' ;
2
+ import * as TestRendener from 'react-test-renderer' ;
3
+ import { fireEvent , render } from '@testing-library/react' ;
4
+
5
+ import { FieldRadioGroup } from './radiogroup' ;
6
+
7
+ describe ( 'components/fields/radiogroup.tsx' , ( ) => {
8
+ const props = {
9
+ label : 'Appearance' ,
10
+ name : 'appearance' ,
11
+ placeholder : 'This is some helper text' ,
12
+ options : [
13
+ { label : 'Value 1' , value : 'one' } ,
14
+ { label : 'Value 2' , value : 'two' } ,
15
+ ] ,
16
+ onChange : jest . fn ( ) ,
17
+ value : 'two' ,
18
+ } ;
19
+
20
+ it ( 'should render ' , ( ) => {
21
+ const tree = TestRendener . create ( < FieldRadioGroup { ...props } /> ) ;
22
+ expect ( tree ) . toMatchSnapshot ( ) ;
23
+ } ) ;
24
+
25
+ it ( 'should check that NProgress is getting called in getDerivedStateFromProps (loading)' , function ( ) {
26
+ const { getByLabelText } = render ( < FieldRadioGroup { ...props } /> ) ;
27
+ fireEvent . click ( getByLabelText ( 'Value 1' ) ) ;
28
+ expect ( props . onChange ) . toHaveBeenCalledTimes ( 1 ) ;
29
+ } ) ;
30
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import * as React from 'react' ;
2
+ import { RadioGroupItem } from '../../../types' ;
3
+
4
+ export const FieldRadioGroup = ( {
5
+ label,
6
+ placeholder,
7
+ name,
8
+ options,
9
+ onChange,
10
+ value,
11
+ } : {
12
+ name : string ;
13
+ label : string ;
14
+ placeholder ?: string ;
15
+ options : RadioGroupItem [ ] ;
16
+ onChange : ( event : React . ChangeEvent < HTMLInputElement > ) => void ;
17
+ value : string ;
18
+ } ) => {
19
+ return (
20
+ < fieldset id = { name } className = "mb-1" >
21
+ < div >
22
+ < legend className = "mb-1 text-base font-medium dark:text-white" >
23
+ { label }
24
+ </ legend >
25
+ { placeholder && < p className = "text-sm text-gray-500" > { placeholder } </ p > }
26
+ </ div >
27
+
28
+ < div
29
+ className = "flex items-center space-x-4 py-2"
30
+ role = "group"
31
+ aria-labelledby = { name }
32
+ >
33
+ { options . map ( ( item ) => {
34
+ return (
35
+ < div
36
+ className = "flex items-center mt-1"
37
+ key = { `radio_item_${ item . value . toLowerCase ( ) } ` }
38
+ >
39
+ < input
40
+ type = "radio"
41
+ className = "focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300"
42
+ id = { `${ name } _${ item . value . toLowerCase ( ) } ` }
43
+ name = { name }
44
+ value = { item . value }
45
+ onChange = { onChange }
46
+ checked = { item . value === value }
47
+ />
48
+ < label
49
+ htmlFor = { `${ name } _${ item . value . toLowerCase ( ) } ` }
50
+ className = "ml-3 block text-sm font-medium text-gray-700 dark:text-white"
51
+ >
52
+ { item . label }
53
+ </ label >
54
+ </ div >
55
+ ) ;
56
+ } ) }
57
+ </ div >
58
+ </ fieldset >
59
+ ) ;
60
+ } ;
Original file line number Diff line number Diff line change @@ -5,23 +5,35 @@ interface IFieldCheckbox {
5
5
label : string ;
6
6
checked : boolean ;
7
7
onChange : any ;
8
+ placeholder ?: string ;
8
9
}
9
10
10
11
export const FieldCheckbox = ( props : IFieldCheckbox ) => {
11
12
return (
12
- < div className = "mt-1 mb-2 " >
13
- < label className = "inline- flex items-center mt-2 " >
13
+ < div className = "flex items-start mt-1 mb-3 " >
14
+ < div className = "flex items-center h-5 " >
14
15
< input
15
16
type = "checkbox"
16
- className = "h-5 w-5"
17
+ id = { props . name }
18
+ className = "focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded"
17
19
checked = { props . checked }
18
20
onChange = { props . onChange }
19
21
/>
22
+ </ div >
20
23
21
- < span className = "ml-4 text-gray-700 dark:text-white" >
24
+ < div className = "ml-3 text-sm" >
25
+ < label
26
+ htmlFor = { props . name }
27
+ className = "font-medium text-gray-700 dark:text-gray-200"
28
+ >
22
29
{ props . label }
23
- </ span >
24
- </ label >
30
+ </ label >
31
+ { props . placeholder && (
32
+ < p className = "text-gray-500 dark:text-gray-300" >
33
+ { props . placeholder }
34
+ </ p >
35
+ ) }
36
+ </ div >
25
37
</ div >
26
38
) ;
27
39
} ;
Original file line number Diff line number Diff line change 1
1
import { UPDATE_SETTING } from '../actions' ;
2
- import { restoreSetting , setAutoLaunch } from '../utils/comms' ;
2
+ import { setAppearance } from '../utils/appearance' ;
3
+ import { setAutoLaunch } from '../utils/comms' ;
3
4
4
5
export default ( ) => ( next ) => ( action ) => {
5
6
switch ( action . type ) {
6
7
case UPDATE_SETTING :
7
8
if ( action . setting === 'openAtStartup' ) {
8
9
setAutoLaunch ( action . value ) ;
9
10
}
11
+
12
+ if ( action . setting === 'appearance' ) {
13
+ setAppearance ( action . value ) ;
14
+ }
10
15
}
11
16
12
17
return next ( action ) ;
Original file line number Diff line number Diff line change 2
2
3
3
exports [` reducers/settings.ts should handle UPDATE_SETTING 1` ] = `
4
4
Object {
5
+ " appearance" : " SYSTEM" ,
5
6
" markOnClick" : false ,
6
7
" openAtStartup" : false ,
7
8
" participating" : true ,
@@ -12,6 +13,7 @@ Object {
12
13
13
14
exports [` reducers/settings.ts should handle UPDATE_SETTING 2` ] = `
14
15
Object {
16
+ " appearance" : " SYSTEM" ,
15
17
" markOnClick" : false ,
16
18
" openAtStartup" : true ,
17
19
" participating" : false ,
@@ -22,6 +24,7 @@ Object {
22
24
23
25
exports [` reducers/settings.ts should return the initial state 1` ] = `
24
26
Object {
27
+ " appearance" : " SYSTEM" ,
25
28
" markOnClick" : false ,
26
29
" openAtStartup" : false ,
27
30
" participating" : false ,
Original file line number Diff line number Diff line change 1
1
import { UPDATE_SETTING } from '../actions' ;
2
2
import { SettingsState } from '../../types/reducers' ;
3
+ import { Appearance } from '../../types' ;
3
4
4
5
const initialState : SettingsState = {
5
6
participating : false ,
6
7
playSound : true ,
7
8
showNotifications : true ,
8
9
markOnClick : false ,
9
10
openAtStartup : false ,
11
+ appearance : Appearance . SYSTEM ,
10
12
} ;
11
13
12
14
export default function reducer ( state = initialState , action ) : SettingsState {
You can’t perform that action at this time.
0 commit comments