index.spec.js 5.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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('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, { standalone: false });
  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. expect(tree.files).toEqual(jasmine.arrayContaining([
  34. '/projects/ng-zorro/src/app/app.component.html',
  35. '/projects/ng-zorro/src/app/app.component.css',
  36. '/projects/ng-zorro/src/app/app.component.ts',
  37. '/projects/ng-zorro/src/app/app-routing.module.ts',
  38. '/projects/ng-zorro/src/app/pages/welcome/welcome-routing.module.ts',
  39. '/projects/ng-zorro/src/app/pages/welcome/welcome.component.ts',
  40. '/projects/ng-zorro/src/app/pages/welcome/welcome.component.css',
  41. '/projects/ng-zorro/src/app/pages/welcome/welcome.component.html'
  42. ]));
  43. }));
  44. describe('style option', () => {
  45. it('should set the style preprocessor correctly', () => __awaiter(void 0, void 0, void 0, function* () {
  46. const options = Object.assign(Object.assign({}, defaultOptions), { style: schema_1.Style.Less });
  47. const tree = yield runner.runSchematic('sidemenu', options, appTree);
  48. const appContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/app.component.ts');
  49. const welcomeContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/pages/welcome/welcome.component.ts');
  50. expect(appContent).toContain('app.component.less');
  51. expect(welcomeContent).toContain('welcome.component.less');
  52. expect(tree.files).toEqual(jasmine.arrayContaining([
  53. '/projects/ng-zorro/src/app/app.component.less',
  54. '/projects/ng-zorro/src/app/pages/welcome/welcome.component.less'
  55. ]));
  56. }));
  57. it('should fall back to the @schematics/angular:component option value', () => __awaiter(void 0, void 0, void 0, function* () {
  58. const options = Object.assign(Object.assign({}, defaultOptions), { template: 'sidemenu' });
  59. appTree = yield (0, test_app_1.createTestApp)(runner, { style: schema_1.Style.Less, standalone: false });
  60. const tree = yield runner.runSchematic('ng-add', options, appTree);
  61. expect(tree.files).toEqual(jasmine.arrayContaining([
  62. '/projects/ng-zorro/src/app/app.component.less',
  63. '/projects/ng-zorro/src/app/pages/welcome/welcome.component.less'
  64. ]));
  65. }));
  66. });
  67. it('should set the prefix correctly', () => __awaiter(void 0, void 0, void 0, function* () {
  68. const options = Object.assign(Object.assign({}, defaultOptions), { prefix: 'nz' });
  69. const tree = yield runner.runSchematic('sidemenu', options, appTree);
  70. const appContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/app.component.ts');
  71. const welcomeContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/pages/welcome/welcome.component.ts');
  72. expect(appContent).toContain(`selector: 'nz-root'`);
  73. expect(welcomeContent).toContain(`selector: 'nz-welcome'`);
  74. }));
  75. it('should set standalone to be false', () => __awaiter(void 0, void 0, void 0, function* () {
  76. const options = Object.assign({}, defaultOptions);
  77. const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
  78. const appContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/app.component.ts');
  79. expect(appContent).toContain('standalone: false');
  80. }));
  81. });
  82. //# sourceMappingURL=index.spec.js.map