1
+ import { TemplateInputParameter } from './../../../utils/interfaces/template-parameters' ;
2
+ import { writeFileSync , readFileSync } from 'fs' ;
3
+ import { effects , filesToAffect , standaloneEffects } from "../../../morph" ;
4
+ import { AngularTypeNames } from "../../types/types" ;
5
+ import { EditFileEffect } from '../../../morph/interfaces/morph.interface' ;
6
+
7
+
8
+ describe ( 'exportPipeFile' , ( ) => {
9
+ afterEach ( ( ) => {
10
+ writeFileSync ( 'src/rz/angular/effects/standalone-pipe/index.ts' , '' ) ;
11
+ } ) ;
12
+ it ( 'should export pipe file' , ( ) => {
13
+ const mockFilePath = 'src/rz/angular/effects/standalone-pipe/standalone-pipe.ts' ;
14
+ const mockTemplateInputParameter : TemplateInputParameter = {
15
+ defaultValue : 'libs/{name}-dialog' ,
16
+ description : 'File path for name file(s)' ,
17
+ inputType : 'text' ,
18
+ name : 'nameFilePath' ,
19
+ optionalTypes : [ { name : 'isExported' , selected : true } ] ,
20
+ paramType : 'filePath' ,
21
+ type : AngularTypeNames . StandalonePipe
22
+ }
23
+
24
+ effects ( mockFilePath , mockTemplateInputParameter , 'angular' ) ;
25
+ const result = readFileSync ( 'src/rz/angular/effects/standalone-pipe/index.ts' ) . toString ( ) ;
26
+ const expected = `export * from "./standalone-pipe";
27
+ `
28
+ expect ( result ) . toEqual ( expected ) ;
29
+ } ) ;
30
+ } ) ;
31
+
32
+ describe ( 'closestIndexFileToImportTo' , ( ) => {
33
+ it ( 'should choose closest index file' , ( ) => {
34
+ const mockFilePath = 'path/to/another/src/hello.pipe.ts' ;
35
+ const mockParameter = {
36
+ optionalTypes : { } ,
37
+ type : AngularTypeNames . StandalonePipe
38
+ } as any ;
39
+
40
+ const fileTree = [
41
+ "path/to/another/src" ,
42
+ "path/to/another/src/hello.pipe.ts" ,
43
+ "path/to/another/index.ts" ,
44
+ "path/to/another"
45
+ ] ;
46
+ const fileToModify = filesToAffect ( mockFilePath , fileTree , mockParameter , 'angular' ) ;
47
+ expect ( fileToModify ) . toEqual ( [ 'path/to/another/index.ts' ] ) ;
48
+ } ) ;
49
+ } ) ;
50
+
51
+ describe ( 'standalonepipeEffects' , ( ) => {
52
+ it ( 'should trigger standalone pipe effects' , ( ) => {
53
+ const programmingLanguage = 'angular' ;
54
+ const mockParameter = {
55
+ type : AngularTypeNames . StandalonePipe
56
+ } as any ;
57
+ const mockFileEffects : EditFileEffect [ ] = [ {
58
+ filePath : 'path/to/another/index.ts' ,
59
+ originFilePath : 'path/to/another/src/hello.pipe.ts' ,
60
+ content : ``
61
+ } ] ;
62
+ const result = standaloneEffects ( programmingLanguage , mockParameter , mockFileEffects ) ;
63
+ const indexContent = `export * from "./src/hello.pipe";
64
+ ` ;
65
+ expect ( result ) . toEqual ( [ {
66
+ content : indexContent ,
67
+ originFilePath : "path/to/another/src/hello.pipe.ts" ,
68
+ filePath : 'path/to/another/index.ts'
69
+ } ] ) ;
70
+ } ) ;
71
+ } ) ;
0 commit comments