1
- import { mount } from '@hypothesis/frontend-testing' ;
1
+ import { checkAccessibility , mount } from '@hypothesis/frontend-testing' ;
2
2
import { useContext } from 'preact/hooks' ;
3
3
4
4
import { $imports , default as AppRoot } from '../AppRoot' ;
@@ -31,9 +31,13 @@ describe('AppRoot', () => {
31
31
$imports . $restore ( ) ;
32
32
} ) ;
33
33
34
+ function createComponent ( ) {
35
+ return mount ( < AppRoot config = { config } /> ) ;
36
+ }
37
+
34
38
it ( 'renders style links' , ( ) => {
35
39
config . styles = [ '/static/styles/foo.css' ] ;
36
- const links = mount ( < AppRoot config = { config } /> ) . find ( 'link' ) ;
40
+ const links = createComponent ( ) . find ( 'link' ) ;
37
41
assert . equal ( links . length , 1 ) ;
38
42
assert . equal ( links . at ( 0 ) . prop ( 'rel' ) , 'stylesheet' ) ;
39
43
assert . equal ( links . at ( 0 ) . prop ( 'href' ) , '/static/styles/foo.css' ) ;
@@ -51,14 +55,14 @@ describe('AppRoot', () => {
51
55
52
56
it ( 'passes config to route' , ( ) => {
53
57
navigate ( '/groups/new' , ( ) => {
54
- mount ( < AppRoot config = { config } /> ) ;
58
+ createComponent ( ) ;
55
59
assert . strictEqual ( configContext , config ) ;
56
60
} ) ;
57
61
} ) ;
58
62
59
63
it ( 'passes saved group to group settings route' , ( ) => {
60
64
navigate ( '/groups/1234/edit' , ( ) => {
61
- const wrapper = mount ( < AppRoot config = { config } /> ) ;
65
+ const wrapper = createComponent ( ) ;
62
66
assert . equal (
63
67
wrapper . find ( 'CreateEditGroupForm' ) . prop ( 'group' ) ,
64
68
config . context . group ,
@@ -68,7 +72,7 @@ describe('AppRoot', () => {
68
72
69
73
it ( 'passes updated group to group settings route' , ( ) => {
70
74
navigate ( '/groups/1234/edit' , ( ) => {
71
- const wrapper = mount ( < AppRoot config = { config } /> ) ;
75
+ const wrapper = createComponent ( ) ;
72
76
const updatedGroup = { name : 'foobar' } ;
73
77
wrapper . find ( 'CreateEditGroupForm' ) . prop ( 'onUpdateGroup' ) ( updatedGroup ) ;
74
78
wrapper . update ( ) ;
@@ -99,10 +103,15 @@ describe('AppRoot', () => {
99
103
] . forEach ( ( { path, selector } ) => {
100
104
it ( `renders expected component for URL (${ path } )` , ( ) => {
101
105
navigate ( path , ( ) => {
102
- const wrapper = mount ( < AppRoot config = { config } /> ) ;
106
+ const wrapper = createComponent ( ) ;
103
107
const component = wrapper . find ( selector ) ;
104
108
assert . isTrue ( component . exists ( ) ) ;
105
109
} ) ;
106
110
} ) ;
107
111
} ) ;
112
+
113
+ it (
114
+ 'should pass a11y checks' ,
115
+ checkAccessibility ( { content : createComponent } ) ,
116
+ ) ;
108
117
} ) ;
0 commit comments