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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ dist-ssr
*.njsproj
*.sln
*.sw?

# Local Claude Code settings
.claude/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ Vitest enforces a minimum of 80 % for lines, functions and statements and 75 % f
We will add the missing tests before raising the limits further, and we do not lower the limits to make the run pass.

We leave out `main.tsx`, test files, test helpers and mock data, because they contain no application logic.
Run `npm run test:coverage` in `frontend/` to see the full report.
Run `npm run test:coverage` in `frontend/` to see the full report. It prints a link to an HTML report in `frontend/coverage/`, coloured green at 100 %, yellow from 80 %, orange below 80 % and red at 0 %.

### Run the tests

Expand All @@ -282,7 +282,7 @@ npm test
- One issue per task and one branch per issue. Changes go through a pull request.
- Make tests and preferably update documentation as you go.
- Another group member must review every pull request (`.github/CODEOWNERS`).
- Before a pull request, run lint, Prettier, type checking, tests and build. See [workflow](docs/workflow.md).
- Before a pull request, run `npm run check` from the repository root. It runs Prettier, ESLint, type checking, tests with coverage and the build, and links to the coverage report. See [workflow](docs/workflow.md).

### Tools

Expand Down
63 changes: 63 additions & 0 deletions docs/requirements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Requirements: IT2810 Project 2

Short version of the course text. A full-stack, searchable catalogue that should in theory scale to any data size.

## Functionality

- [ ] Search on single terms, case-insensitive, without needless requests (debounce or a button)
- [ ] Result list built for large result sets: pages, or loading more on scroll
- [ ] Detail view for each item
- [ ] Sorting and filtering on the **whole** result set, not only what the client has loaded
- [ ] User-generated data (reviews, ratings, lists, search history, …) stored on the database server and shown in the app
- [ ] Accessibility (universell utforming)
- [ ] Sustainable web development, through design choices
- [ ] Good design and choices that fit the data
- [ ] Database and backend hosted on the group's VM at submission

## Technology

- [ ] React + TypeScript, set up with Vite
- [ ] State management (Redux, MobX, Apollo local state, …)
- [ ] Our own GraphQL backend in Node + TypeScript
- [ ] Any database, installed by us directly on the VM. No Docker.
- [ ] Reuse good third-party components and libraries

## Quality, testing and docs

- [ ] Linting and Prettier
- [ ] Component tests with Vitest
- [ ] Automated end-to-end tests (a longer sequence of interactions) and API tests
- [ ] README that discusses and explains all major choices, including components and API
- [ ] Readable, well-structured code, commented for outside readers
- [ ] Reproducible: easy for others (staff) to install and run
- [ ] AI use documented, with our own control shown through issues, PRs, code review and systematic collaboration
- [ ] Individual contributions summarised in a separate file in Canvas/Blackboard, **not** in git

## VM setup

- [ ] Served by Apache at `http://it2810-18.idi.ntnu.no/project2`
- [ ] Backend preferably on port 3001
- [ ] Everything needed to start the backend is available to staff (in git, or a file readable with sudo on the VM)

## Deliveries

All go to git.ntnu.no plus the prototype on the VM, followed by peer review in FeedbackFruits.

| # | Due | Peer review by | Expected | Extra |
|---|---|---|---|---|
| 1 | 2 Oct | 9 Oct | Specification or draft with mock data | |
| 2 | 16 Oct | 21 Oct | Database and backend running on the VM, some client interaction | |
| 3 | 30 Oct | 6 Nov | First complete prototype (beta): search, paging, sort, filter, sustainability, accessibility | Timesheet |
| 4 | 13 Nov | 20 Nov | Finished project; testing is assessed too | Timesheet for all of Project 2 |
| Final | 27 Nov | | Projects 1 and 2, can still change after peer review | Individual timesheet and description |

## Grading

