2022-03-28 22:01:10 +08:00
|
|
|
import { mockServer, MockServer } from '@nocobase/test';
|
|
|
|
import { Database } from '@nocobase/database';
|
2022-04-24 20:22:50 +08:00
|
|
|
import { PluginMultiAppManager } from '../server';
|
2022-04-29 20:00:50 +08:00
|
|
|
import { ApplicationModel } from '..';
|
2022-03-28 22:01:10 +08:00
|
|
|
|
|
|
|
describe('multiple apps create', () => {
|
|
|
|
let app: MockServer;
|
|
|
|
let db: Database;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
app = mockServer({});
|
|
|
|
db = app.db;
|
|
|
|
await app.cleanDb();
|
2022-04-24 20:22:50 +08:00
|
|
|
app.plugin(PluginMultiAppManager);
|
2022-03-28 22:01:10 +08:00
|
|
|
|
|
|
|
await app.loadAndInstall();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
await app.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create application', async () => {
|
|
|
|
const miniApp = await db.getRepository('applications').create({
|
|
|
|
values: {
|
|
|
|
name: 'miniApp',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(app.appManager.applications.get('miniApp')).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove application', async () => {
|
|
|
|
await db.getRepository('applications').create({
|
|
|
|
values: {
|
|
|
|
name: 'miniApp',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(app.appManager.applications.get('miniApp')).toBeDefined();
|
|
|
|
|
|
|
|
await db.getRepository('applications').destroy({
|
|
|
|
filter: {
|
|
|
|
name: 'miniApp',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(app.appManager.applications.get('miniApp')).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create with plugins', async () => {
|
|
|
|
await db.getRepository('applications').create({
|
|
|
|
values: {
|
|
|
|
name: 'miniApp',
|
2022-04-24 20:22:50 +08:00
|
|
|
options: {
|
|
|
|
plugins: [['@nocobase/plugin-ui-schema-storage', { test: 'B' }]],
|
|
|
|
},
|
2022-03-28 22:01:10 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const miniApp = app.appManager.applications.get('miniApp');
|
|
|
|
expect(miniApp).toBeDefined();
|
|
|
|
|
2022-04-24 20:22:50 +08:00
|
|
|
const plugin = miniApp.pm.get('@nocobase/plugin-ui-schema-storage');
|
|
|
|
|
|
|
|
expect(plugin).toBeDefined();
|
|
|
|
expect(plugin.options).toEqual({
|
|
|
|
test: 'B',
|
|
|
|
});
|
2022-03-28 22:01:10 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should lazy load applications', async () => {
|
|
|
|
await db.getRepository('applications').create({
|
|
|
|
values: {
|
|
|
|
name: 'miniApp',
|
2022-04-24 20:22:50 +08:00
|
|
|
options: {
|
|
|
|
plugins: ['@nocobase/plugin-ui-schema-storage'],
|
|
|
|
},
|
2022-03-28 22:01:10 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
await app.appManager.removeApplication('miniApp');
|
|
|
|
|
|
|
|
app.appManager.setAppSelector(() => {
|
|
|
|
return 'miniApp';
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(app.appManager.applications.has('miniApp')).toBeFalsy();
|
|
|
|
|
|
|
|
await app.agent().resource('test').test();
|
|
|
|
|
|
|
|
expect(app.appManager.applications.has('miniApp')).toBeTruthy();
|
|
|
|
});
|
2022-04-29 20:00:50 +08:00
|
|
|
|
|
|
|
it('should change handleAppStart', async () => {
|
|
|
|
const customHandler = jest.fn();
|
|
|
|
ApplicationModel.handleAppStart = customHandler;
|
|
|
|
|
|
|
|
await db.getRepository('applications').create({
|
|
|
|
values: {
|
|
|
|
name: 'miniApp',
|
|
|
|
options: {
|
|
|
|
plugins: ['@nocobase/plugin-ui-schema-storage'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(customHandler).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
2022-03-28 22:01:10 +08:00
|
|
|
});
|