-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
monteri
committed
Apr 4, 2024
1 parent
0f0ac38
commit 1682aac
Showing
2 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
reducer, | ||
fetchGroupConfigurations, | ||
updateGroupConfigurationsSuccess, | ||
deleteGroupConfigurationsSuccess, | ||
updateExperimentConfigurationSuccess, | ||
deleteExperimentConfigurationSuccess, | ||
} from './slice'; | ||
import { RequestStatus } from '../../data/constants'; | ||
|
||
describe('groupConfigurations slice', () => { | ||
let initialState; | ||
|
||
beforeEach(() => { | ||
initialState = { | ||
savingStatus: '', | ||
loadingStatus: RequestStatus.IN_PROGRESS, | ||
groupConfigurations: { | ||
allGroupConfigurations: [{ id: 1, name: 'Group 1', groups: [{ id: 1, name: 'inner group' }] }], | ||
experimentGroupConfigurations: [], | ||
}, | ||
}; | ||
}); | ||
|
||
it('should update group configurations with fetchGroupConfigurations', () => { | ||
const payload = { | ||
groupConfigurations: { | ||
allGroupConfigurations: [{ id: 2, name: 'Group 2' }], | ||
experimentGroupConfigurations: [], | ||
}, | ||
}; | ||
|
||
const newState = reducer(initialState, fetchGroupConfigurations(payload)); | ||
|
||
expect(newState.groupConfigurations).toEqual(payload.groupConfigurations); | ||
}); | ||
|
||
it('should update an existing group configuration with updateGroupConfigurationsSuccess', () => { | ||
const payload = { data: { id: 1, name: 'Updated Group' } }; | ||
|
||
const newState = reducer(initialState, updateGroupConfigurationsSuccess(payload)); | ||
|
||
expect(newState.groupConfigurations.allGroupConfigurations[0]).toEqual(payload.data); | ||
}); | ||
|
||
it('should delete a group configuration with deleteGroupConfigurationsSuccess', () => { | ||
const payload = { parentGroupId: 1, groupId: 1 }; | ||
|
||
const newState = reducer(initialState, deleteGroupConfigurationsSuccess(payload)); | ||
|
||
expect(newState.groupConfigurations.allGroupConfigurations[0].groups.length).toEqual(0); | ||
}); | ||
|
||
it('should update experiment configuration with updateExperimentConfigurationSuccess', () => { | ||
const payload = { configuration: { id: 1, name: 'Experiment Config' } }; | ||
|
||
const newState = reducer(initialState, updateExperimentConfigurationSuccess(payload)); | ||
|
||
expect(newState.groupConfigurations.experimentGroupConfigurations.length).toEqual(1); | ||
expect(newState.groupConfigurations.experimentGroupConfigurations[0]).toEqual(payload.configuration); | ||
}); | ||
|
||
it('should delete an experiment configuration with deleteExperimentConfigurationSuccess', () => { | ||
const initialStateWithExperiment = { | ||
savingStatus: '', | ||
loadingStatus: RequestStatus.IN_PROGRESS, | ||
groupConfigurations: { | ||
allGroupConfigurations: [], | ||
experimentGroupConfigurations: [{ id: 1, name: 'Experiment Config' }], | ||
}, | ||
}; | ||
const payload = { configurationId: 1 }; | ||
|
||
const newState = reducer(initialStateWithExperiment, deleteExperimentConfigurationSuccess(payload)); | ||
|
||
expect(newState.groupConfigurations.experimentGroupConfigurations.length).toEqual(0); | ||
}); | ||
}); |