@@ -68,8 +68,9 @@ describe("ScriptsList", () => {
68
68
} ) ;
69
69
} ) ;
70
70
71
- it ( "dispatches action to fetch scripts load " , ( ) => {
71
+ it ( "fetches scripts if they haven't been loaded yet " , ( ) => {
72
72
const state = { ...initialState } ;
73
+ state . scripts . loaded = false ;
73
74
const store = mockStore ( state ) ;
74
75
75
76
mount (
@@ -80,11 +81,27 @@ describe("ScriptsList", () => {
80
81
</ Provider >
81
82
) ;
82
83
83
- expect ( store . getActions ( ) ) . toEqual ( [
84
- {
85
- type : "FETCH_SCRIPTS" ,
86
- } ,
87
- ] ) ;
84
+ expect (
85
+ store . getActions ( ) . some ( ( action ) => action . type === "FETCH_SCRIPTS" )
86
+ ) . toBe ( true ) ;
87
+ } ) ;
88
+
89
+ it ( "does not fetch scripts if they've already been loaded" , ( ) => {
90
+ const state = { ...initialState } ;
91
+ state . scripts . loaded = true ;
92
+ const store = mockStore ( state ) ;
93
+
94
+ mount (
95
+ < Provider store = { store } >
96
+ < MemoryRouter initialEntries = { [ { pathname : "/" } ] } >
97
+ < ScriptsList />
98
+ </ MemoryRouter >
99
+ </ Provider >
100
+ ) ;
101
+
102
+ expect (
103
+ store . getActions ( ) . some ( ( action ) => action . type === "FETCH_SCRIPTS" )
104
+ ) . toBe ( false ) ;
88
105
} ) ;
89
106
90
107
it ( "Displays commissioning scripts by default" , ( ) => {
@@ -194,7 +211,9 @@ describe("ScriptsList", () => {
194
211
wrapper . find ( "TableRow" ) . at ( 1 ) . find ( "Button" ) . at ( 1 ) . simulate ( "click" ) ;
195
212
// Click on the delete confirm button
196
213
wrapper . find ( "TableRow" ) . at ( 1 ) . find ( "Button" ) . at ( 3 ) . simulate ( "click" ) ;
197
- expect ( store . getActions ( ) [ 1 ] ) . toEqual ( {
214
+ expect (
215
+ store . getActions ( ) . find ( ( action ) => action . type === "DELETE_SCRIPT" )
216
+ ) . toEqual ( {
198
217
type : "DELETE_SCRIPT" ,
199
218
payload : {
200
219
id : 1 ,
0 commit comments