index.spec.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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/component/schema");
  18. const node_test_1 = require("node:test");
  19. const test_app_1 = require("../testing/test-app");
  20. const appOptions = {
  21. name: 'ng-zorro',
  22. inlineStyle: false,
  23. inlineTemplate: false,
  24. routing: false,
  25. style: schema_1.Style.Less,
  26. skipTests: false,
  27. skipPackageJson: false
  28. };
  29. const defaultOptions = {
  30. name: 'test',
  31. inlineStyle: false,
  32. inlineTemplate: false,
  33. changeDetection: schema_1.ChangeDetection.Default,
  34. style: schema_1.Style.Less,
  35. skipTests: false,
  36. module: undefined,
  37. export: false,
  38. project: 'ng-zorro'
  39. };
  40. (0, node_test_1.describe)('ng-component schematic', () => {
  41. let runner;
  42. let appTree;
  43. beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
  44. runner = new testing_1.SchematicTestRunner('schematics', require.resolve('../collection.json'));
  45. appTree = yield (0, test_app_1.createTestApp)(runner, Object.assign({}, appOptions));
  46. }));
  47. it('should create a component', () => __awaiter(void 0, void 0, void 0, function* () {
  48. const options = Object.assign({}, defaultOptions);
  49. const tree = yield runner.runSchematic('component', options, appTree);
  50. const files = tree.files;
  51. expect(files).toEqual(jasmine.arrayContaining([
  52. '/projects/ng-zorro/src/app/test/test.component.less',
  53. '/projects/ng-zorro/src/app/test/test.component.html',
  54. '/projects/ng-zorro/src/app/test/test.component.spec.ts',
  55. '/projects/ng-zorro/src/app/test/test.component.ts'
  56. ]));
  57. }));
  58. (0, node_test_1.describe)('style', () => {
  59. it('should create specified style', () => __awaiter(void 0, void 0, void 0, function* () {
  60. const options = Object.assign(Object.assign({}, defaultOptions), { style: schema_1.Style.Sass });
  61. const tree = yield runner.runSchematic('component', options, appTree);
  62. const files = tree.files.filter(file => file.startsWith('/projects/ng-zorro/src/app/test/'));
  63. expect(files).toEqual(jasmine.arrayContaining([
  64. '/projects/ng-zorro/src/app/test/test.component.sass',
  65. '/projects/ng-zorro/src/app/test/test.component.html',
  66. '/projects/ng-zorro/src/app/test/test.component.spec.ts',
  67. '/projects/ng-zorro/src/app/test/test.component.ts'
  68. ]));
  69. }));
  70. it('should not create style file when inlineStyle is true', () => __awaiter(void 0, void 0, void 0, function* () {
  71. const options = Object.assign(Object.assign({}, defaultOptions), { inlineStyle: true });
  72. const tree = yield runner.runSchematic('component', options, appTree);
  73. const files = tree.files.filter(file => file.startsWith('/projects/ng-zorro/src/app/test/'));
  74. expect(files.length).toEqual(3);
  75. expect(files).toEqual(jasmine.arrayContaining([
  76. '/projects/ng-zorro/src/app/test/test.component.html',
  77. '/projects/ng-zorro/src/app/test/test.component.spec.ts',
  78. '/projects/ng-zorro/src/app/test/test.component.ts'
  79. ]));
  80. }));
  81. it('should not create style file when style is none', () => __awaiter(void 0, void 0, void 0, function* () {
  82. const options = Object.assign(Object.assign({}, defaultOptions), { style: schema_1.Style.None });
  83. const tree = yield runner.runSchematic('component', options, appTree);
  84. const files = tree.files.filter(file => file.startsWith('/projects/ng-zorro/src/app/test/'));
  85. expect(files.length).toEqual(3);
  86. expect(files).toEqual(jasmine.arrayContaining([
  87. '/projects/ng-zorro/src/app/test/test.component.html',
  88. '/projects/ng-zorro/src/app/test/test.component.spec.ts',
  89. '/projects/ng-zorro/src/app/test/test.component.ts'
  90. ]));
  91. }));
  92. });
  93. (0, node_test_1.describe)('displayBlock', () => {
  94. it('should add display block styles to the component', () => __awaiter(void 0, void 0, void 0, function* () {
  95. const options = Object.assign(Object.assign({}, defaultOptions), { displayBlock: true });
  96. const tree = yield runner.runSchematic('component', options, appTree);
  97. const content = tree.readContent('/projects/ng-zorro/src/app/test/test.component.less');
  98. expect(content).toMatch(/display: block/);
  99. }));
  100. it('should add display block styles to the component when inlineStyle is true', () => __awaiter(void 0, void 0, void 0, function* () {
  101. const options = Object.assign(Object.assign({}, defaultOptions), { displayBlock: true, inlineStyle: true });
  102. const tree = yield runner.runSchematic('component', options, appTree);
  103. const content = tree.readContent('/projects/ng-zorro/src/app/test/test.component.ts');
  104. expect(content).toMatch(/display: block/);
  105. }));
  106. });
  107. (0, node_test_1.describe)('flat', () => {
  108. it('should create a flat component', () => __awaiter(void 0, void 0, void 0, function* () {
  109. const options = Object.assign(Object.assign({}, defaultOptions), { flat: true });
  110. const tree = yield runner.runSchematic('component', options, appTree);
  111. const files = tree.files;
  112. expect(files).toEqual(jasmine.arrayContaining([
  113. '/projects/ng-zorro/src/app/test.component.less',
  114. '/projects/ng-zorro/src/app/test.component.html',
  115. '/projects/ng-zorro/src/app/test.component.spec.ts',
  116. '/projects/ng-zorro/src/app/test.component.ts'
  117. ]));
  118. }));
  119. });
  120. (0, node_test_1.describe)('classnameWithModule', () => {
  121. it('should find the closest module', () => __awaiter(void 0, void 0, void 0, function* () {
  122. const options = Object.assign(Object.assign({}, defaultOptions), { standalone: false });
  123. const closestModule = '/projects/ng-zorro/src/app/test/test.module.ts';
  124. appTree.create(closestModule, `
  125. import { NgModule } from '@angular/core';
  126. @NgModule({
  127. imports: [],
  128. declarations: []
  129. })
  130. export class ClosestModule { }
  131. `);
  132. const tree = yield runner.runSchematic('component', options, appTree);
  133. const fooModuleContent = tree.readContent(closestModule);
  134. expect(fooModuleContent).toMatch(/import { TestComponent } from '.\/test.component'/);
  135. }));
  136. it('should set classname with the closest module', () => __awaiter(void 0, void 0, void 0, function* () {
  137. const options = Object.assign(Object.assign({}, defaultOptions), { classnameWithModule: true, standalone: false });
  138. const testModule = '/projects/ng-zorro/src/app/test/test.module.ts';
  139. appTree.create(testModule, `
  140. import { NgModule } from '@angular/core';
  141. @NgModule({
  142. imports: [],
  143. declarations: []
  144. })
  145. export class TestModule { }
  146. `);
  147. const tree = yield runner.runSchematic('component', options, appTree);
  148. const fooModuleContent = tree.readContent(testModule);
  149. expect(fooModuleContent).toMatch(/import { TestTestComponent } from '.\/test.component'/);
  150. }));
  151. it('should set classname with the specified module', () => __awaiter(void 0, void 0, void 0, function* () {
  152. const options = Object.assign(Object.assign({}, defaultOptions), { classnameWithModule: true, module: 'app.module.ts', standalone: false });
  153. const app = yield (0, test_app_1.createTestApp)(runner, Object.assign(Object.assign({}, appOptions), { standalone: false }));
  154. const tree = yield runner.runSchematic('component', options, app);
  155. const appComponentContent = tree.readContent('/projects/ng-zorro/src/app/app.module.ts');
  156. expect(appComponentContent).toMatch(/import { AppTestComponent } from '.\/test\/test.component'/);
  157. }));
  158. });
  159. });
  160. //# sourceMappingURL=index.spec.js.map