test: add tests for getChildrenNavigationCache

This commit is contained in:
otrepanier
2020-10-28 14:16:25 -07:00
committed by Satyajit Sahoo
parent 8d0e0f48ad
commit 09d4bc24e9

View File

@@ -0,0 +1,60 @@
import getChildrenNavigationCache from '../getChildrenNavigationCache';
it('should return empty table if navigation arg not provided', () => {
expect(getChildrenNavigationCache()._childrenNavigation).toBeUndefined();
});
it('should populate navigation._childrenNavigation as a side-effect', () => {
const navigation = {
state: {
routes: [{ key: 'one' }],
},
};
const result = getChildrenNavigationCache(navigation);
expect(result).toBeDefined();
expect(navigation._childrenNavigation).toBe(result);
});
it('should delete children cache keys that are no longer valid', () => {
const navigation = {
state: {
routes: [{ key: 'one' }, { key: 'two' }, { key: 'three' }],
},
_childrenNavigation: {
one: {},
two: {},
three: {},
four: {},
},
};
const result = getChildrenNavigationCache(navigation);
expect(result).toEqual({
one: {},
two: {},
three: {},
});
});
it('should not delete children cache keys if in transitioning state', () => {
const navigation = {
state: {
routes: [{ key: 'one' }, { key: 'two' }, { key: 'three' }],
isTransitioning: true,
},
_childrenNavigation: {
one: {},
two: {},
three: {},
four: {},
},
};
const result = getChildrenNavigationCache(navigation);
expect(result).toEqual({
one: {},
two: {},
three: {},
four: {},
});
});