Skip to content

Commit d525a89

Browse files
committed
Update tests
1 parent 8d352b9 commit d525a89

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

ui/js/dfv/src/store/test/actions.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
SAVE_STATUSES,
3+
DUPLICATE_STATUSES,
34
DELETE_STATUSES,
45
UI_ACTIONS,
56
CURRENT_POD_ACTIONS,
@@ -11,6 +12,7 @@ import {
1112
setSaveStatus,
1213
setDeleteStatus,
1314
setGroupSaveStatus,
15+
setGroupDuplicateStatus,
1416
setGroupDeleteStatus,
1517
// @todo add Field tests:
1618
setFieldSaveStatus,
@@ -27,6 +29,7 @@ import {
2729
savePod,
2830
deletePod,
2931
saveGroup,
32+
duplicateGroup,
3033
deleteGroup,
3134

3235
// setGroupFields,
@@ -103,6 +106,24 @@ describe( 'actions', () => {
103106
expect( result ).toEqual( expected );
104107
} );
105108

109+
test( 'setGroupDuplicateStatus() creates a function to create an action to change the group\'s duplicate status', () => {
110+
const expected = {
111+
type: UI_ACTIONS.SET_GROUP_DUPLICATE_STATUS,
112+
saveStatus: DUPLICATE_STATUSES.DUPLICATE_SUCCESS,
113+
result: {
114+
message: 'Duplicated successfully.',
115+
},
116+
};
117+
118+
const result = setGroupDuplicateStatus(
119+
DUPLICATE_STATUSES.DUPLICATE_SUCCESS,
120+
)( {
121+
message: 'Duplicated successfully.',
122+
} );
123+
124+
expect( result ).toEqual( expected );
125+
} );
126+
106127
test( 'setGroupDeleteStatus() creates a function to create action to change the group\'s delete status', () => {
107128
const expected = {
108129
type: UI_ACTIONS.SET_GROUP_DELETE_STATUS,
@@ -322,6 +343,18 @@ describe( 'actions', () => {
322343
expect( result.payload.onStart().type ).toEqual( UI_ACTIONS.SET_GROUP_SAVE_STATUS );
323344
} );
324345

346+
test( 'duplicateGroup() returns an action to duplicate a pod by its ID', () => {
347+
const action = CURRENT_POD_ACTIONS.API_REQUEST;
348+
349+
const result = duplicateGroup( 123 );
350+
351+
expect( result.type ).toEqual( action );
352+
expect( result.payload.onSuccess[ 0 ]().type ).toEqual( UI_ACTIONS.SET_GROUP_DUPLICATE_STATUS );
353+
expect( result.payload.onSuccess[ 1 ]().type ).toEqual( CURRENT_POD_ACTIONS.DUPLICATE_GROUP );
354+
expect( result.payload.onFailure().type ).toEqual( UI_ACTIONS.SET_GROUP_DUPLICATE_STATUS );
355+
expect( result.payload.onStart().type ).toEqual( UI_ACTIONS.SET_GROUP_DUPLICATE_STATUS );
356+
} );
357+
325358
test( 'deleteGroup() returns an action to delete a group by its ID', () => {
326359
const action = CURRENT_POD_ACTIONS.API_REQUEST;
327360

ui/js/dfv/src/store/test/reducer.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as paths from '../state-paths';
44

55
import {
66
SAVE_STATUSES,
7+
DUPLICATE_STATUSES,
78
DELETE_STATUSES,
89
CURRENT_POD_ACTIONS,
910
UI_ACTIONS,
@@ -59,15 +60,30 @@ describe( 'UI reducer', () => {
5960
expect( newState.saveMessage ).toEqual( 'Saving...' );
6061
} );
6162

62-
it( 'uses the default for an unknown save status', () => {
63+
it( 'changes the duplicate status', () => {
6364
const action = {
64-
type: UI_ACTIONS.SET_SAVE_STATUS,
65-
saveStatus: 'xyzzy',
65+
type: UI_ACTIONS.SET_DUPLICATE_STATUS,
66+
duplicateStatus: DUPLICATE_STATUSES.DUPLICATING,
67+
result: {
68+
message: 'Duplicating...',
69+
},
70+
};
71+
72+
const newState = ui( state, action );
73+
74+
expect( newState.duplicateStatus ).toEqual( action.duplicateStatus );
75+
expect( newState.duplicateMessage ).toEqual( 'Duplicating...' );
76+
} );
77+
78+
it( 'uses the default for an unknown duplicate status', () => {
79+
const action = {
80+
type: UI_ACTIONS.SET_DUPLICATE_STATUS,
81+
duplicateStatus: 'xyzzy',
6682
};
6783

6884
const newState = ui( state, action );
6985

70-
expect( newState.saveStatus ).toEqual( INITIAL_UI_STATE.saveStatus );
86+
expect( newState.duplicateStatus ).toEqual( INITIAL_UI_STATE.duplicateStatus );
7187
} );
7288

7389
it( 'changes the delete status', () => {

0 commit comments

Comments
 (0)