ViewStore.jest.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. import { ViewStore } from './ViewStore';
  2. import { toJS } from 'mobx';
  3. describe('ViewStore', () => {
  4. let store;
  5. beforeAll(() => {
  6. store = ViewStore.create({
  7. path: '',
  8. query: {},
  9. routeParams: {},
  10. });
  11. });
  12. it('Can update path and query', () => {
  13. store.updatePathAndQuery('/hello', { key: 1, otherParam: 'asd' }, { key: 1, otherParam: 'asd' });
  14. expect(store.path).toBe('/hello');
  15. expect(store.query.get('key')).toBe(1);
  16. expect(store.currentUrl).toBe('/hello?key=1&otherParam=asd');
  17. });
  18. it('Query can contain arrays', () => {
  19. store.updatePathAndQuery('/hello', { values: ['A', 'B'] }, { key: 1, otherParam: 'asd' });
  20. expect(toJS(store.query.get('values'))).toMatchObject(['A', 'B']);
  21. expect(store.currentUrl).toBe('/hello?values=A&values=B');
  22. });
  23. it('Query can contain boolean', () => {
  24. store.updatePathAndQuery('/hello', { abool: true }, { abool: true });
  25. expect(toJS(store.query.get('abool'))).toBe(true);
  26. expect(store.currentUrl).toBe('/hello?abool');
  27. });
  28. });