Skip to content

Commit

Permalink
Complete tests coverage for the storage
Browse files Browse the repository at this point in the history
Signed-off-by: guido <[email protected]>
  • Loading branch information
widoz committed Dec 20, 2023
1 parent 7584b05 commit d738e47
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/js/unit/storage/initial-state.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, expect, it } from '@jest/globals';

import { makeInitialState } from '../../../../sources/js/src/storage/posts/initial-state';

describe('Initial state', () => {
it('ensure all options are empty', () => {
const initialState = makeInitialState();
expect(initialState.initialPostsOptions.size).toBe(0);
expect(initialState.postsOptions.size).toBe(0);
expect(initialState.cachedPostsOptions.size).toBe(0);
expect(initialState.selectedPostsOptions.size).toBe(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,65 @@ describe('reducer', () => {

expect(newState.selectedPostsOptions).toEqual(OrderedSet([]));
});

it('Does not set the initial posts options when the options are already set', () => {
state = {
...state,
initialPostsOptions: OrderedSet([
{
value: 1,
label: 'Option One',
},
{
value: 2,
label: 'Option Two',
},
]),
};

const newState = reducer(state, {
type: 'SET_INITIAL_POSTS_OPTIONS',
postsOptions: OrderedSet([
{
value: 3,
label: 'Option Three',
},
{
value: 4,
label: 'Option Four',
},
]),
});

expect(newState.initialPostsOptions).toEqual(state.initialPostsOptions);
});

it('When setting initial posts options it also cache them', () => {
const postsOptions = OrderedSet([
{
value: 3,
label: 'Option Three',
},
{
value: 4,
label: 'Option Four',
},
]);

const newState = reducer(state, {
type: 'SET_INITIAL_POSTS_OPTIONS',
postsOptions,
});

expect(newState.cachedPostsOptions).toEqual(postsOptions);
});

it('does nothing if the action type is not recognized', () => {
const newState = reducer(state, {
// @ts-ignore
type: 'NOT_RECOGNIZED_ACTION',
});

expect(newState).toEqual(state);
});
});

0 comments on commit d738e47

Please sign in to comment.