From 5b9f0707b85de2f9c151f2021217bfefc4695425 Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Tue, 27 Feb 2024 21:41:34 -0800 Subject: [PATCH 1/7] install cypress and add initial test --- .gitignore | 1 + cypress.config.ts | 7 + cypress/e2e/login.cy.ts | 12 + cypress/support/e2e.ts | 5 + cypress/support/index.d.ts | 11 + cypress/tsconfig.json | 8 + package.json | 4 +- src/app/login/LoginForm.tsx | 19 +- src/components/input/ProfileButton.tsx | 4 +- yarn.lock | 717 ++++++++++++++++++++++++- 10 files changed, 768 insertions(+), 20 deletions(-) create mode 100644 cypress.config.ts create mode 100644 cypress/e2e/login.cy.ts create mode 100644 cypress/support/e2e.ts create mode 100644 cypress/support/index.d.ts create mode 100644 cypress/tsconfig.json diff --git a/.gitignore b/.gitignore index 050397c9..8f39d0f1 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ yarn-error.log* # local env files .env .env.* +*.env.* *.dev.yml diff --git a/cypress.config.ts b/cypress.config.ts new file mode 100644 index 00000000..5bed49b8 --- /dev/null +++ b/cypress.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'cypress'; + +export default defineConfig({ + e2e: { + baseUrl: 'http://localhost:3000', + }, +}); diff --git a/cypress/e2e/login.cy.ts b/cypress/e2e/login.cy.ts new file mode 100644 index 00000000..f0490560 --- /dev/null +++ b/cypress/e2e/login.cy.ts @@ -0,0 +1,12 @@ +describe('Login test', () => { + it('logs user in with correct credentials and logs user out', () => { + cy.visit('/login'); + cy.dataCy('input-username').type(Cypress.env('umami_user')); + cy.dataCy('input-password').type(Cypress.env('umami_password')); + cy.dataCy('button-submit').click(); + cy.url().should('eq', Cypress.config().baseUrl + '/dashboard'); + cy.dataCy('button-profile').click(); + cy.dataCy('item-logout').click(); + cy.url().should('eq', Cypress.config().baseUrl + '/login'); + }); +}); diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts new file mode 100644 index 00000000..2ee2ed8e --- /dev/null +++ b/cypress/support/e2e.ts @@ -0,0 +1,5 @@ +/// + +Cypress.Commands.add('dataCy', value => { + return cy.get(`[data-cy=${value}]`); +}); diff --git a/cypress/support/index.d.ts b/cypress/support/index.d.ts new file mode 100644 index 00000000..da94c844 --- /dev/null +++ b/cypress/support/index.d.ts @@ -0,0 +1,11 @@ +/// + +declare namespace Cypress { + interface Chainable { + /** + * Custom command to select DOM element by data-cy attribute. + * @example cy.dataCy('greeting') + */ + dataCy(value: string): Chainable>; + } +} diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json new file mode 100644 index 00000000..18edb199 --- /dev/null +++ b/cypress/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": ["es5", "dom"], + "types": ["cypress", "node"] + }, + "include": ["**/*.ts"] +} diff --git a/package.json b/package.json index 4a38c4e8..422bb475 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,8 @@ "change-password": "node scripts/change-password.js", "lint": "next lint --quiet", "prepare": "node -e \"if (process.env.NODE_ENV !== 'production'){process.exit(1)} \" || husky install", - "postbuild": "node scripts/postbuild.js" + "postbuild": "node scripts/postbuild.js", + "cypress-open": "cypress open" }, "lint-staged": { "**/*.{js,jsx,ts,tsx}": [ @@ -133,6 +134,7 @@ "@typescript-eslint/eslint-plugin": "^6.7.3", "@typescript-eslint/parser": "^6.7.3", "cross-env": "^7.0.3", + "cypress": "^13.6.6", "esbuild": "^0.17.17", "eslint": "^8.33.0", "eslint-config-next": "^14.0.4", diff --git a/src/app/login/LoginForm.tsx b/src/app/login/LoginForm.tsx index 28d79458..03192413 100644 --- a/src/app/login/LoginForm.tsx +++ b/src/app/login/LoginForm.tsx @@ -42,17 +42,30 @@ export function LoginForm() {
umami
- + - + - + {formatMessage(labels.login)} diff --git a/src/components/input/ProfileButton.tsx b/src/components/input/ProfileButton.tsx index 11cf1613..4b3c3f7b 100644 --- a/src/components/input/ProfileButton.tsx +++ b/src/components/input/ProfileButton.tsx @@ -25,7 +25,7 @@ export function ProfileButton() { return ( - - - {(close: () => void) => ( - - )} - - - - )} + + + + + {(close: () => void) => ( + + )} + + + Date: Wed, 28 Feb 2024 12:40:23 -0800 Subject: [PATCH 5/7] add orderBy --- src/pages/api/teams/[teamId]/websites/index.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/pages/api/teams/[teamId]/websites/index.ts b/src/pages/api/teams/[teamId]/websites/index.ts index e4919d20..dd2fdeff 100644 --- a/src/pages/api/teams/[teamId]/websites/index.ts +++ b/src/pages/api/teams/[teamId]/websites/index.ts @@ -43,13 +43,7 @@ export default async ( return unauthorized(res); } - const { page, query, pageSize } = req.query; - - const websites = await getTeamWebsites(teamId, { - page, - query, - pageSize, - }); + const websites = await getTeamWebsites(teamId, req.query); return ok(res, websites); } From 44d8606d1aa2e8e059e97e26fc0a6e6fbfd6457b Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Wed, 28 Feb 2024 15:01:13 -0800 Subject: [PATCH 6/7] add cypress docker compose file --- .../cypress.config.ts | 4 ++ cypress/docker-compose.yml | 47 +++++++++++++++++++ cypress/e2e/login.cy.ts | 26 ++++++---- package.json | 3 +- 4 files changed, 69 insertions(+), 11 deletions(-) rename cypress.config.ts => cypress/cypress.config.ts (63%) create mode 100644 cypress/docker-compose.yml diff --git a/cypress.config.ts b/cypress/cypress.config.ts similarity index 63% rename from cypress.config.ts rename to cypress/cypress.config.ts index 5bed49b8..c52aeb49 100644 --- a/cypress.config.ts +++ b/cypress/cypress.config.ts @@ -4,4 +4,8 @@ export default defineConfig({ e2e: { baseUrl: 'http://localhost:3000', }, + env: { + umami_user: 'admin', + umami_password: 'pennydoodoo', + }, }); diff --git a/cypress/docker-compose.yml b/cypress/docker-compose.yml new file mode 100644 index 00000000..8ce1c938 --- /dev/null +++ b/cypress/docker-compose.yml @@ -0,0 +1,47 @@ +--- +version: '3' +services: + umami: + image: ghcr.io/umami-software/umami:postgresql-latest + ports: + - '3000:3000' + environment: + DATABASE_URL: postgresql://umami:umami@db:5432/umami + DATABASE_TYPE: postgresql + APP_SECRET: replace-me-with-a-random-string + depends_on: + db: + condition: service_healthy + restart: always + healthcheck: + test: ['CMD-SHELL', 'curl http://localhost:3000/api/heartbeat'] + interval: 5s + timeout: 5s + retries: 5 + db: + image: postgres:15-alpine + environment: + POSTGRES_DB: umami + POSTGRES_USER: umami + POSTGRES_PASSWORD: umami + volumes: + - umami-db-data:/var/lib/postgresql/data + restart: always + healthcheck: + test: ['CMD-SHELL', 'pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}'] + interval: 5s + timeout: 5s + retries: 5 + cypress: + image: 'cypress/included:13.6.0' + depends_on: + - umami + - db + environment: + - CYPRESS_baseUrl=http://localhost:3000 + entrypoint: /bin/sh -c "yarn install" + working_dir: /cypress + volumes: + - ./:/cypress +volumes: + umami-db-data: diff --git a/cypress/e2e/login.cy.ts b/cypress/e2e/login.cy.ts index f0490560..4bd6a6b7 100644 --- a/cypress/e2e/login.cy.ts +++ b/cypress/e2e/login.cy.ts @@ -1,12 +1,18 @@ describe('Login test', () => { - it('logs user in with correct credentials and logs user out', () => { - cy.visit('/login'); - cy.dataCy('input-username').type(Cypress.env('umami_user')); - cy.dataCy('input-password').type(Cypress.env('umami_password')); - cy.dataCy('button-submit').click(); - cy.url().should('eq', Cypress.config().baseUrl + '/dashboard'); - cy.dataCy('button-profile').click(); - cy.dataCy('item-logout').click(); - cy.url().should('eq', Cypress.config().baseUrl + '/login'); - }); + it( + 'logs user in with correct credentials and logs user out', + { + defaultCommandTimeout: 10000, + }, + () => { + cy.visit('/login'); + cy.dataCy('input-username').type(Cypress.env('umami_user')); + cy.dataCy('input-password').type(Cypress.env('umami_password')); + cy.dataCy('button-submit').click(); + cy.url().should('eq', Cypress.config().baseUrl + '/dashboard'); + cy.dataCy('button-profile').click(); + cy.dataCy('item-logout').click(); + cy.url().should('eq', Cypress.config().baseUrl + '/login'); + }, + ); }); diff --git a/package.json b/package.json index 24946e3f..16658e2e 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,8 @@ "lint": "next lint --quiet", "prepare": "node -e \"if (process.env.NODE_ENV !== 'production'){process.exit(1)} \" || husky install", "postbuild": "node scripts/postbuild.js", - "cypress-open": "cypress open" + "cypress-open": "cypress open cypress run --config-file cypress/cypress.config.ts", + "cypress-run": "cypress run cypress run --config-file cypress/cypress.config.ts" }, "lint-staged": { "**/*.{js,jsx,ts,tsx}": [ From 14c0c5060ad1f3556b1665f077406c6a58010b33 Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Wed, 28 Feb 2024 16:29:35 -0800 Subject: [PATCH 7/7] working compose file for cypress --- cypress/cypress.config.ts => cypress.config.ts | 4 ---- cypress/docker-compose.yml | 12 ++++++++---- cypress/tsconfig.json | 2 +- package.json | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) rename cypress/cypress.config.ts => cypress.config.ts (63%) diff --git a/cypress/cypress.config.ts b/cypress.config.ts similarity index 63% rename from cypress/cypress.config.ts rename to cypress.config.ts index c52aeb49..5bed49b8 100644 --- a/cypress/cypress.config.ts +++ b/cypress.config.ts @@ -4,8 +4,4 @@ export default defineConfig({ e2e: { baseUrl: 'http://localhost:3000', }, - env: { - umami_user: 'admin', - umami_password: 'pennydoodoo', - }, }); diff --git a/cypress/docker-compose.yml b/cypress/docker-compose.yml index 8ce1c938..3cd8f546 100644 --- a/cypress/docker-compose.yml +++ b/cypress/docker-compose.yml @@ -2,7 +2,8 @@ version: '3' services: umami: - image: ghcr.io/umami-software/umami:postgresql-latest + build: ../ + #image: ghcr.io/umami-software/umami:postgresql-latest ports: - '3000:3000' environment: @@ -38,10 +39,13 @@ services: - umami - db environment: - - CYPRESS_baseUrl=http://localhost:3000 - entrypoint: /bin/sh -c "yarn install" - working_dir: /cypress + - CYPRESS_baseUrl=http://umami:3000 + - CYPRESS_umami_user=admin + - CYPRESS_umami_password=umami volumes: + - ../tsconfig.json:/tsconfig.json + - ../cypress.config.ts:/cypress.config.ts - ./:/cypress + - ../node_modules/:/node_modules volumes: umami-db-data: diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json index 18edb199..48c3e14e 100644 --- a/cypress/tsconfig.json +++ b/cypress/tsconfig.json @@ -4,5 +4,5 @@ "lib": ["es5", "dom"], "types": ["cypress", "node"] }, - "include": ["**/*.ts"] + "include": ["**/*.ts", "../cypress.config.ts"] } diff --git a/package.json b/package.json index 16658e2e..895ff334 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,8 @@ "lint": "next lint --quiet", "prepare": "node -e \"if (process.env.NODE_ENV !== 'production'){process.exit(1)} \" || husky install", "postbuild": "node scripts/postbuild.js", - "cypress-open": "cypress open cypress run --config-file cypress/cypress.config.ts", - "cypress-run": "cypress run cypress run --config-file cypress/cypress.config.ts" + "cypress-open": "cypress open cypress run", + "cypress-run": "cypress run cypress run" }, "lint-staged": { "**/*.{js,jsx,ts,tsx}": [