@@ -2,9 +2,9 @@ import { fromJS } from "immutable";
2
2
3
3
import { mountedComponent , screen , stub } from "../../../../test-utils" ;
4
4
import { ACTIONS } from "../../../permissions" ;
5
+ import { lookups } from "../../../../test" ;
5
6
6
7
import RolesList from "./container" ;
7
- import { lookups } from "../../../../test" ;
8
8
9
9
describe ( "<RolesList />" , ( ) => {
10
10
const dataLength = 30 ;
@@ -15,7 +15,49 @@ describe("<RolesList />", () => {
15
15
description : `Test description ${ i + 1 } `
16
16
} ) ) ;
17
17
18
- const initialState = fromJS ( {
18
+ const initialState = fromJS ( {
19
+ records : {
20
+ admin : {
21
+ roles : {
22
+ data,
23
+ metadata : { total : dataLength , per : 20 , page : 1 } ,
24
+ loading : false ,
25
+ errors : false
26
+ }
27
+ }
28
+ } ,
29
+ user : {
30
+ permissions : {
31
+ roles : [ ACTIONS . MANAGE ]
32
+ }
33
+ } ,
34
+ forms : {
35
+ options : {
36
+ lookups : lookups ( )
37
+ }
38
+ }
39
+ } ) ;
40
+
41
+
42
+ stub ( window . I18n , "t" ) . withArgs ( "messages.record_list.of" ) . returns ( "of" ) . withArgs ( "buttons.new" ) . returns ( "New" ) ;
43
+
44
+ it ( "renders record list table" , ( ) => {
45
+ mountedComponent ( < RolesList /> , initialState , [ "/admin/roles" ] ) ;
46
+ expect ( screen . getByRole ( "grid" ) ) . toBeInTheDocument ( ) ;
47
+ } ) ;
48
+
49
+ it ( "should trigger a valid action with next page when clicking next page" , ( ) => {
50
+ mountedComponent ( < RolesList /> , initialState , [ "/admin/roles" ] ) ;
51
+ expect ( screen . getByText ( `1-20 of ${ dataLength } ` ) ) . toBeInTheDocument ( ) ;
52
+ } ) ;
53
+
54
+ it ( "should render new button" , ( ) => {
55
+ mountedComponent ( < RolesList /> , initialState , [ "/admin/roles" ] ) ;
56
+ expect ( screen . getByText ( `New` ) ) . toBeInTheDocument ( ) ;
57
+ } ) ;
58
+
59
+ describe ( "when user can't create role" , ( ) => {
60
+ const initialStateCreateRole = fromJS ( {
19
61
records : {
20
62
admin : {
21
63
roles : {
@@ -28,7 +70,7 @@ describe("<RolesList />", () => {
28
70
} ,
29
71
user : {
30
72
permissions : {
31
- roles : [ ACTIONS . MANAGE ]
73
+ roles : [ ACTIONS . READ ]
32
74
}
33
75
} ,
34
76
forms : {
@@ -38,54 +80,9 @@ describe("<RolesList />", () => {
38
80
}
39
81
} ) ;
40
82
41
- stubI18n = stub ( window . I18n , "t" )
42
- . withArgs ( "messages.record_list.of" )
43
- . returns ( "of" )
44
- . withArgs ( "buttons.new" )
45
- . returns ( "New" ) ;
46
-
47
- it ( "renders record list table" , ( ) => {
48
- mountedComponent ( < RolesList /> , initialState , [ "/admin/roles" ] )
49
- expect ( screen . getByRole ( 'grid' ) ) . toBeInTheDocument ( ) ;
50
- } ) ;
51
-
52
- it ( "should trigger a valid action with next page when clicking next page" , ( ) => {
53
- mountedComponent ( < RolesList /> , initialState , [ "/admin/roles" ] )
54
- expect ( screen . getByText ( `1-20 of ${ dataLength } ` ) ) . toBeInTheDocument ( ) ;
55
- } ) ;
56
-
57
- it ( "should render new button" , ( ) => {
58
- mountedComponent ( < RolesList /> , initialState , [ "/admin/roles" ] )
59
- expect ( screen . getByText ( `New` ) ) . toBeInTheDocument ( ) ;
60
- } ) ;
61
-
62
- describe ( "when user can't create role" , ( ) => {
63
- const initialState = fromJS ( {
64
- records : {
65
- admin : {
66
- roles : {
67
- data,
68
- metadata : { total : dataLength , per : 20 , page : 1 } ,
69
- loading : false ,
70
- errors : false
71
- }
72
- }
73
- } ,
74
- user : {
75
- permissions : {
76
- roles : [ ACTIONS . READ ]
77
- }
78
- } ,
79
- forms : {
80
- options : {
81
- lookups : lookups ( )
82
- }
83
- }
84
- } ) ;
85
-
86
83
it ( "should not render new button" , ( ) => {
87
- mountedComponent ( < RolesList /> , initialState , [ "/admin/roles" ] )
88
- expect ( screen . queryByText ( / N e w / ) ) . not . toBeInTheDocument ( ) ;
84
+ mountedComponent ( < RolesList /> , initialStateCreateRole , [ "/admin/roles" ] ) ;
85
+ expect ( screen . queryByText ( / N e w / ) ) . not . toBeInTheDocument ( ) ;
89
86
} ) ;
90
87
} ) ;
91
88
} ) ;
0 commit comments