From 3d4f9af928030278a52921e350f0ab38c6bef757 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sun, 29 May 2022 11:04:27 +0300 Subject: [PATCH] Delete comment test --- .gitignore | 5 ++++- README.md | 5 +++++ app/components/FormWithConfirm.tsx | 7 ++++++- app/db/models/plusSuggestions.server.ts | 3 ++- app/db/sql.ts | 4 +++- app/routes/plus/suggestions.tsx | 16 +++++++++----- cypress.json | 2 +- cypress/integration/plus.spec.ts | 7 ++++++- cypress/support/index.ts | 2 +- package-lock.json | 28 +++++++++++++++++++++++++ package.json | 6 +++++- 11 files changed, 72 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 2beb96a84..db63cb684 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,7 @@ node_modules /public/build .env -db.sqlite3* \ No newline at end of file +db*.sqlite3* + +/cypress/videos +/cypress/screenshots \ No newline at end of file diff --git a/README.md b/README.md index 09be3e8d7..44e4580be 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,11 @@ There is a sequence of commands you need to run: 4. `npm run migrate` to set up the database tables. 5. `npm run dev` to run both the server and frontend. +And if you want to run the E2E tests: + +6. Make a copy of the `db.sqlite3` file created by migration and name it `db-cypress.sqlite3`. +7. `npm run dev:cypress` and `npm run cy:open` can be used to run the E2E tests. + ## Project structure ``` diff --git a/app/components/FormWithConfirm.tsx b/app/components/FormWithConfirm.tsx index 63de77269..8a05b0382 100644 --- a/app/components/FormWithConfirm.tsx +++ b/app/components/FormWithConfirm.tsx @@ -33,7 +33,12 @@ export function FormWithConfirm({

{dialogHeading}

-
- + Comments ({suggested.suggestions.length})
@@ -246,6 +251,7 @@ function SuggestedUser({ icon={} variant="minimal-destructive" aria-label="Delete comment" + data-cy="delete-comment-button" /> ) : null} diff --git a/cypress.json b/cypress.json index 065f531fb..174f2ce41 100644 --- a/cypress.json +++ b/cypress.json @@ -1,5 +1,5 @@ { - "baseUrl": "http://localhost:5800", + "baseUrl": "http://localhost:4455", "pluginsFile": false, "fixturesFolder": false } diff --git a/cypress/integration/plus.spec.ts b/cypress/integration/plus.spec.ts index 6f899e924..53fc7825c 100644 --- a/cypress/integration/plus.spec.ts +++ b/cypress/integration/plus.spec.ts @@ -13,7 +13,7 @@ describe("Plus suggestions page", () => { cy.contains("You are suggested"); }); - it("adds a comment", () => { + it.only("adds a comment and deletes one", () => { cy.auth(); cy.visit(PLUS_SUGGESTIONS_PAGE); cy.getCy("plus2-radio").click(); @@ -24,5 +24,10 @@ describe("Plus suggestions page", () => { cy.getCy("submit-button").click(); cy.contains("Cracked!"); + + cy.getCy("comments-summary").first().click(); + cy.getCy("delete-comment-button").first().click(); + cy.getCy("confirm-button").click(); + cy.contains("Cracked!").should("not.exist"); }); }); diff --git a/cypress/support/index.ts b/cypress/support/index.ts index a9b1a4465..15b277832 100644 --- a/cypress/support/index.ts +++ b/cypress/support/index.ts @@ -17,7 +17,7 @@ Cypress.Commands.add("getCy", (id) => { // TODO: make this a request instead... probably faster? Cypress.Commands.add("seed", () => { - cy.exec("npm run seed"); + cy.exec("npm run seed:cypress"); }); Cypress.Commands.add("auth", (id = 1) => { diff --git a/package-lock.json b/package-lock.json index 694aad38f..628890a82 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,6 +33,7 @@ "@types/react-dom": "^18.0.5", "@typescript-eslint/eslint-plugin": "^5.26.0", "@typescript-eslint/parser": "^5.26.0", + "cross-env": "^7.0.3", "cypress": "^9.7.0", "eslint": "^8.16.0", "eslint-plugin-react": "^7.30.0", @@ -3984,6 +3985,24 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "node_modules/cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "bin": { + "cross-env": "src/bin/cross-env.js", + "cross-env-shell": "src/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=10.14", + "npm": ">=6", + "yarn": ">=1" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -17071,6 +17090,15 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "requires": { + "cross-spawn": "^7.0.1" + } + }, "cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", diff --git a/package.json b/package.json index 09b6c017d..4e8004128 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,13 @@ "scripts": { "build": "remix build", "deploy": "fly deploy --remote-only", - "dev": "remix dev", + "dev": "cross-env NODE_ENV=dev remix dev", + "dev:cypress": "cross-env NODE_ENV=test PORT=4455 remix dev", "start": "remix-serve build", "migrate": "node ./migrations/index.mjs", "migrate:reset": "node scripts/delete-db-files.mjs && npm run migrate", "seed": "node --experimental-specifier-resolution=node --loader ts-node/esm -r tsconfig-paths/register scripts/seed.ts", + "seed:cypress": "cross-env NODE_ENV=test npm run seed", "lint:ts": "eslint . --ext .ts,.tsx", "lint:styles": "stylelint \"app/styles/**/*.css\"", "lf": "npm run typecheck && npm run lint:styles -- --fix && npm run lint:ts -- --fix && npm run prettier:write", @@ -18,6 +20,7 @@ "typecheck": "tsc --noEmit", "test:unit": "uvu -r tsm -r tsconfig-paths/register -i cypress", "cy:open": "cypress open", + "cy:run": "cypress run", "checks": "npm run lint:styles && npm run lint:ts && npm run prettier:check && npm run typecheck" }, "dependencies": { @@ -48,6 +51,7 @@ "@types/react-dom": "^18.0.5", "@typescript-eslint/eslint-plugin": "^5.26.0", "@typescript-eslint/parser": "^5.26.0", + "cross-env": "^7.0.3", "cypress": "^9.7.0", "eslint": "^8.16.0", "eslint-plugin-react": "^7.30.0",