/
index.spec.ts
74 lines (64 loc) · 2.59 KB
/
index.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
import { createAlainApp, migrationCollection } from '../../../utils/testing';
describe('Schematic: ng-update: v17Rule', () => {
let runner: SchematicTestRunner;
let tree: UnitTestTree;
const logs: string[] = [];
const jsonSchemaModulePath = '/projects/foo/src/app/shared/json-schema/json-schema.module.ts';
beforeEach(async () => {
({ runner, tree } = await createAlainApp());
if (!tree.exists(jsonSchemaModulePath)) {
tree.create(
jsonSchemaModulePath,
`import { NgModule } from '@angular/core';
import { DelonFormModule, WidgetRegistry } from '@delon/form';
import { TestWidget } from './test/test.widget';
import { SharedModule } from '../shared.module';
export const SCHEMA_THIRDS_COMPONENTS = [TestWidget];
@NgModule({
declarations: SCHEMA_THIRDS_COMPONENTS,
imports: [SharedModule, DelonFormModule.forRoot()],
exports: SCHEMA_THIRDS_COMPONENTS
})
export class JsonSchemaModule {
constructor(widgetRegistry: WidgetRegistry) {
widgetRegistry.register(TestWidget.KEY, TestWidget);
}
}
`
);
}
});
async function runMigration(): Promise<void> {
logs.length = 0;
runner = new SchematicTestRunner('schematics', migrationCollection);
runner.logger.subscribe(e => logs.push(e.message));
await runner.runSchematic('migration-v17', {}, tree);
}
it('should be working', async () => {
await runMigration();
const content = tree.readContent(jsonSchemaModulePath);
expect(content).toContain(`import { UploadWidgetModule } from '@delon/form/widgets/upload';`);
expect(content).toContain(`, UploadWidgetModule`);
});
it('#removeAlainThemeModuleForRoot', async () => {
const globalConfigPath = '/projects/foo/src/app/global-config.module.ts';
tree.create(
globalConfigPath,
`
import { AlainThemeModule } from '@delon/theme';
const alainModules: any[] = [AlainThemeModule.forRoot(), DelonACLModule.forRoot()];
`
);
await runMigration();
const content = tree.readContent(globalConfigPath);
expect(content).not.toContain(`AlainThemeModule.forRoot()`);
});
it('#replaceProvideAlainConfig', async () => {
const globalConfigPath = '/projects/foo/src/app/global-config.module.ts';
tree.create(globalConfigPath, `const alainProvides = [{ provide: ALAIN_CONFIG, useValue: alainConfig }];`);
await runMigration();
const content = tree.readContent(globalConfigPath);
expect(content).toContain(`provideAlainConfig(alainConfig)`);
});
});