From 670a38349d978d41f78812595e899259d313d554 Mon Sep 17 00:00:00 2001 From: david-yz-liu Date: Sat, 14 Nov 2026 12:15:12 -0500 Subject: [PATCH 1/2] Updated Cypress to 14.5.4 and fixed end-to-end tests - Migrated the legacy cypress.json config (unsupported since Cypress 10) to cypress.config.js - Updated outdated test IDs (course codes now have session suffixes, e.g. csc209h1) and graph structure - Looked up hybrid edge IDs at runtime, since they are database-generated - Added a support file that hides the disclaimer popup, which blocked interactions - Added missing cy.visit for test isolation, and aligned overridden-prereq hover assertions with Node.test.js - Added cypress:run/cypress:open scripts and README instructions Co-Authored-By: Claude Opus 5.5 --- .gitignore | 3 +- CHANGELOG.md | 1 + README.md | 14 +++ cypress.config.js | 9 ++ cypress.json | 4 - cypress/integration/graph_spec/bool_spec.js | 32 +++--- cypress/integration/graph_spec/edge_spec.js | 110 ++++++++++-------- cypress/integration/graph_spec/graph_spec.js | 48 ++++---- cypress/integration/graph_spec/node_spec.js | 113 ++++++++++--------- cypress/support/e2e.js | 4 + eslint.config.cjs | 1 + package.json | 4 +- pnpm-lock.yaml | 50 +++++--- 13 files changed, 226 insertions(+), 167 deletions(-) create mode 100644 cypress.config.js delete mode 100644 cypress.json create mode 100644 cypress/support/e2e.js diff --git a/.gitignore b/.gitignore index f70cb4297..fef0da543 100644 --- a/.gitignore +++ b/.gitignore @@ -56,7 +56,8 @@ coverage /cypress/fixtures /cypress/integration/examples /cypress/plugins -/cypress/support +/cypress/screenshots +/cypress/videos # Python virtual environment venv diff --git a/CHANGELOG.md b/CHANGELOG.md index 57336e6a0..98b566e70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ ### 🔧 Internal changes +- Updated Cypress to 14.5.4, migrated `cypress.json` to `cypress.config.js`, fixed outdated end-to-end tests, and added `cypress:run`/`cypress:open` scripts and README instructions for running them - Added test coverage for `CampusMap` component (7 test cases covering rendering, markers, and zoom functionality) - Simplified timetable availability check in `Description.tsx` by removing redundant `Object.keys(sessions).length !== 0` condition - Updated OpenStreetMap tile layer URL from HTTP to HTTPS in `CampusMap.tsx` for improved security diff --git a/README.md b/README.md index 74bf299bc..92e6fdd3a 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,20 @@ Run `$ pnpm run typecheck`, which uses [Typescript](https://www.typescriptlang.o To run all tests, run `$ pnpm test`. However, if you need to run a specific file or folder of tests, run `$ pnpm test -- `. +#### Running end-to-end tests + +We use [Cypress](https://www.cypress.io/) for end-to-end tests that run against the full app in a browser. The tests are in `cypress/integration/`. + +1. Make sure the database is populated (see [Parsing and Generation](#parsing-and-generation)) and start the app (see [Running](#running)). The tests expect the server at `http://localhost:8000`. +2. In a new terminal window, run one of: + - `$ pnpm run cypress:run` to run all tests headlessly in the terminal. + - `$ pnpm run cypress:run --spec ` to run a specific test file (e.g., `cypress/integration/graph_spec/node_spec.js`). + - `$ pnpm run cypress:open` to open the interactive Cypress app, where you can pick tests to run and watch them in the browser. + +Screenshots of failing tests are saved to `cypress/screenshots/`. + +**Note:** If Cypress fails to start with `bad option: --smoke-test`, your terminal has the `ELECTRON_RUN_AS_NODE` environment variable set (VS Code's integrated terminal can do this). Unset it first, e.g. `$ env -u ELECTRON_RUN_AS_NODE pnpm run cypress:run`. + #### Running back-end tests To run all tests, run `$ stack test`. To run a specific test group or test case, run `stack test --ta '-p ""'`. diff --git a/cypress.config.js b/cypress.config.js new file mode 100644 index 000000000..9b33083d3 --- /dev/null +++ b/cypress.config.js @@ -0,0 +1,9 @@ +const { defineConfig } = require("cypress") + +module.exports = defineConfig({ + e2e: { + baseUrl: "http://localhost:8000", + specPattern: "cypress/integration/**/*_spec.js", + excludeSpecPattern: "**/examples/*.js", + }, +}) diff --git a/cypress.json b/cypress.json deleted file mode 100644 index df540f818..000000000 --- a/cypress.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "baseUrl": "http://localhost:8000", - "ignoreTestFiles": ["/**/examples/*.js"] -} diff --git a/cypress/integration/graph_spec/bool_spec.js b/cypress/integration/graph_spec/bool_spec.js index b186c569b..a9c5b4f4a 100644 --- a/cypress/integration/graph_spec/bool_spec.js +++ b/cypress/integration/graph_spec/bool_spec.js @@ -4,36 +4,36 @@ describe("Boolean tests", () => { }) it("should initially be 'bool' and 'inactive'", () => { - cy.get('[data-testid="and(csc209,csc258)"]') + cy.get('[data-testid="and(csc209h1,csc258h1)"]') .should("have.class", "bool") .should("have.class", "inactive") }) it("shouldn't do anything when you click or hover over it", () => { - cy.get('[data-testid="and(csc209,csc258)"]') + cy.get('[data-testid="and(csc209h1,csc258h1)"]') .should("have.class", "bool") .should("have.class", "inactive") - cy.get('[data-testid="and(csc209,csc258)"]').click() - cy.get('[data-testid="and(csc209,csc258)"]') + cy.get('[data-testid="and(csc209h1,csc258h1)"]').click() + cy.get('[data-testid="and(csc209h1,csc258h1)"]') .should("have.class", "bool") .should("have.class", "inactive") - cy.get('[data-testid="and(csc209,csc258)"]').trigger("mouseover") - cy.get('[data-testid="and(csc209,csc258)"]') + cy.get('[data-testid="and(csc209h1,csc258h1)"]').trigger("mouseover") + cy.get('[data-testid="and(csc209h1,csc258h1)"]') .should("have.class", "bool") .should("have.class", "inactive") }) it("AND should be 'active' when prereq parents are met", () => { - cy.get('[data-testid="and(csc209,csc258)"]').contains("and") - cy.get('[data-testid="csc258"]').click() - cy.get('[data-testid="csc209"]').click() - cy.get('[data-testid="and(csc209,csc258)"]').should("have.class", "active") - cy.get('[data-testid="csc367"]').should("have.class", "takeable") + cy.get('[data-testid="and(csc209h1,csc258h1)"]').contains("and") + cy.get('[data-testid="csc258h1"]').click() + cy.get('[data-testid="csc209h1"]').click() + cy.get('[data-testid="and(csc209h1,csc258h1)"]').should("have.class", "active") + cy.get('[data-testid="csc367h1"]').should("have.class", "takeable") }) it("OR should be 'active' when 1+ of the prereq parents are met", () => { - cy.get('[data-testid="and(csc463,csc373)"]').contains("or") - cy.get('[data-testid="csc373"]').click() - cy.get('[data-testid="csc463"]').click() - cy.get('[data-testid="and(csc463,csc373)"]').should("have.class", "active") - cy.get('[data-testid="csc438"]').should("have.class", "takeable") + cy.get('[data-testid="and(csc373h1,csc463h1)"]').contains("or") + cy.get('[data-testid="csc373h1"]').click() + cy.get('[data-testid="csc463h1"]').click() + cy.get('[data-testid="and(csc373h1,csc463h1)"]').should("have.class", "active") + cy.get('[data-testid="csc438h1"]').should("have.class", "takeable") }) }) diff --git a/cypress/integration/graph_spec/edge_spec.js b/cypress/integration/graph_spec/edge_spec.js index 7655a57c9..d0dd19bc0 100644 --- a/cypress/integration/graph_spec/edge_spec.js +++ b/cypress/integration/graph_spec/edge_spec.js @@ -1,98 +1,110 @@ +// Edges out of hybrid nodes use the hybrid's database-generated id (e.g. "h3586->csc456h1"), +// which isn't stable across databases, so look it up from the hybrid node at runtime. +const hybridEdge = (hybridTestId, target) => + cy + .get(`[data-testid="${hybridTestId}"]`) + .invoke("attr", "id") + .then(id => cy.get(`[data-testid="${id}->${target}"]`)) + +// h(csc209h1) is the hybrid node for CSC209H1, a prereq of CSC456H1 +const SOURCE = "csc209h1" +const HYBRID = "h(csc209h1)" +const DEST = "csc456h1" +const edge = () => hybridEdge(HYBRID, DEST) + describe("Edge", () => { beforeEach(() => { cy.visit("/graph") }) describe("Clicking course nodes", () => { it("unselected source and destination => 'inactive' Edge", () => { - cy.get('[data-testid="csc108->csc148"]').should("have.class", "inactive") + cy.get('[data-testid="csc108h1->csc148h1"]').should("have.class", "inactive") }) it("with selected source and unselected destination => 'takeable' Edge", () => { - cy.get('[data-testid="csc108"]').click() - cy.get('[data-testid="csc108->csc148"]').should("have.class", "takeable") + cy.get('[data-testid="csc108h1"]').click() + cy.get('[data-testid="csc108h1->csc148h1"]').should("have.class", "takeable") }) it("with unselected source with selected destination => 'inactive' Edge", () => { - cy.get('[data-testid="csc148"]').click() - cy.get('[data-testid="csc108->csc148"]').should("have.class", "inactive") + cy.get('[data-testid="csc148h1"]').click() + cy.get('[data-testid="csc108h1->csc148h1"]').should("have.class", "inactive") }) it("with selected source and destination => 'active' Edge", () => { - cy.get('[data-testid="csc108"]').click() - cy.get('[data-testid="csc148"]').click() - cy.get('[data-testid="csc108->csc148"]').should("have.class", "active") + cy.get('[data-testid="csc108h1"]').click() + cy.get('[data-testid="csc148h1"]').click() + cy.get('[data-testid="csc108h1->csc148h1"]').should("have.class", "active") }) }) describe("hovering behaviour", () => { describe("hovering over source does nothing", () => { it("hovered and unselected source and unselected destination => stays 'inactive'", () => { - cy.get('[data-testid="h62->csc343"]').should("have.class", "inactive") - cy.get('[data-testid="csc111"]').trigger("mouseout") - cy.get('[data-testid="h62->csc343"]').should("have.class", "inactive") + edge().should("have.class", "inactive") + cy.get(`[data-testid="${SOURCE}"]`).trigger("mouseout") + edge().should("have.class", "inactive") }) it("hovered and selected source and unselected destination => stays 'takeable'", () => { - cy.get('[data-testid="csc111"]').click() - cy.get('[data-testid="h62->csc343"]').should("have.class", "takeable") - cy.get('[data-testid="csc111"]').trigger("mouseover") - cy.get('[data-testid="h62->csc343"]').should("have.class", "takeable") + cy.get(`[data-testid="${SOURCE}"]`).click() + edge().should("have.class", "takeable") + cy.get(`[data-testid="${SOURCE}"]`).trigger("mouseover") + edge().should("have.class", "takeable") }) it("hovered and unselected source and selected destination => stays 'active'", () => { - cy.get('[data-testid="csc343"]').click() - cy.get('[data-testid="h62->csc343"]').should("have.class", "inactive") - cy.get('[data-testid="csc111"]').trigger("mouseover") - cy.get('[data-testid="h62->csc343"]').should("have.class", "inactive") + cy.get(`[data-testid="${DEST}"]`).click() + edge().should("have.class", "inactive") + cy.get(`[data-testid="${SOURCE}"]`).trigger("mouseover") + edge().should("have.class", "inactive") }) it("(hovered and selected source) and selected destination => stays 'active'", () => { - cy.get('[data-testid="csc111"]').click() - cy.get('[data-testid="csc343"]').click() - cy.get('[data-testid="h62->csc343"]').should("have.class", "active") - cy.get('[data-testid="csc111"]').trigger("mouseover") - cy.get('[data-testid="h62->csc343"]').should("have.class", "active") + cy.get(`[data-testid="${SOURCE}"]`).click() + cy.get(`[data-testid="${DEST}"]`).click() + edge().should("have.class", "active") + cy.get(`[data-testid="${SOURCE}"]`).trigger("mouseover") + edge().should("have.class", "active") }) }) }) describe("hovering over destination", () => { it("unselected source and (unselected and hovered destination) => edge should transition from 'inactive' to 'missing'", () => { - cy.get('[data-testid="h62->csc343"]').should("have.class", "inactive") - cy.get('[data-testid="csc343"]').trigger("mouseover") - cy.get('[data-testid="h62->csc343"]').should("have.class", "missing") + edge().should("have.class", "inactive") + cy.get(`[data-testid="${DEST}"]`).trigger("mouseover") + edge().should("have.class", "missing") }) it("selected source and (unselected and hovered destination) => edge remains 'takeable'", () => { - cy.get('[data-testid="csc111"]').click() - cy.get('[data-testid="h62->csc343"]').should("have.class", "takeable") - cy.get('[data-testid="csc343"]').trigger("mouseover") - cy.get('[data-testid="h62->csc343"]').should("have.class", "takeable") + cy.get(`[data-testid="${SOURCE}"]`).click() + edge().should("have.class", "takeable") + cy.get(`[data-testid="${DEST}"]`).trigger("mouseover") + edge().should("have.class", "takeable") }) it("unselected source and (selected and hovered destination) => edge should transition to inactive 'missing'", () => { - cy.get('[data-testid="csc343"]').click() - cy.get('[data-testid="h62->csc343"]').should("have.class", "inactive") - cy.get('[data-testid="csc343"]').trigger("mouseover") - cy.get('[data-testid="h62->csc343"]').should("have.class", "missing") + cy.get(`[data-testid="${DEST}"]`).click() + edge().should("have.class", "inactive") + cy.get(`[data-testid="${DEST}"]`).trigger("mouseover") + edge().should("have.class", "missing") }) it("unselected source and (selected and hovered destination) => edge and all unmet and inactive prereqs should be 'missing'", () => { - // selected node with missing prereqs - cy.get('[data-testid="csc443"]').click() + // selected node with missing prereqs: CSC443H1 <- CSC209H1 <- CSC207H1 + cy.get('[data-testid="csc443h1"]').click().trigger("mouseout") - cy.get('[data-testid="h62->csc343"]').should("have.class", "inactive") - cy.get('[data-testid="csc343->csc443"]').should("have.class", "inactive") - cy.get('[data-testid="csc207->csc343"]').should("have.class", "inactive") + cy.get('[data-testid="csc209h1->csc443h1"]').should("have.class", "inactive") + cy.get('[data-testid="csc207h1->csc209h1"]').should("have.class", "inactive") - cy.get('[data-testid="csc443"]').trigger("mouseover") - cy.get('[data-testid="h62->csc343"]').should("have.class", "missing") - cy.get('[data-testid="csc343->csc443"]').should("have.class", "missing") - cy.get('[data-testid="csc207->csc343"]').should("have.class", "missing") + cy.get('[data-testid="csc443h1"]').trigger("mouseover") + cy.get('[data-testid="csc209h1->csc443h1"]').should("have.class", "missing") + cy.get('[data-testid="csc207h1->csc209h1"]').should("have.class", "missing") }) it("selected source and selected destination, hovering over the destination will have the Edge remain 'active'", () => { - cy.get('[data-testid="csc111"]').click() - cy.get('[data-testid="csc343"]').click() - cy.get('[data-testid="h62->csc343"]').should("have.class", "active") - cy.get('[data-testid="csc343"]').trigger("mouseover") - cy.get('[data-testid="h62->csc343"]').should("have.class", "active") + cy.get(`[data-testid="${SOURCE}"]`).click() + cy.get(`[data-testid="${DEST}"]`).click() + edge().should("have.class", "active") + cy.get(`[data-testid="${DEST}"]`).trigger("mouseover") + edge().should("have.class", "active") }) }) }) diff --git a/cypress/integration/graph_spec/graph_spec.js b/cypress/integration/graph_spec/graph_spec.js index 55b2da5ec..cf346e6fd 100644 --- a/cypress/integration/graph_spec/graph_spec.js +++ b/cypress/integration/graph_spec/graph_spec.js @@ -5,51 +5,51 @@ describe("Graph", () => { describe("Boolean tests", () => { it("should initially be 'bool' and 'inactive'", () => { - cy.get(`[data-testid="and(csc209,csc258)"]`) + cy.get(`[data-testid="and(csc209h1,csc258h1)"]`) .should("have.class", "bool") .should("have.class", "inactive") }) it("shouldn't do anything when you click or hover over it", () => { - cy.get(`[data-testid="and(csc209,csc258)"]`) + cy.get(`[data-testid="and(csc209h1,csc258h1)"]`) .should("have.class", "bool") .should("have.class", "inactive") - cy.get(`[data-testid="and(csc209,csc258)"]`).click() - cy.get(`[data-testid="and(csc209,csc258)"]`) + cy.get(`[data-testid="and(csc209h1,csc258h1)"]`).click() + cy.get(`[data-testid="and(csc209h1,csc258h1)"]`) .should("have.class", "bool") .should("have.class", "inactive") - cy.get(`[data-testid="and(csc209,csc258)"]`).trigger("mouseover") - cy.get(`[data-testid="and(csc209,csc258)"]`) + cy.get(`[data-testid="and(csc209h1,csc258h1)"]`).trigger("mouseover") + cy.get(`[data-testid="and(csc209h1,csc258h1)"]`) .should("have.class", "bool") .should("have.class", "inactive") }) it("AND should be 'active' when prereq parents are met", () => { - cy.get(`[data-testid="and(csc209,csc258)"]`).contains("and") - cy.get(`[data-testid="csc258"]`).click() - cy.get(`[data-testid="csc209"]`).click() - cy.get(`[data-testid="and(csc209,csc258)"]`).should("have.class", "active") - cy.get(`[data-testid="csc367"]`).should("have.class", "takeable") + cy.get(`[data-testid="and(csc209h1,csc258h1)"]`).contains("and") + cy.get(`[data-testid="csc258h1"]`).click() + cy.get(`[data-testid="csc209h1"]`).click() + cy.get(`[data-testid="and(csc209h1,csc258h1)"]`).should("have.class", "active") + cy.get(`[data-testid="csc367h1"]`).should("have.class", "takeable") }) it("OR should be 'active' when 1+ of the prereq parents are met", () => { - cy.get(`[data-testid="and(csc463,csc373)"]`).contains("or") - cy.get(`[data-testid="csc373"]`).click() - cy.get(`[data-testid="csc463"]`).click() - cy.get(`[data-testid="and(csc463,csc373)"]`).should("have.class", "active") - cy.get(`[data-testid="csc438"]`).should("have.class", "takeable") + cy.get(`[data-testid="and(csc373h1,csc463h1)"]`).contains("or") + cy.get(`[data-testid="csc373h1"]`).click() + cy.get(`[data-testid="csc463h1"]`).click() + cy.get(`[data-testid="and(csc373h1,csc463h1)"]`).should("have.class", "active") + cy.get(`[data-testid="csc438h1"]`).should("have.class", "takeable") }) }) it("'missing' class when the mouse is hovering over a child class", () => { - cy.get(`[data-testid="csc458"]`).trigger("mouseover") - cy.get(`[data-testid="csc458"]`).should("have.class", "missing") - cy.get(`[data-testid='h(csc263265)']`).should("have.class", "missing") - cy.get(`[data-testid='and(csc209,csc258)']`).should("have.class", "missing") - cy.get(`[data-testid='csc209']`).should("have.class", "missing") - cy.get(`[data-testid='csc258']`).should("have.class", "missing") - cy.get(`[data-testid='csc108']`).should("have.class", "missing") + cy.get(`[data-testid="csc458h1"]`).trigger("mouseover") + cy.get(`[data-testid="csc458h1"]`).should("have.class", "missing") + cy.get(`[data-testid='h(csc263h1,csc265h1)']`).should("have.class", "missing") + cy.get(`[data-testid='and(csc209h1,csc258h1)']`).should("have.class", "missing") + cy.get(`[data-testid='csc209h1']`).should("have.class", "missing") + cy.get(`[data-testid='csc258h1']`).should("have.class", "missing") + cy.get(`[data-testid='csc108h1']`).should("have.class", "missing") // unaffected, despite sharing the same prereqs as CSC458 - cy.get(`[data-testid='csc385']`).should("have.class", "inactive") + cy.get(`[data-testid='csc385h1']`).should("have.class", "inactive") }) describe("Info Box", () => { diff --git a/cypress/integration/graph_spec/node_spec.js b/cypress/integration/graph_spec/node_spec.js index 7c2beac59..b58117aa2 100644 --- a/cypress/integration/graph_spec/node_spec.js +++ b/cypress/integration/graph_spec/node_spec.js @@ -6,12 +6,12 @@ describe("Hybrid Node", () => { cy.get("body").trigger("mouseout") }) it("should have the 'hybrid' CSS class", () => { - cy.get('[data-testid="h(csc209)"]').should("have.class", "hybrid") - cy.get('[data-testid="h(csc209)"]').should("have.class", "inactive") + cy.get('[data-testid="h(csc209h1)"]').should("have.class", "hybrid") + cy.get('[data-testid="h(csc209h1)"]').should("have.class", "inactive") }) it("shouldn't do anything when you hover or click it", () => { - cy.get('[data-testid="h(csc209)"]').should("have.class", "inactive") - cy.get('[data-testid="h(csc209)"]') + cy.get('[data-testid="h(csc209h1)"]').should("have.class", "inactive") + cy.get('[data-testid="h(csc209h1)"]') .click() .should("have.class", "inactive") .trigger("mouseover") @@ -20,114 +20,117 @@ describe("Hybrid Node", () => { .should("have.class", "inactive") }) it("should be 'inactive' when it's prereq parent is NOT met", () => { - cy.get('[data-testid="h(csc209)"]').should("have.class", "inactive") + cy.get('[data-testid="h(csc209h1)"]').should("have.class", "inactive") }) it("should be 'active' when its prereq parent is met", () => { - cy.get('[data-testid="csc209"]').click() - cy.get('[data-testid="h(csc209)"]').should("have.class", "active") + cy.get('[data-testid="csc209h1"]').click() + cy.get('[data-testid="h(csc209h1)"]').should("have.class", "active") }) it("should be 'missing' if not 'active' and it's an unmet prereq of the currently hovered course", () => { - cy.get('[data-testid="csc317"]').trigger("mouseover") - cy.get('[data-testid="h(csc209)"]').should("have.class", "missing") - cy.get('[data-testid="csc317"]').trigger("mouseout") + cy.get('[data-testid="csc456h1"]').trigger("mouseover") + cy.get('[data-testid="h(csc209h1)"]').should("have.class", "missing") + cy.get('[data-testid="csc456h1"]').trigger("mouseout") }) }) describe("Course Node", () => { + beforeEach(() => { + cy.visit("/graph") + }) + it("should have the CSS class: 'node'", () => { - cy.get('[data-testid="csc108"]').should("have.class", "node") + cy.get('[data-testid="csc108h1"]').should("have.class", "node") }) describe("Unselected Course Node", () => { it("should be 'takeable' if it has no prereqs", () => { - cy.get('[data-testid="csc108"]').should("have.class", "takeable") + cy.get('[data-testid="csc108h1"]').should("have.class", "takeable") }) it("should be 'inactive' if the prereqs are NOT met", () => { - cy.get('[data-testid="csc148"]').should("have.class", "inactive") + cy.get('[data-testid="csc148h1"]').should("have.class", "inactive") }) it("should be 'takeable' if the prereqs are met", () => { - cy.get('[data-testid="csc108"]').click() - cy.get('[data-testid="csc148"]').should("have.class", "takeable") + cy.get('[data-testid="csc108h1"]').click() + cy.get('[data-testid="csc148h1"]').should("have.class", "takeable") // cleanup - cy.get('[data-testid="csc108"]').click() + cy.get('[data-testid="csc108h1"]').click() }) it('should be "missing" when unselected and hovered over', () => { - cy.get('[data-testid="csc108"]').trigger("mouseover") - cy.get('[data-testid="csc108"]').should("have.class", "missing") + cy.get('[data-testid="csc108h1"]').trigger("mouseover") + cy.get('[data-testid="csc108h1"]').should("have.class", "missing") }) it("when hovered, should set all unmet prereqs and itself as 'missing'", () => { - cy.get('[data-testid="csc207"]').trigger("mouseover") - cy.get('[data-testid="csc148"]').should("have.class", "missing") - cy.get('[data-testid="csc108"]').should("have.class", "missing") + cy.get('[data-testid="csc207h1"]').trigger("mouseover") + cy.get('[data-testid="csc148h1"]').should("have.class", "missing") + cy.get('[data-testid="csc108h1"]').should("have.class", "missing") }) }) describe("Selected Course Node", () => { it("with met prereqs should 'active'", () => { - cy.get('[data-testid="csc108"]').click() - cy.get('[data-testid="csc108"]').should("have.class", "active") + cy.get('[data-testid="csc108h1"]').click() + cy.get('[data-testid="csc108h1"]').should("have.class", "active") // cleanup - cy.get('[data-testid="csc108"]').click() + cy.get('[data-testid="csc108h1"]').click() }) describe("selected course with un-met prereqs", () => { it("should be 'overridden' (if you don't hover over it)", () => { - cy.get('[data-testid="csc148"]').click() - cy.get('[data-testid="csc148"]').should("have.class", "overridden") + cy.get('[data-testid="csc148h1"]').click() + cy.get('[data-testid="csc148h1"]').should("have.class", "overridden") // cleanup - cy.get('[data-testid="csc148"]').click() + cy.get('[data-testid="csc148h1"]').click() }) it("'overridden' course counts as a satisfied prereq (acts like 'active')", () => { - cy.get('[data-testid="csc148"]').click() - cy.get('[data-testid="csc148"]').should("have.class", "overridden") - cy.get('[data-testid="csc207"]').should("have.class", "takeable") + cy.get('[data-testid="csc148h1"]').click() + cy.get('[data-testid="csc148h1"]').should("have.class", "overridden") + cy.get('[data-testid="csc207h1"]').should("have.class", "takeable") }) - it("hovering over a course with an 'overridden' prereq still marks the 'overridden' unmet prereqs as 'missing'", () => { - cy.get('[data-testid="csc148"]').click() - cy.get('[data-testid="csc207"]').trigger("mouseover") - cy.get('[data-testid="csc108"]').should("have.class", "missing") + // cy.click() leaves the mouse over the clicked node, so trigger "mouseout" after + // clicking to avoid that node's hover state affecting the assertions. + it("hovering over a course with an 'overridden' prereq does not mark the 'overridden' unmet prereqs as 'missing'", () => { + cy.get('[data-testid="csc148h1"]').click().trigger("mouseout") + cy.get('[data-testid="csc207h1"]').trigger("mouseover") + // not missing because csc148h1 is overridden + cy.get('[data-testid="csc108h1"]').should("have.class", "takeable") }) it("hovering over the child of an 'active' course will ignore any unmet ancestor courses", () => { - cy.get('[data-testid="csc148"]').click() - cy.get('[data-testid="csc207"]').click() - cy.get('[data-testid="csc207"]').trigger("mouseover") - cy.get('[data-testid="csc108"]').should("have.class", "missing") - - // cleanup - cy.get('[data-testid="csc148"]').click() - cy.get('[data-testid="csc207"]').click() + cy.get('[data-testid="csc148h1"]').click().trigger("mouseout") + cy.get('[data-testid="csc207h1"]').click().trigger("mouseout") + cy.get('[data-testid="csc207h1"]').trigger("mouseover") + cy.get('[data-testid="csc108h1"]').should("have.class", "takeable") }) it("'missing' class when the mouse is hovering over a child class", () => { - cy.get('[data-testid="csc458"]') + cy.get('[data-testid="csc458h1"]') .trigger("mouseover") .should("have.class", "missing") - cy.get('[data-testid="h(csc263265)"]').should("have.class", "missing") - cy.get('[data-testid="and(csc209,csc258)"]').should("have.class", "missing") - cy.get('[data-testid="csc209"]').should("have.class", "missing") - cy.get('[data-testid="csc258"]').should("have.class", "missing") - cy.get('[data-testid="csc108"]').should("have.class", "missing") + cy.get('[data-testid="h(csc263h1,csc265h1)"]').should("have.class", "missing") + cy.get('[data-testid="and(csc209h1,csc258h1)"]').should("have.class", "missing") + cy.get('[data-testid="csc209h1"]').should("have.class", "missing") + cy.get('[data-testid="csc258h1"]').should("have.class", "missing") + cy.get('[data-testid="csc108h1"]').should("have.class", "missing") // unaffected, despite sharing the same prereqs as CSC458 - cy.get('[data-testid="csc385"]').should("have.class", "inactive") + cy.get('[data-testid="csc385h1"]').should("have.class", "inactive") // cleanup - cy.get('[data-testid="csc148"]').click() + cy.get('[data-testid="csc148h1"]').click() }) it("selected + hovered over + unmet prereqs: 'missing'", () => { - cy.get('[data-testid="csc324"]').click() - cy.get('[data-testid="csc324"]').should("have.class", "overridden") + cy.get('[data-testid="csc324h1"]').click() + cy.get('[data-testid="csc324h1"]').should("have.class", "overridden") - cy.get('[data-testid="csc324"]').trigger("mouseover") - cy.get('[data-testid="csc324"]').should("have.class", "missing") + cy.get('[data-testid="csc324h1"]').trigger("mouseover") + cy.get('[data-testid="csc324h1"]').should("have.class", "missing") // cleanup - cy.get('[data-testid="csc324"]').click() + cy.get('[data-testid="csc324h1"]').click() }) }) }) diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js new file mode 100644 index 000000000..55c81ead7 --- /dev/null +++ b/cypress/support/e2e.js @@ -0,0 +1,4 @@ +// Hide the disclaimer popup, which otherwise covers part of the graph and blocks interactions +Cypress.on("window:before:load", win => { + win.localStorage.setItem("hide-disclaimer", "true") +}) diff --git a/eslint.config.cjs b/eslint.config.cjs index f40113dfb..5a715f2e8 100644 --- a/eslint.config.cjs +++ b/eslint.config.cjs @@ -72,6 +72,7 @@ module.exports = [ languageOptions: { globals: { cy: "readonly", + Cypress: "readonly", }, }, }, diff --git a/package.json b/package.json index f2564927e..23e6b1f9e 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,8 @@ "watch": "webpack --watch --config webpack.dev.js --disable-interpret", "build": "cross-env NODE_ENV=production webpack --config webpack.prod.js --disable-interpret", "test": "jest", + "cypress:open": "cypress open --e2e", + "cypress:run": "cypress run --e2e", "typecheck": "tsc", "prettier": "prettier --write .", "eslint": "eslint --fix js", @@ -75,7 +77,7 @@ "babel-plugin-polyfill-corejs3": "^1.0.0", "cross-env": "^10.1.0", "css-loader": "^7.1.4", - "cypress": "14.0.1", + "cypress": "14.5.4", "eslint": "^10.8.0", "eslint-config-prettier": "^10.1.8", "eslint-plugin-prettier": "5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 53a0d7389..494624a5e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -144,8 +144,8 @@ importers: specifier: ^7.1.4 version: 7.1.5(webpack@5.112.2) cypress: - specifier: 14.0.1 - version: 14.0.1 + specifier: 14.5.4 + version: 14.5.4 eslint: specifier: ^10.8.0 version: 10.14.0(supports-color@8.1.1) @@ -922,10 +922,6 @@ packages: '@cacheable/utils@2.5.0': resolution: {integrity: sha512-buipgOVDkkPXNR5+xBpDw7Zk2n1EvU7qBJCNUcL7rhQ//kfpOXPAvQ511Os0vpLYJ1pZnvudNytkQt2hst3wqA==} - '@colors/colors@1.5.0': - resolution: {integrity: sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==} - engines: {node: '>=0.1.90'} - '@csstools/color-helpers@5.1.0': resolution: {integrity: sha512-S11EXWJyy0Mz5SYvRmY8nJYTFFd1LCNV+7cXyAgQtOOuzb4EsgfqDufL+9esx72/eLhsRdGZwaldu/h+E4t4BA==} engines: {node: '>=18'} @@ -2590,8 +2586,8 @@ packages: resolution: {integrity: sha512-aCj4O5wKyszjMmDT4tZj93kxyydN/K5zPWSCe6/0AV/AA1pqe5ZBIw0a2ZfPQV7lL5/yb5HsUreJ6UFAF1tEQw==} engines: {node: '>=18'} - cli-table3@0.6.5: - resolution: {integrity: sha512-+W/5efTR7y5HRD7gACw9yQjqMVvEMLBHmboM/kPWam+H+Hmyrgjh6YncVKK122YZkXrLudzTuAukUw9FnMf7IQ==} + cli-table3@0.6.1: + resolution: {integrity: sha512-w0q/enDHhPLq44ovMGdQeeDLvwxwavsJX7oQGYt/LrBlYsyaxyDnp6z3QzFut/6kLLKnlcUVJLrpB7KBfgG/RA==} engines: {node: 10.* || >= 12.*} cli-truncate@2.1.0: @@ -2634,6 +2630,10 @@ packages: colorette@2.0.20: resolution: {integrity: sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==} + colors@1.4.0: + resolution: {integrity: sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==} + engines: {node: '>=0.1.90'} + combined-stream@1.0.8: resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} engines: {node: '>= 0.8'} @@ -2764,8 +2764,8 @@ packages: csstype@3.2.3: resolution: {integrity: sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==} - cypress@14.0.1: - resolution: {integrity: sha512-gBAvKZE3f6eBaW1v8OtrwAFP90rjNZjjOO40M2KvOvmwVXk96Ps5Yjyck1EzGkXmNCaC/8kXFOY/1KD/wsaWpQ==} + cypress@14.5.4: + resolution: {integrity: sha512-0Dhm4qc9VatOcI1GiFGVt8osgpPdqJLHzRwcAB5MSD/CAAts3oybvPUPawHyvJZUd8osADqZe/xzMsZ8sDTjXw==} engines: {node: ^18.0.0 || ^20.0.0 || >=22.0.0} hasBin: true @@ -3473,6 +3473,10 @@ packages: resolution: {integrity: sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==} engines: {node: '>= 0.4'} + hasha@5.2.2: + resolution: {integrity: sha512-Hrp5vIK/xr5SkeN2onO32H0MgNZ0f17HRNH39WfL0SYUNOTZ5Lz1TJ8Pajo/87dYGEFlLMm7mIc/k/s6Bvz9HQ==} + engines: {node: '>=8'} + hashery@1.5.1: resolution: {integrity: sha512-iZyKG96/JwPz1N55vj2Ie2vXbhu440zfUfJvSwEqEbeLluk7NnapfGqa7LH0mOsnDxTF85Mx8/dyR6HfqcbmbQ==} engines: {node: '>=20'} @@ -5401,6 +5405,10 @@ packages: resolution: {integrity: sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==} engines: {node: '>=10'} + type-fest@0.8.1: + resolution: {integrity: sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==} + engines: {node: '>=8'} + type-is@1.6.18: resolution: {integrity: sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==} engines: {node: '>= 0.6'} @@ -6529,9 +6537,6 @@ snapshots: hashery: 1.5.1 keyv: 5.6.0 - '@colors/colors@1.5.0': - optional: true - '@csstools/color-helpers@5.1.0': {} '@csstools/css-calc@2.1.4(@csstools/css-parser-algorithms@3.0.5(@csstools/css-tokenizer@3.0.4))(@csstools/css-tokenizer@3.0.4)': @@ -8301,11 +8306,11 @@ snapshots: dependencies: restore-cursor: 5.1.0 - cli-table3@0.6.5: + cli-table3@0.6.1: dependencies: string-width: 4.2.3 optionalDependencies: - '@colors/colors': 1.5.0 + colors: 1.4.0 cli-truncate@2.1.0: dependencies: @@ -8345,6 +8350,9 @@ snapshots: colorette@2.0.20: {} + colors@1.4.0: + optional: true + combined-stream@1.0.8: dependencies: delayed-stream: 1.0.0 @@ -8463,7 +8471,7 @@ snapshots: csstype@3.2.3: {} - cypress@14.0.1: + cypress@14.5.4: dependencies: '@cypress/request': 3.0.10 '@cypress/xvfb': 1.2.4(supports-color@8.1.1) @@ -8478,7 +8486,7 @@ snapshots: check-more-types: 2.24.0 ci-info: 4.5.0 cli-cursor: 3.1.0 - cli-table3: 0.6.5 + cli-table3: 0.6.1 commander: 6.2.1 common-tags: 1.8.2 dayjs: 1.11.23 @@ -8491,6 +8499,7 @@ snapshots: figures: 3.2.0 fs-extra: 9.1.0 getos: 3.2.1 + hasha: 5.2.2 is-installed-globally: 0.4.0 lazy-ass: 1.6.0 listr2: 3.14.0(enquirer@2.4.1) @@ -9338,6 +9347,11 @@ snapshots: dependencies: has-symbols: 1.1.0 + hasha@5.2.2: + dependencies: + is-stream: 2.0.1 + type-fest: 0.8.1 + hashery@1.5.1: dependencies: hookified: 1.15.1 @@ -11470,6 +11484,8 @@ snapshots: type-fest@0.21.3: {} + type-fest@0.8.1: {} + type-is@1.6.18: dependencies: media-typer: 0.3.0 From 2564e0517cd3fd160ba52e1d773cf286a5d69abf Mon Sep 17 00:00:00 2001 From: david-yz-liu Date: Sat, 14 Nov 2026 12:41:01 -0500 Subject: [PATCH 2/2] Added end-to-end tests to CI and stubbed course info in Info Box test - Run Cypress in the CI build job against a server with the graphs database - Cache the Cypress binary and upload screenshots/server log on failure - Stub /course in the Info Box test with a fixture, since course info otherwise requires scraping the Arts & Science Calendar Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 30 ++++++++++++++++++++ .gitignore | 1 - CHANGELOG.md | 2 +- README.md | 2 +- cypress/fixtures/csc108-course-info.json | 13 +++++++++ cypress/integration/graph_spec/graph_spec.js | 11 +++++-- 6 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 cypress/fixtures/csc108-course-info.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3608f9631..6284c1434 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,6 +50,9 @@ jobs: apt-get update apt-get install -y graphviz apt-get install -y texlive-latex-base + # System dependencies for Cypress (https://docs.cypress.io/app/get-started/install-cypress#Linux-Prerequisites) + apt-get install -y libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libnss3 libxss1 libxtst6 xauth xvfb + apt-get install -y libasound2t64 || apt-get install -y libasound2 if [ ! -d squashfs-root ]; then wget --tries=5 --retry-connrefused --waitretry=10 -O magick https://github.com/ImageMagick/ImageMagick/releases/download/7.1.2-31/ImageMagick-7.1.2-31-gcc-x86_64.AppImage chmod u+x ./magick @@ -57,6 +60,12 @@ jobs: fi stack --allow-different-user update + - name: Restore Cypress binary cache + uses: actions/cache@v6 + with: + path: /root/.cache/Cypress + key: v1-courseography-cypress-${{ hashFiles('pnpm-lock.yaml') }} + - uses: pnpm/setup@v3.1.2 with: cache: true @@ -88,6 +97,27 @@ jobs: stack --allow-different-user --no-terminal test --coverage $(stack --allow-different-user exec which hpc-lcov) -o coverage/backend.info + - name: Set up database and start server for end-to-end tests + run: | + pnpm run build + stack --allow-different-user exec courseography database-setup + stack --allow-different-user exec courseography database-graphs + stack --allow-different-user exec courseography > server.log 2>&1 & + timeout 120 sh -c 'until curl -sf http://localhost:8000/graph > /dev/null; do sleep 2; done' + + - name: Run end-to-end tests + run: pnpm run cypress:run + + - name: Upload end-to-end test failure artifacts + if: failure() + uses: actions/upload-artifact@v7 + with: + name: cypress-failures + path: | + cypress/screenshots + server.log + if-no-files-found: ignore + - name: Upload coverage to Coveralls uses: coverallsapp/github-action@v2 with: diff --git a/.gitignore b/.gitignore index fef0da543..cd0173c26 100644 --- a/.gitignore +++ b/.gitignore @@ -53,7 +53,6 @@ cabal.sandbox.config coverage # cypress suggested folder structure scaffolding -/cypress/fixtures /cypress/integration/examples /cypress/plugins /cypress/screenshots diff --git a/CHANGELOG.md b/CHANGELOG.md index 98b566e70..893162fe8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ ### 🔧 Internal changes -- Updated Cypress to 14.5.4, migrated `cypress.json` to `cypress.config.js`, fixed outdated end-to-end tests, and added `cypress:run`/`cypress:open` scripts and README instructions for running them +- Updated Cypress to 14.5.4, migrated `cypress.json` to `cypress.config.js`, fixed outdated end-to-end tests, added `cypress:run`/`cypress:open` scripts and README instructions for running them, and added an end-to-end test run to CI - Added test coverage for `CampusMap` component (7 test cases covering rendering, markers, and zoom functionality) - Simplified timetable availability check in `Description.tsx` by removing redundant `Object.keys(sessions).length !== 0` condition - Updated OpenStreetMap tile layer URL from HTTP to HTTPS in `CampusMap.tsx` for improved security diff --git a/README.md b/README.md index 92e6fdd3a..e9f9f6823 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ run `$ pnpm test -- `. #### Running end-to-end tests -We use [Cypress](https://www.cypress.io/) for end-to-end tests that run against the full app in a browser. The tests are in `cypress/integration/`. +We use [Cypress](https://www.cypress.io/) for end-to-end tests that run against the full app in a browser. The tests are in `cypress/integration/`, and they also run in CI on every pull request. 1. Make sure the database is populated (see [Parsing and Generation](#parsing-and-generation)) and start the app (see [Running](#running)). The tests expect the server at `http://localhost:8000`. 2. In a new terminal window, run one of: diff --git a/cypress/fixtures/csc108-course-info.json b/cypress/fixtures/csc108-course-info.json new file mode 100644 index 000000000..776b39cd6 --- /dev/null +++ b/cypress/fixtures/csc108-course-info.json @@ -0,0 +1,13 @@ +{ + "name": "CSC108H1", + "title": "Introduction to Computer Programming", + "description": "Programming in a language such as Python. Elementary data types, lists, maps. Program structure: control flow, functions, classes, objects, methods. Algorithms and problem solving. Searching, sorting, and complexity. Unit testing.", + "prereqString": null, + "coreqs": null, + "exclusions": "CSC110Y1, CSC148H1", + "prep": null, + "breadth": "The Physical and Mathematical Universes (5)", + "distribution": "Science", + "allMeetingTimes": [], + "videoUrls": [] +} diff --git a/cypress/integration/graph_spec/graph_spec.js b/cypress/integration/graph_spec/graph_spec.js index cf346e6fd..c49820bf4 100644 --- a/cypress/integration/graph_spec/graph_spec.js +++ b/cypress/integration/graph_spec/graph_spec.js @@ -54,11 +54,18 @@ describe("Graph", () => { describe("Info Box", () => { it("clicking the info box should produce a pop up modal", () => { - cy.visit("/graph") + // Course info comes from scraping the Arts & Science Calendar, so stub it + // rather than requiring a fully populated database + cy.intercept( + { method: "GET", pathname: "/course" }, + { fixture: "csc108-course-info.json" } + ).as("getCourse") + cy.contains("CSC108").trigger("mouseover") cy.contains("Info").click() - cy.contains("CSC108 Introduction to Computer Programming") + cy.wait("@getCourse").its("request.url").should("include", "name=csc108") + cy.contains("CSC108H1 Introduction to Computer Programming") // force click because it's not visible cy.get(".ReactModal__Overlay").click({ force: true }) })