Commit 08c78ab8 by Daniel Lee

dashfolders: fix tests for ViewStore after merge

parent 49634593
import { types } from 'mobx-state-tree';
const BreadcrumbItem = types.model('BreadcrumbItem', {
title: types.string,
url: types.string,
});
export const NavItem = types.model('NavItem', {
id: types.identifier(types.string),
text: types.string,
......@@ -15,7 +10,6 @@ export const NavItem = types.model('NavItem', {
active: types.optional(types.boolean, false),
breadcrumbs: types.optional(types.array(types.late(() => Breadcrumb)), []),
children: types.optional(types.array(types.late(() => NavItem)), []),
breadcrumbs: types.optional(types.array(BreadcrumbItem), []),
});
export const Breadcrumb = types.model('Breadcrumb', {
......
......@@ -8,18 +8,19 @@ describe('ViewStore', () => {
store = ViewStore.create({
path: '',
query: {},
routeParams: {},
});
});
it('Can update path and query', () => {
store.updatePathAndQuery('/hello', { key: 1, otherParam: 'asd' });
store.updatePathAndQuery('/hello', { key: 1, otherParam: 'asd' }, { key: 1, otherParam: 'asd' });
expect(store.path).toBe('/hello');
expect(store.query.get('key')).toBe(1);
expect(store.currentUrl).toBe('/hello?key=1&otherParam=asd');
});
it('Query can contain arrays', () => {
store.updatePathAndQuery('/hello', { values: ['A', 'B'] });
store.updatePathAndQuery('/hello', { values: ['A', 'B'] }, { key: 1, otherParam: 'asd' });
expect(toJS(store.query.get('values'))).toMatchObject(['A', 'B']);
expect(store.currentUrl).toBe('/hello?values=A&values=B');
});
......
......@@ -22,6 +22,7 @@ export const ViewStore = types
},
}))
.actions(self => {
// querystring only
function updateQuery(query: any) {
self.query.clear();
for (let key of Object.keys(query)) {
......@@ -29,6 +30,7 @@ export const ViewStore = types
}
}
// needed to get route parameters like slug from the url
function updateRouteParams(routeParams: any) {
self.routeParams.clear();
for (let key of Object.keys(routeParams)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment