Prerequisite
Create new interfaces and types that will be utilized throughout the hero and villain groups of components.
// src/models/Boy.ts
export interface Boy {
id: string;
name: string;
description: string;
}
/* istanbul ignore file */// src/models/types.ts
import { Hero } from "./Hero";
import { Villain } from "./Villain";
import { Boy } from "./Boy";
export type HeroProperty = Hero["name"] | Hero["description"] | Hero["id"];
export type VillainProperty =
| Villain["name"]
| Villain["description"]
| Villain["id"];
export type BoyProperty = Boy["name"] | Boy["description"] | Boy["id"];
export type EntityRoute = "heroes" | "villains" | "boys";
export type EntityType = "hero" | "villain" | "boy";
/** Returns the corresponding route for the entity;
*
* `hero` -> `/heroes`, `villain` -> `/villains`, `boy` -> `/boys` */
export const entityRoute = (entityType: EntityType) =>
entityType === "hero"
? "heroes"
: entityType === "villain"
? "villains"
: "boys";
/* istanbul ignore file */Move api.ts to its own folder
api.ts to its own folderFrom ./src/hooks/api.ts to ./src/api/api.ts. Your IDE should update the dependencies should automatically.
Update the hooks
useDeleteEntity gets updated for Boy..
useGetEntities just needs the comment to be updated
Helper for GET to
/heroesor/villainsroutesHelper for GET to
/heroes,/villainsor/boysroutes.
usePostEntity gets updated for Boy.
usePutEntity gets updated for Boys.
Modify the e2e commands
Between the 3 files under ./cypress/support, we can compartmentalize the imports in favor of relevance
commands.ts: all plugin imports, and commands common to e2e & CT (ex:cy.getByCY).component.ts: the commands specific to component tests (ex:cy.mount,cy.wrappedMount).e2e.ts: the commands specific to e2e (ex:cy.crud).
component.tsx and e2e.ts will import commands.ts so that CT and e2e files have access to common commands and plugins.
Update the type definitions in the repo root.
Create a boys mirror of the heroes
Update ./db.json
./db.jsonAdd boys group.
Mirror it to ./cypress/fixtures/db.json so that we can reset the db state correctly.
Add fixture ./cypress/fixtures/boys.json
./cypress/fixtures/boys.jsonMirror the components
We are creating 3 components for boys, mirroring heroes group as they are. We also have to update some of the base components.
For ListHeader only the type changes for title.
The rest are mirrors. Create a folder ./src/boys/ and the 3 mirror files under it.
Add Boys route to App.tsx
Add Boys to NavBar component.
Mirror the e2e tests
We create 3 new e2e tests, which are boy mirrors of the hero versions.
The backend test needs a new block to cover villains.
The routes-nav needs a new test to cover villains route.
Mirror the Cypress component tests
First, update Navbar and App tests. For Navbar.cy we just need to add boys to the routes array
For App.cy we need to intercept the boys route and add a check for boys.
We need 3 new component tests for the 3 components under boys.
Mirror the RTL tests
We just need to replicate what was done with Cy CT to RTL.
App.test needs a msw handler and a new route check.
Navbar.test needs the same routes variable update to include Boys.
Last updated