standalone.spec.js 5.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. "use strict";
  2. /**
  3. * Use of this source code is governed by an MIT-style license that can be
  4. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  5. */
  6. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  7. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  8. return new (P || (P = Promise))(function (resolve, reject) {
  9. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  10. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  11. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  12. step((generator = generator.apply(thisArg, _arguments || [])).next());
  13. });
  14. };
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. const testing_1 = require("@angular-devkit/schematics/testing");
  17. const schema_1 = require("@schematics/angular/ng-new/schema");
  18. const test_app_1 = require("../../testing/test-app");
  19. const get_file_content_1 = require("../../utils/get-file-content");
  20. describe('[standalone] side-menu schematic', () => {
  21. const defaultOptions = {
  22. project: 'ng-zorro'
  23. };
  24. let runner;
  25. let appTree;
  26. beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
  27. runner = new testing_1.SchematicTestRunner('schematics', require.resolve('../../collection.json'));
  28. appTree = yield (0, test_app_1.createTestApp)(runner);
  29. }));
  30. it('should create side-menu files', () => __awaiter(void 0, void 0, void 0, function* () {
  31. const options = Object.assign({}, defaultOptions);
  32. const tree = yield runner.runSchematic('sidemenu', options, appTree);
  33. const files = tree.files;
  34. expect(files).toEqual(jasmine.arrayContaining([
  35. '/projects/ng-zorro/src/app/app.component.html',
  36. '/projects/ng-zorro/src/app/app.component.css',
  37. '/projects/ng-zorro/src/app/app.component.ts',
  38. '/projects/ng-zorro/src/app/app.routes.ts',
  39. '/projects/ng-zorro/src/app/icons-provider.ts',
  40. '/projects/ng-zorro/src/app/pages/welcome/welcome.component.ts',
  41. '/projects/ng-zorro/src/app/pages/welcome/welcome.component.css',
  42. '/projects/ng-zorro/src/app/pages/welcome/welcome.component.html',
  43. '/projects/ng-zorro/src/app/pages/welcome/welcome.routes.ts'
  44. ]));
  45. }));
  46. it('should infer the standalone option from the project structure', () => __awaiter(void 0, void 0, void 0, function* () {
  47. const options = Object.assign({}, defaultOptions);
  48. const tree = yield runner.runSchematic('sidemenu', options, appTree);
  49. const appContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/app.component.ts');
  50. expect(tree.exists('/projects/material/src/app/app.module.ts')).toBe(false);
  51. // since v19, the standalone option is removed
  52. expect(appContent).not.toContain('standalone: true');
  53. expect(appContent).toContain('imports: [');
  54. }));
  55. describe('style option', () => {
  56. it('should set the style preprocessor correctly', () => __awaiter(void 0, void 0, void 0, function* () {
  57. const options = Object.assign(Object.assign({}, defaultOptions), { style: schema_1.Style.Less });
  58. const tree = yield runner.runSchematic('sidemenu', options, appTree);
  59. const files = tree.files;
  60. const appContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/app.component.ts');
  61. const welcomeContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/pages/welcome/welcome.component.ts');
  62. expect(appContent).toContain('app.component.less');
  63. expect(welcomeContent).toContain('welcome.component.less');
  64. expect(files).toEqual(jasmine.arrayContaining([
  65. '/projects/ng-zorro/src/app/app.component.less',
  66. '/projects/ng-zorro/src/app/pages/welcome/welcome.component.less'
  67. ]));
  68. }));
  69. it('should fall back to the @schematics/angular:component option value', () => __awaiter(void 0, void 0, void 0, function* () {
  70. const options = Object.assign(Object.assign({}, defaultOptions), { template: 'sidemenu' });
  71. appTree = yield (0, test_app_1.createTestApp)(runner, { style: schema_1.Style.Less });
  72. const tree = yield runner.runSchematic('ng-add', options, appTree);
  73. expect(tree.files).toEqual(jasmine.arrayContaining([
  74. '/projects/ng-zorro/src/app/app.component.less',
  75. '/projects/ng-zorro/src/app/pages/welcome/welcome.component.less'
  76. ]));
  77. }));
  78. });
  79. it('should set the prefix correctly', () => __awaiter(void 0, void 0, void 0, function* () {
  80. const options = Object.assign(Object.assign({}, defaultOptions), { prefix: 'nz' });
  81. const tree = yield runner.runSchematic('sidemenu', options, appTree);
  82. const appContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/app.component.ts');
  83. const welcomeContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/pages/welcome/welcome.component.ts');
  84. expect(appContent).toContain(`selector: 'nz-root'`);
  85. expect(welcomeContent).toContain(`selector: 'nz-welcome'`);
  86. }));
  87. });
  88. //# sourceMappingURL=standalone.spec.js.map