Skip to content

Commit

Permalink
Merge pull request #35 from razroo/ZETA-6515-add-not-supported-logic
Browse files Browse the repository at this point in the history
[ZETA-6515]: Add not supported logic
  • Loading branch information
CharlieGreenman authored Aug 22, 2023
2 parents 1e90759 + ab6fa75 commit e7d16cc
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 10 deletions.
13 changes: 13 additions & 0 deletions src/rz/angular/angular-effect.spec.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
6 changes: 3 additions & 3 deletions src/rz/angular/angular-effects.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/rz/morph/index.ts
Original file line number Diff line number Diff line change
@@ -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";
3 changes: 3 additions & 0 deletions src/rz/morph/interfaces/morph.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' |
Expand Down
41 changes: 39 additions & 2 deletions src/rz/morph/morph.spec.ts
Original file line number Diff line number Diff line change
@@ -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 = `<mat-paginator *ngIf="isPageable"
Expand Down Expand Up @@ -106,6 +106,43 @@ describe('morph', () => {
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();
Expand Down
8 changes: 4 additions & 4 deletions src/rz/morph/morph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
}

Expand All @@ -58,7 +58,7 @@ export function standaloneEffects(programmingLanguage: string, parameter: Templa
case CommunityPaths.Angular:
return angularStandaloneEffects((parameter.type) as AngularTypeNames, fileEffects)
default:
return []
return []
}
}

Expand Down

0 comments on commit e7d16cc

Please sign in to comment.