dashfolders: fix tests for ViewStore after merge

pull/10719/head
Daniel Lee 8 years ago
parent 49634593cf
commit 08c78ab8b7
  1. 6
      public/app/stores/NavStore/NavItem.ts
  2. 5
      public/app/stores/ViewStore/ViewStore.jest.ts
  3. 2
      public/app/stores/ViewStore/ViewStore.ts

@ -1,10 +1,5 @@
import { types } from 'mobx-state-tree'; import { types } from 'mobx-state-tree';
const BreadcrumbItem = types.model('BreadcrumbItem', {
title: types.string,
url: types.string,
});
export const NavItem = types.model('NavItem', { export const NavItem = types.model('NavItem', {
id: types.identifier(types.string), id: types.identifier(types.string),
text: types.string, text: types.string,
@ -15,7 +10,6 @@ export const NavItem = types.model('NavItem', {
active: types.optional(types.boolean, false), active: types.optional(types.boolean, false),
breadcrumbs: types.optional(types.array(types.late(() => Breadcrumb)), []), breadcrumbs: types.optional(types.array(types.late(() => Breadcrumb)), []),
children: types.optional(types.array(types.late(() => NavItem)), []), children: types.optional(types.array(types.late(() => NavItem)), []),
breadcrumbs: types.optional(types.array(BreadcrumbItem), []),
}); });
export const Breadcrumb = types.model('Breadcrumb', { export const Breadcrumb = types.model('Breadcrumb', {

@ -8,18 +8,19 @@ describe('ViewStore', () => {
store = ViewStore.create({ store = ViewStore.create({
path: '', path: '',
query: {}, query: {},
routeParams: {},
}); });
}); });
it('Can update path and query', () => { 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.path).toBe('/hello');
expect(store.query.get('key')).toBe(1); expect(store.query.get('key')).toBe(1);
expect(store.currentUrl).toBe('/hello?key=1&otherParam=asd'); expect(store.currentUrl).toBe('/hello?key=1&otherParam=asd');
}); });
it('Query can contain arrays', () => { 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(toJS(store.query.get('values'))).toMatchObject(['A', 'B']);
expect(store.currentUrl).toBe('/hello?values=A&values=B'); expect(store.currentUrl).toBe('/hello?values=A&values=B');
}); });

@ -22,6 +22,7 @@ export const ViewStore = types
}, },
})) }))
.actions(self => { .actions(self => {
// querystring only
function updateQuery(query: any) { function updateQuery(query: any) {
self.query.clear(); self.query.clear();
for (let key of Object.keys(query)) { 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) { function updateRouteParams(routeParams: any) {
self.routeParams.clear(); self.routeParams.clear();
for (let key of Object.keys(routeParams)) { for (let key of Object.keys(routeParams)) {

Loading…
Cancel
Save