vendor: amis 6.13.0 base (fork root)
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`store:index 1`] = `
|
||||
{
|
||||
"storeType": "RendererStore",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`store:index 2`] = `
|
||||
{
|
||||
"storeType": "RendererStore",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`store:index 3`] = `
|
||||
{
|
||||
"storeType": "RendererStore",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`store:index 4`] = `
|
||||
{
|
||||
"storeType": "RendererStore",
|
||||
}
|
||||
`;
|
||||
@@ -0,0 +1,173 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`store:ServiceStore 1`] = `
|
||||
{
|
||||
"action": undefined,
|
||||
"busying": false,
|
||||
"checking": false,
|
||||
"childrenIds": [],
|
||||
"data": {},
|
||||
"dialogData": undefined,
|
||||
"dialogOpen": false,
|
||||
"dialogSchema": undefined,
|
||||
"disposed": false,
|
||||
"drawerData": undefined,
|
||||
"drawerOpen": false,
|
||||
"drawerSchema": undefined,
|
||||
"error": false,
|
||||
"fetching": false,
|
||||
"hasRemoteData": false,
|
||||
"id": "1",
|
||||
"initedAt": 0,
|
||||
"initializing": false,
|
||||
"msg": "",
|
||||
"parentId": "",
|
||||
"path": "",
|
||||
"pristine": {},
|
||||
"pristineRaw": {},
|
||||
"saving": false,
|
||||
"schema": null,
|
||||
"schemaKey": "",
|
||||
"storeType": "ServiceStore",
|
||||
"upStreamData": {},
|
||||
"updatedAt": 0,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`store:ServiceStore fetchInitData failed 1`] = `
|
||||
[
|
||||
{
|
||||
"action": undefined,
|
||||
"busying": false,
|
||||
"checking": false,
|
||||
"childrenIds": [],
|
||||
"data": {},
|
||||
"dialogData": undefined,
|
||||
"dialogOpen": false,
|
||||
"dialogSchema": undefined,
|
||||
"disposed": false,
|
||||
"drawerData": undefined,
|
||||
"drawerOpen": false,
|
||||
"drawerSchema": undefined,
|
||||
"error": false,
|
||||
"fetching": true,
|
||||
"hasRemoteData": false,
|
||||
"id": "1",
|
||||
"initedAt": 0,
|
||||
"initializing": false,
|
||||
"msg": "",
|
||||
"parentId": "",
|
||||
"path": "",
|
||||
"pristine": {},
|
||||
"pristineRaw": {},
|
||||
"saving": false,
|
||||
"schema": null,
|
||||
"schemaKey": "",
|
||||
"storeType": "ServiceStore",
|
||||
"upStreamData": {},
|
||||
"updatedAt": 0,
|
||||
},
|
||||
{
|
||||
"action": undefined,
|
||||
"busying": false,
|
||||
"checking": false,
|
||||
"childrenIds": [],
|
||||
"data": {},
|
||||
"dialogData": undefined,
|
||||
"dialogOpen": false,
|
||||
"dialogSchema": undefined,
|
||||
"disposed": false,
|
||||
"drawerData": undefined,
|
||||
"drawerOpen": false,
|
||||
"drawerSchema": undefined,
|
||||
"error": false,
|
||||
"fetching": false,
|
||||
"hasRemoteData": false,
|
||||
"id": "1",
|
||||
"initedAt": 0,
|
||||
"initializing": false,
|
||||
"msg": "",
|
||||
"parentId": "",
|
||||
"path": "",
|
||||
"pristine": {},
|
||||
"pristineRaw": {},
|
||||
"saving": false,
|
||||
"schema": null,
|
||||
"schemaKey": "",
|
||||
"storeType": "ServiceStore",
|
||||
"upStreamData": {},
|
||||
"updatedAt": 0,
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`store:ServiceStore fetchInitData success 1`] = `
|
||||
[
|
||||
{
|
||||
"action": undefined,
|
||||
"busying": false,
|
||||
"checking": false,
|
||||
"childrenIds": [],
|
||||
"data": {},
|
||||
"dialogData": undefined,
|
||||
"dialogOpen": false,
|
||||
"dialogSchema": undefined,
|
||||
"disposed": false,
|
||||
"drawerData": undefined,
|
||||
"drawerOpen": false,
|
||||
"drawerSchema": undefined,
|
||||
"error": false,
|
||||
"fetching": true,
|
||||
"hasRemoteData": false,
|
||||
"id": "1",
|
||||
"initedAt": 0,
|
||||
"initializing": false,
|
||||
"msg": "",
|
||||
"parentId": "",
|
||||
"path": "",
|
||||
"pristine": {},
|
||||
"pristineRaw": {},
|
||||
"saving": false,
|
||||
"schema": null,
|
||||
"schemaKey": "",
|
||||
"storeType": "ServiceStore",
|
||||
"upStreamData": {},
|
||||
},
|
||||
{
|
||||
"action": undefined,
|
||||
"busying": false,
|
||||
"checking": false,
|
||||
"childrenIds": [],
|
||||
"data": {
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
},
|
||||
"dialogData": undefined,
|
||||
"dialogOpen": false,
|
||||
"dialogSchema": undefined,
|
||||
"disposed": false,
|
||||
"drawerData": undefined,
|
||||
"drawerOpen": false,
|
||||
"drawerSchema": undefined,
|
||||
"error": false,
|
||||
"fetching": false,
|
||||
"hasRemoteData": true,
|
||||
"id": "1",
|
||||
"initedAt": 0,
|
||||
"initializing": false,
|
||||
"msg": "",
|
||||
"parentId": "",
|
||||
"path": "",
|
||||
"pristine": {
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
},
|
||||
"pristineRaw": {},
|
||||
"saving": false,
|
||||
"schema": null,
|
||||
"schemaKey": "",
|
||||
"storeType": "ServiceStore",
|
||||
"upStreamData": {},
|
||||
},
|
||||
]
|
||||
`;
|
||||
53
packages/amis/__tests__/stores/index.test.ts
Normal file
53
packages/amis/__tests__/stores/index.test.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import {RendererStore} from '../../src';
|
||||
import {getSnapshot, getEnv} from 'mobx-state-tree';
|
||||
import {ServiceStore} from '../../src';
|
||||
|
||||
test('store:index', () => {
|
||||
const store = RendererStore.create({});
|
||||
|
||||
expect(getSnapshot(store)).toMatchSnapshot();
|
||||
|
||||
const serviceStore = ServiceStore.create({
|
||||
path: '/xxx',
|
||||
storeType: ServiceStore.name,
|
||||
id: '1'
|
||||
});
|
||||
store.addStore(serviceStore);
|
||||
|
||||
expect(getSnapshot(store)).toMatchSnapshot();
|
||||
|
||||
const serviceStore2 = ServiceStore.create({
|
||||
path: '/yyy',
|
||||
storeType: ServiceStore.name,
|
||||
id: '2',
|
||||
parentId: '1'
|
||||
});
|
||||
|
||||
store.addStore(serviceStore2);
|
||||
|
||||
expect(getSnapshot(store)).toMatchSnapshot();
|
||||
|
||||
expect(serviceStore2.parentStore).toEqual(serviceStore);
|
||||
|
||||
store.removeStore(serviceStore2);
|
||||
expect(getSnapshot(store)).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('store:index env', () => {
|
||||
const fetcher = jest.fn();
|
||||
const notify = jest.fn();
|
||||
const isCancel = jest.fn(() => false);
|
||||
|
||||
const store = RendererStore.create(
|
||||
{},
|
||||
{
|
||||
fetcher,
|
||||
notify,
|
||||
isCancel
|
||||
}
|
||||
);
|
||||
|
||||
expect(store.fetcher).toBe(fetcher);
|
||||
expect(store.notify).toBe(notify);
|
||||
expect(store.isCancel).toBe(isCancel);
|
||||
});
|
||||
95
packages/amis/__tests__/stores/service.test.ts
Normal file
95
packages/amis/__tests__/stores/service.test.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
import {getSnapshot, getEnv, onSnapshot} from 'mobx-state-tree';
|
||||
import {StoreNode} from '../../src';
|
||||
import {ServiceStore} from '../../src';
|
||||
import {RendererStore} from '../../src';
|
||||
import omit = require('lodash/omit');
|
||||
|
||||
test('store:ServiceStore', () => {
|
||||
const store = ServiceStore.create({
|
||||
id: '1',
|
||||
storeType: ServiceStore.name
|
||||
});
|
||||
|
||||
expect(getSnapshot(store)).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('store:ServiceStore fetchInitData success', async () => {
|
||||
const fetcher = jest.fn().mockImplementationOnce(() =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
data: {
|
||||
a: 1,
|
||||
b: 2
|
||||
}
|
||||
})
|
||||
);
|
||||
const isCancel = jest.fn(() => false);
|
||||
const mainStore = RendererStore.create(
|
||||
{},
|
||||
{
|
||||
fetcher,
|
||||
isCancel
|
||||
}
|
||||
);
|
||||
const states: Array<any> = [];
|
||||
|
||||
const store = ServiceStore.create(
|
||||
{
|
||||
id: '1',
|
||||
storeType: ServiceStore.name
|
||||
},
|
||||
{
|
||||
fetcher,
|
||||
isCancel
|
||||
}
|
||||
);
|
||||
mainStore.addStore(store);
|
||||
|
||||
onSnapshot(store, snapshot => states.push(snapshot));
|
||||
|
||||
await store.fetchInitData('/api/xxx');
|
||||
|
||||
const ignoreUdatedAt = states.map(snapshot => omit(snapshot, ['updatedAt']));
|
||||
expect(ignoreUdatedAt).toMatchSnapshot();
|
||||
|
||||
expect(states.length).toBe(2);
|
||||
expect(states[1].updatedAt).not.toEqual(states[0].updatedAt);
|
||||
});
|
||||
|
||||
test('store:ServiceStore fetchInitData failed', async () => {
|
||||
const fetcher = jest
|
||||
.fn()
|
||||
.mockImplementationOnce(() => Promise.reject('Network Error'));
|
||||
const notify = jest.fn();
|
||||
const isCancel = jest.fn(() => false);
|
||||
const mainStore = RendererStore.create(
|
||||
{},
|
||||
{
|
||||
fetcher,
|
||||
notify,
|
||||
isCancel
|
||||
}
|
||||
);
|
||||
const states: Array<any> = [];
|
||||
|
||||
const store = ServiceStore.create(
|
||||
{
|
||||
id: '1',
|
||||
storeType: ServiceStore.name
|
||||
},
|
||||
{
|
||||
fetcher,
|
||||
notify,
|
||||
isCancel
|
||||
}
|
||||
);
|
||||
mainStore.addStore(store);
|
||||
|
||||
onSnapshot(store, snapshot => states.push(snapshot));
|
||||
|
||||
await store.fetchInitData('/api/xxx');
|
||||
expect(states).toMatchSnapshot();
|
||||
expect(notify).toHaveBeenCalled();
|
||||
expect(notify).toHaveBeenLastCalledWith('error', 'Network Error');
|
||||
expect(isCancel).toHaveBeenCalled();
|
||||
});
|
||||
Reference in New Issue
Block a user