Skip to content

Commit 8d49e62

Browse files
committed
Update unit tests
1 parent b8c6ff8 commit 8d49e62

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

assets/src/components/site-scan-context-provider/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export function siteScanReducer( state, action ) {
116116
};
117117
}
118118
case ACTION_SCANNABLE_URLS_RECEIVE: {
119-
if ( ! action.scannableUrls || action.scannableUrls.length === 0 ) {
119+
if ( ! action.scannableUrls || action.scannableUrls?.length === 0 ) {
120120
return {
121121
...state,
122122
status: STATUS_COMPLETED,

assets/src/components/site-scan-context-provider/test/site-scan-reducer.js

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,33 @@ describe( 'siteScanReducer', () => {
9090
* ACTION_SCANNABLE_URLS_RECEIVE
9191
*/
9292
it( 'returns correct state for ACTION_SCANNABLE_URLS_RECEIVE', () => {
93-
expect( siteScanReducer( {}, {
93+
expect( siteScanReducer( { scanOnce: false, scansCount: 0 }, {
9494
type: ACTION_SCANNABLE_URLS_RECEIVE,
9595
scannableUrls: [],
9696
} ) ).toStrictEqual( {
9797
status: STATUS_COMPLETED,
98-
scannableUrls: [],
98+
scanOnce: false,
99+
scansCount: 0,
99100
} );
100101

101-
expect( siteScanReducer( {}, {
102+
expect( siteScanReducer( { scanOnce: false, scansCount: 2 }, {
102103
type: ACTION_SCANNABLE_URLS_RECEIVE,
103104
scannableUrls: [ 'foo', 'bar' ],
104105
} ) ).toStrictEqual( {
105106
status: STATUS_READY,
106107
scannableUrls: [ 'foo', 'bar' ],
108+
scanOnce: false,
109+
scansCount: 2,
110+
} );
111+
112+
expect( siteScanReducer( { scanOnce: true, scansCount: 1 }, {
113+
type: ACTION_SCANNABLE_URLS_RECEIVE,
114+
scannableUrls: [ 'foo', 'bar' ],
115+
} ) ).toStrictEqual( {
116+
status: STATUS_COMPLETED,
117+
scannableUrls: [ 'foo', 'bar' ],
118+
scanOnce: true,
119+
scansCount: 1,
107120
} );
108121
} );
109122

@@ -129,18 +142,45 @@ describe( 'siteScanReducer', () => {
129142
] )( 'returns correct state for ACTION_SCAN_INITIALIZE when initial status is %s', ( status ) => {
130143
expect( siteScanReducer( {
131144
status,
145+
scanOnce: false,
146+
scansCount: 0,
132147
scannableUrls: [ 'foo', 'bar' ],
133148
urlIndexesPendingScan: [],
134149
}, {
135150
type: ACTION_SCAN_INITIALIZE,
136151
} ) ).toStrictEqual( {
137152
status: STATUS_IDLE,
138153
currentlyScannedUrlIndexes: [],
154+
scanOnce: false,
155+
scansCount: 1,
139156
scannableUrls: [ 'foo', 'bar' ],
140157
urlIndexesPendingScan: [ 0, 1 ],
141158
} );
142159
} );
143160

161+
it.each( [
162+
STATUS_CANCELLED,
163+
STATUS_COMPLETED,
164+
STATUS_FAILED,
165+
STATUS_READY,
166+
] )( 'returns correct state for ACTION_SCAN_INITIALIZE when initial status is %s and scan should be done just once', ( status ) => {
167+
expect( siteScanReducer( {
168+
status,
169+
scanOnce: true,
170+
scansCount: 1,
171+
scannableUrls: [ 'foo', 'bar' ],
172+
urlIndexesPendingScan: [],
173+
}, {
174+
type: ACTION_SCAN_INITIALIZE,
175+
} ) ).toStrictEqual( {
176+
status: STATUS_COMPLETED,
177+
scanOnce: true,
178+
scansCount: 1,
179+
scannableUrls: [ 'foo', 'bar' ],
180+
urlIndexesPendingScan: [],
181+
} );
182+
} );
183+
144184
/**
145185
* ACTION_SCAN_URL
146186
*/

0 commit comments

Comments
 (0)