Skip to content
Merged
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
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,22 @@ 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
./magick --appimage-extract
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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ cabal.sandbox.config
coverage

# cypress suggested folder structure scaffolding
/cypress/fixtures
/cypress/integration/examples
/cypress/plugins
/cypress/support
/cypress/screenshots
/cypress/videos

# Python virtual environment
venv
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 -- <path>`.

#### 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/`, 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:
- `$ pnpm run cypress:run` to run all tests headlessly in the terminal.
- `$ pnpm run cypress:run --spec <path>` 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 "<name of test group/case>"'`.
Expand Down
9 changes: 9 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { defineConfig } = require("cypress")

module.exports = defineConfig({
e2e: {
baseUrl: "http://localhost:8000",
specPattern: "cypress/integration/**/*_spec.js",
excludeSpecPattern: "**/examples/*.js",
},
})
4 changes: 0 additions & 4 deletions cypress.json

This file was deleted.

13 changes: 13 additions & 0 deletions cypress/fixtures/csc108-course-info.json
Original file line number Diff line number Diff line change
@@ -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": []
}
32 changes: 16 additions & 16 deletions cypress/integration/graph_spec/bool_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
})
110 changes: 61 additions & 49 deletions cypress/integration/graph_spec/edge_spec.js
Original file line number Diff line number Diff line change
@@ -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")
})
})
})
Loading
Loading