* feat: multiple apps plugin * feat: multipleAppManager in Application * stage * fix: export error * test: multiple app * application model * feat: create application with plugins * load and install after sub application created * create subApp database beforeInstall * sub apps listen to main app start & stop events * refactor: getPluginName as package name * feat: load apps on mainApp starts * fix: test * feat: beforeGetApplication event * fix: test * fix: test with sqlite memory database * test: lazyLoad application * fix: test with sqlite memory * chore: clone database collection & promise.all
93 lines
2.1 KiB
TypeScript
93 lines
2.1 KiB
TypeScript
import { mockServer, MockServer } from '@nocobase/test';
|
|
import { Database } from '@nocobase/database';
|
|
import { PluginMultipleApps } from '../server';
|
|
|
|
describe('multiple apps create', () => {
|
|
let app: MockServer;
|
|
let db: Database;
|
|
|
|
beforeEach(async () => {
|
|
app = mockServer({});
|
|
db = app.db;
|
|
await app.cleanDb();
|
|
app.plugin(PluginMultipleApps);
|
|
|
|
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',
|
|
plugins: [
|
|
{
|
|
name: '@nocobase/plugin-ui-schema-storage',
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
const miniApp = app.appManager.applications.get('miniApp');
|
|
expect(miniApp).toBeDefined();
|
|
|
|
expect(miniApp.pm.get('@nocobase/plugin-ui-schema-storage')).toBeDefined();
|
|
});
|
|
|
|
it('should lazy load applications', async () => {
|
|
await db.getRepository('applications').create({
|
|
values: {
|
|
name: 'miniApp',
|
|
plugins: [
|
|
{
|
|
name: '@nocobase/plugin-ui-schema-storage',
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
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();
|
|
});
|
|
});
|