- Each approved delivery with peer review participation: 10 % of the portfolio.
- Qualitative assessment of the projects: 50 % of the grade, mostly Project 2 (45 %).
- Meeting the requirements alone is not enough for a top grade. It also needs:
- **Application understanding:** good insight into this kind of app, explores better solutions instead of easy ones, focus on usability and user experience.
- **Technical understanding:** scales with any amount of data, thoroughly tested for typical and atypical use, efficient and sustainable solutions, competence at every level, reproducible setup and clear docs.
- **Design:** excellent visual and interaction design, thorough focus on accessibility.

Budget: about 8 hours a week per group member.
44 changes: 26 additions & 18 deletions docs/workflow.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
# Workflow

Create one issue per task and one branch per issue. Submit changes through a pull request.
Another team member must review and merge the pull request and close the issue.
Co-authorship does not prevent that person from merging.
## From task to `main`

Use branch prefixes such as `feature-`, `fix-`, `docs-`, `test-`, or `chore-`.
1. **Issue:** one per task, with a goal, tasks and «done when».
2. **Branch:** one per issue, named `<issue>-<short-name>`, e.g. `33-reviews`.
3. **Commits:** small, in English, [Conventional Commits](https://www.conventionalcommits.org/) with the issue number:
`feat(search): add filter chips (#35)`.
4. **Check:** `npm run check` passes (see below).
5. **Pull request:** links the issue (`Closes #33`) and says what was tested and how.
6. **Review:** another group member reviews (`.github/CODEOWNERS`), merges and closes the issue.
Co-authorship does not stop that person from merging.

Before a pull request, run the frontend checks from the project folder:
## Before a pull request

```bash
cd frontend
npm run format
npm run lint
npm run format:check
npm test -- --run
npm run build
```
Run from the repository root:

Check the backend manually with `npm start` from `backend/`.
Open [localhost:3001](http://localhost:3001/) and confirm it returns database information.
The backend does not have automated tests yet.
| Command | Does |
| ------------------------ | ------------------------------------------------------------------------------------------- |
| `npm run check` | Prettier, ESLint, TypeScript, tests with coverage and build, for `frontend/` and `backend/` |
| `npm run check -- --fix` | Runs Prettier and ESLint fixes first |
| `npm run check -- --e2e` | Also runs the Playwright tests |

Keep documentation current and record AI assistance during development.
Submit personal time logs and contribution summaries in Canvas.
- Every step runs, even after a failure. Steps a package lacks show as «not set up».
- The output ends with a summary, the coverage numbers and a link to the report.
- Coverage report: `frontend/coverage/index.html`. 100 % green, 80–99 % yellow, 1–79 % orange, 0 % red.

## Conventions

- **Language:** English in code, commits, PRs and docs. Norwegian (bokmål) in everything users see.
- **Docs:** update README and `docs/` in the same PR as the change.
- **AI:** allowed. AI-written code goes through the same checks and review, and we record how we used it.
- **Personal:** time logs and contribution summaries go in Canvas/Blackboard, never in git.
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"format:check": "prettier --check .",
"test": "vitest",
"test:run": "vitest run",
"test:coverage": "vitest run --coverage",
"test:coverage": "node scripts/coverage.mjs",
"typecheck": "tsc -b --noEmit",
"e2e": "playwright test"
},
Expand Down
106 changes: 106 additions & 0 deletions frontend/scripts/coverage-report.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Restyles Istanbul's HTML coverage report (coverage/) after Vitest has written it.
//
// Istanbul only has three colour levels. We want four, so this script replaces its
// low/medium/high classes with our own:
// 100 % → full (green)
// 80–99.99 % → partial (yellow)
// 0.01–79.99 % → low (orange)
// 0 % → none (red)
// It also links kk-report.css, a cleaner stylesheet with dark mode.
//
// Run directly with `node scripts/coverage-report.mjs`, or through scripts/coverage.mjs.
import { copyFileSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const here = path.dirname(fileURLToPath(import.meta.url));
const ISTANBUL_LEVELS = /\b(low|medium|high)\b/g;

export function coverageLevel(percent) {
if (percent >= 100) return 'full';
if (percent >= 80) return 'partial';
if (percent > 0) return 'low';
return 'none';
}

/** Replaces Istanbul's level class in a tag's class attribute with ours. */
function withLevel(tag, level) {
return tag.replace(/class=(["'])([^"']*)\1/, (_match, quote, classes) => {
const kept = classes.replace(ISTANBUL_LEVELS, '').replace(/\s+/g, ' ').trim();
return `class=${quote}${kept} kk-${level}${quote}`;
});
}

/**
* One summary row: file name, bar, then a percentage and a count per metric.
* The file name and the bar follow statements; each count follows its percentage.
*/
function restyleRow(row) {
const cells = (row.match(/<td[^>]*>/g) ?? []).map((tag) => ({
kind: /class="(\w+)/.exec(tag)?.[1],
value: Number(/data-value="([^"]*)"/.exec(tag)?.[1]),
}));
const statements = cells.find((cell) => cell.kind === 'pct');
if (!statements) return row;

const rowLevel = coverageLevel(statements.value);
let current = rowLevel;
const levels = cells.map((cell) => {
if (cell.kind === 'pct') current = coverageLevel(cell.value);
return cell.kind === 'file' || cell.kind === 'pic' ? rowLevel : current;
});

let index = 0;
return row.replace(/<td[^>]*>/g, (tag) => withLevel(tag, levels[index++]));
}

export function restyleHtml(html, prefix) {
if (html.includes('kk-report.css')) return html; // already done

let statementsLevel;
let result = html
// The four metric boxes at the top of each page.
.replace(
/<div class='fl pad1y space-right2'>(\s*<span class="strong">([\d.]+)% <\/span>)/g,
(_match, inner, percent) => {
const level = coverageLevel(Number(percent));
statementsLevel ??= level;
return `<div class='fl pad1y space-right2 kk-metric kk-${level}'>${inner}`;
},
)
.replace(/<tr>[\s\S]*?<\/tr>/g, restyleRow)
.replace(
/<link rel="stylesheet" href="([./]*)base\.css" \/>/,
(link) => `${link}\n <link rel="stylesheet" href="${prefix}kk-report.css" />`,
)
.replace(
'<meta charset="utf-8" />',
'<meta charset="utf-8" />\n <meta name="color-scheme" content="light dark" />',
);

if (statementsLevel) {
result = result.replace(/class='status-line \w+'/, `class='status-line kk-${statementsLevel}'`);
}
return result;
}

export function restyleReport(reportDir) {
copyFileSync(path.join(here, 'kk-report.css'), path.join(reportDir, 'kk-report.css'));

const walk = (dir) => {
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) walk(full);
else if (entry.name.endsWith('.html')) {
const depth = path.relative(reportDir, dir).split(path.sep).filter(Boolean).length;
const html = readFileSync(full, 'utf8');
writeFileSync(full, restyleHtml(html, '../'.repeat(depth)));
}
}
};
walk(reportDir);
}

if (process.argv[1] === fileURLToPath(import.meta.url)) {
restyleReport(path.resolve(here, '..', 'coverage'));
}
25 changes: 25 additions & 0 deletions frontend/scripts/coverage.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// `npm run test:coverage`: runs Vitest with coverage, restyles the HTML report and
// prints a link to it. Exits with Vitest's exit code, so failing tests or coverage
// below the thresholds in vitest.config.ts still fail the command.
import { spawnSync } from 'node:child_process';
import { existsSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { restyleReport } from './coverage-report.mjs';

const frontend = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const reportDir = path.join(frontend, 'coverage');

const vitest = spawnSync('npx', ['vitest', 'run', '--coverage', ...process.argv.slice(2)], {
cwd: frontend,
stdio: 'inherit',
shell: process.platform === 'win32',
});

const index = path.join(reportDir, 'index.html');
if (existsSync(index)) {
restyleReport(reportDir);
console.log(`\nCoverage report: ${pathToFileURL(index).href}`);
}

process.exit(vitest.status ?? 1);
Loading