Skip to content

Commit

Permalink
Add a checkSelection selector module and expose a getHostCheckSelecti…
Browse files Browse the repository at this point in the history
…on selector
  • Loading branch information
nelsonkopliku committed Jul 17, 2023
1 parent 63a70de commit f141d5f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions assets/js/state/selectors/checksSelection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { TARGET_HOST } from '@lib/model';

export const getHostCheckSelection =
(hostID) =>
({ checksSelection }) =>
checksSelection?.[TARGET_HOST][hostID] || {};
32 changes: 32 additions & 0 deletions assets/js/state/selectors/checksSelection.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { faker } from '@faker-js/faker';
import { getHostCheckSelection } from './checksSelection';

describe('Checks Selection selector', () => {
it(`should get a host's check selection state`, () => {
const hostID = faker.datatype.uuid();
expect(
getHostCheckSelection(hostID)({
checksSelection: {
host: {
[faker.datatype.uuid()]: { status: 'successfully_saved' },
[hostID]: { status: 'saving' },
},
},
})
).toEqual({ status: 'saving' });
});

it(`should not get a host's check selection state if not present`, () => {
const hostWithoutSelection = faker.datatype.uuid();
expect(
getHostCheckSelection(hostWithoutSelection)({
checksSelection: {
host: {
[faker.datatype.uuid()]: { status: 'successfully_saved' },
[faker.datatype.uuid()]: { status: 'saving' },
},
},
})
).toEqual({});
});
});

0 comments on commit f141d5f

Please sign in to comment.