Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions schematics/utility/addAuthentication/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Rule, Tree } from "@angular-devkit/schematics";
import { InsertChange } from "@schematics/angular/utility/change";
import { Schema } from "../../application/schema";
import modifyCommandTs from "./updateCommandsTs/change";

function addAuthenticationRule(_options: Schema): Rule {
return (tree: Tree) => {
const changesInCommansTs = modifyCommandTs(tree);
const updateRecorder = tree.beginUpdate("web/cypress/support/commands.ts");

if (changesInCommansTs instanceof InsertChange) {
updateRecorder.insertLeft(
changesInCommansTs.pos,
changesInCommansTs.toAdd
);
}

tree.commitUpdate(updateRecorder);

return tree;
};
}

export default addAuthenticationRule;
40 changes: 40 additions & 0 deletions schematics/utility/addAuthentication/updateCommandsTs/change.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { SchematicsException, Tree } from "@angular-devkit/schematics";
import { getSourceNodes } from "@schematics/angular/utility/ast-utils";
import { Change, InsertChange } from "@schematics/angular/utility/change";
import ts from "typescript";

function modifyCommandTs(tree: Tree): Change {
const fileRawContent = tree.read("web/cypress/support/commands.ts");

if (!fileRawContent) throw new SchematicsException(`File does not exist.`);

const fileFormattedContent = fileRawContent.toString("utf-8");
const sourceFile = ts.createSourceFile(
"commands.ts",
fileFormattedContent,
ts.ScriptTarget.Latest,
true
);
const nodes: ts.Node[] = getSourceNodes(sourceFile);
const insertionNode = nodes.find(
(node) =>
node.kind === ts.SyntaxKind.ImportDeclaration &&
node.getText().includes("./methods/base-commands")
);

if (!insertionNode)
throw new SchematicsException(`insertion node not retrieved!`);

const contentToInsert = `
import "./methods/auth-commands";
import "./methods/aws-calls";
`;

return new InsertChange(
"web/cypress/support/commands.ts",
insertionNode.getEnd(),
contentToInsert
);
}

export default modifyCommandTs;

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
// Add all your custom global commands to the "Chainable" interface
namespace Cypress {
interface Chainable {
checkThatURLContains(specificPage: string);
checkThatURLContains(specificPage: string);<%if(modules.includes('authentication')) {%>
fillSignUpForm(email: string, password: string);
fillSignInForm(email: string, password: string);
signOut();
clickOn(selector: string);
typeText(selector: string, text: string);
clearElement(selector: string);
checkValidation(validationText: string);
getByDataTestId(selector: string, ...args: any[]);
checkIfTextIsShown(selector: string, text: string);
checkTheStateOfElement(selector: string, state: string);
checkIfPasswordIsVisible(selector: string, isVisible: boolean);
confirmUserSignUp(email: string);
createUserWithPassword(email: string);
addUserToSpecificGroup(email: string, group: string);
createAdminWithPassword(email: string);
<%}%>
}
}
4 changes: 4 additions & 0 deletions schematics/web/e2e/framework/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { WEB_PACKAGE_JSON_PATH } from "@consts/index";
import { E2ERunner, Module } from "@enums/Module";
import { Schematic } from "@enums/Schematic";
import addAuthenticationRule from "@janush-schematics/utility/addAuthentication";
import { stubArg } from "@janush-schematics/utility/stubArg/stubArg";
import { addPackageJsonDependency } from "@schematics/angular/utility/dependencies";
import {
Expand Down Expand Up @@ -69,6 +70,9 @@ export const e2eFrameworkGenerator = (options: Schema): Rule => {
MergeStrategy.Overwrite
)
: stubArg,
options.modules.includes(Module.AUTHENTICATION)
? addAuthenticationRule
: stubArg,
packageJsonCypressExtender,
schematic("apply-prettier", {}),
]);
Expand Down