diff --git a/src/rz/angular/angular-effect.spec.ts b/src/rz/angular/angular-effect.spec.ts new file mode 100644 index 0000000..4bfc61d --- /dev/null +++ b/src/rz/angular/angular-effect.spec.ts @@ -0,0 +1,13 @@ +import { NOT_SUPPORTED } from "../morph"; +import { angularFilesToAffect } from "./angular-effects"; + +describe('AngularEffects', () => { + it('should return NOT_SUPPORTED if not supported', () => { + const filePath = 'libs/hello.ts'; + const fileTree: string[] = []; + const type = 'zulu' as any; + + const result = angularFilesToAffect(filePath, fileTree, type, []); + expect(result).toEqual(NOT_SUPPORTED) + }) +}) \ No newline at end of file diff --git a/src/rz/angular/angular-effects.ts b/src/rz/angular/angular-effects.ts index 3702555..5b3bd2f 100644 --- a/src/rz/angular/angular-effects.ts +++ b/src/rz/angular/angular-effects.ts @@ -1,5 +1,5 @@ import { Parameters } from "../morph"; -import { EditFileEffect } from "../morph/interfaces/morph.interface"; +import { EditFileEffect, NOT_SUPPORTED, NOT_SUPPORTED_TYPE } from "../morph/interfaces/morph.interface"; import { addClassToDeclarationsAndImports, componentEffects, fileToAddClassToDeclarationsAndImports } from "./effects/component/component-effects"; import { exportDirectiveFile } from "./effects/directive/directive"; import { exportGraphqlFile } from "./effects/graphql/graphql"; @@ -11,12 +11,12 @@ import { exportServiceFile } from "./effects/service/service"; import { exportComponentFile } from "./effects/standalone-component/standalone-component"; import { AngularType, AngularTypeNames, AngularOptionalType } from "./types/types"; -export function angularFilesToAffect(filePathWithName: string, fileTree: string[], type: AngularTypeNames, optionalTypes: AngularOptionalType[]): string[] { +export function angularFilesToAffect(filePathWithName: string, fileTree: string[], type: AngularTypeNames, optionalTypes: AngularOptionalType[]): string[] | NOT_SUPPORTED_TYPE { switch(type) { case AngularTypeNames.Component: return fileToAddClassToDeclarationsAndImports(filePathWithName, fileTree, optionalTypes); default: - return []; + return NOT_SUPPORTED; } } diff --git a/src/rz/morph/index.ts b/src/rz/morph/index.ts index f984df0..a4ba1d6 100644 --- a/src/rz/morph/index.ts +++ b/src/rz/morph/index.ts @@ -1,3 +1,3 @@ export { morphCode, filesToAffect, effects, standaloneEffects, Parameters, types } from "./morph"; -export { EditFile, EditInput} from "./interfaces/morph.interface"; +export { EditFile, EditInput, NOT_SUPPORTED_TYPE, NOT_SUPPORTED} from "./interfaces/morph.interface"; export { communityPaths, supportedCommunityPaths } from "./community-paths/community-paths"; \ No newline at end of file diff --git a/src/rz/morph/interfaces/morph.interface.ts b/src/rz/morph/interfaces/morph.interface.ts index 268cd94..8368d36 100644 --- a/src/rz/morph/interfaces/morph.interface.ts +++ b/src/rz/morph/interfaces/morph.interface.ts @@ -7,6 +7,9 @@ export interface EditInput { edits: EditFile[]; } +export type NOT_SUPPORTED_TYPE = 'NOT_SUPPORTED'; +export const NOT_SUPPORTED = 'NOT_SUPPORTED'; + export interface EditFile { nodeType?: 'import' | 'export' | 'classDeclaration' | 'classMethod' | 'addNgModuleImport' | 'addNgModuleImportToSpec' | 'addNgModuleProvider' | 'addNgModuleDeclaration' | 'addNgModuleProviderToSpec' | 'addToVariableObject' | 'editImport' | 'addConstructorMethod' | diff --git a/src/rz/morph/morph.spec.ts b/src/rz/morph/morph.spec.ts index ff7abbe..223ac83 100644 --- a/src/rz/morph/morph.spec.ts +++ b/src/rz/morph/morph.spec.ts @@ -1,8 +1,8 @@ import { EditScssInput } from './../scss/interfaces/morph-scss.interface'; import { readFileSync, writeFileSync } from 'fs'; import { EditHtmlFile, EditHtmlInput } from '../angular/interfaces/edit-html.interface'; -import { EditInput } from './interfaces/morph.interface'; -import { morphCode } from "./morph"; +import { EditInput, NOT_SUPPORTED } from './interfaces/morph.interface'; +import { filesToAffect, morphCode } from "./morph"; describe('morph', () => { const siblingCodeBlock = ` { expect(morphCode(editScssInput as EditScssInput)).toEqual(expected); }); + describe('NOT_SUPPORTED', () => { + + it('should return NOT_SUPPORTED if not language supported', () => { + const mockFilePath = 'path/to/another/src/hello.component.ts'; + const mockParameter = { + optionalTypes: {}, + type: 'component' as any + } as any; + + const fileTree = [ + "path/to/another/src", + "path/to/another/src/hello.component.ts", + "path/to/another/hello.module.ts", + "path/to/another" + ]; + const fileToModify = filesToAffect(mockFilePath, fileTree, mockParameter, 'felipe'); + expect(fileToModify).toEqual(NOT_SUPPORTED); + }); + + it('should return NOT_SUPPORTED if language supported but type is not', () => { + const mockFilePath = 'path/to/another/src/hello.component.ts'; + const mockParameter = { + optionalTypes: {}, + type: 'yolo' as any + } as any; + + const fileTree = [ + "path/to/another/src", + "path/to/another/src/hello.component.ts", + "path/to/another/hello.module.ts", + "path/to/another" + ]; + const fileToModify = filesToAffect(mockFilePath, fileTree, mockParameter, 'angular'); + expect(fileToModify).toEqual(NOT_SUPPORTED); + }) + }) + describe('insertIntoHtmlTag', () => { it('should insert html into the specified tag if parent tag is div', () => { const fileToBeAddedTo = readFileSync('src/rz/angular/snapshots/insert-into-html-tag/insert-into-html-tag.html.snap').toString(); diff --git a/src/rz/morph/morph.ts b/src/rz/morph/morph.ts index 9ffdf30..8418ba2 100644 --- a/src/rz/morph/morph.ts +++ b/src/rz/morph/morph.ts @@ -11,7 +11,7 @@ import { EditJsonInput } from '../json/interfaces/json-morph.interface'; import { angularEffects, angularFilesToAffect, angularStandaloneEffects } from '../angular/angular-effects'; import { reactTypes } from '../react'; import { TemplateInputParameter } from '../utils/interfaces/template-parameters'; -import { EditFileEffect } from './interfaces/morph.interface'; +import { EditFileEffect, NOT_SUPPORTED, NOT_SUPPORTED_TYPE } from './interfaces/morph.interface'; // takes in singular object and makes all edits to files // used when editing a file @@ -38,12 +38,12 @@ export interface Parameters { // sister function to "effects" // This function happens first and then effects is called -export function filesToAffect(filePathWithName: string, fileTree: string[], parameter: TemplateInputParameter, programmingLanguage: string): string[] { +export function filesToAffect(filePathWithName: string, fileTree: string[], parameter: TemplateInputParameter, programmingLanguage: string): string[] | NOT_SUPPORTED_TYPE { switch(programmingLanguage) { case 'angular': return angularFilesToAffect(filePathWithName, fileTree, (parameter.type) as AngularTypeNames, (parameter.optionalTypes) as any as AngularOptionalType[]); default: - return []; + return NOT_SUPPORTED; } } @@ -58,7 +58,7 @@ export function standaloneEffects(programmingLanguage: string, parameter: Templa case CommunityPaths.Angular: return angularStandaloneEffects((parameter.type) as AngularTypeNames, fileEffects) default: - return [] + return [] } }