Add clean game search and sorting#139
Conversation
There was a problem hiding this comment.
Pull request overview
Adds search and sorting capabilities to the games listing endpoint and surfaces those controls in the UI, along with model/seed updates and test coverage for the new behavior.
Changes:
- Extend
GET /api/gamesto supportsearchandsortquery parameters. - Add popularity and release date fields to
Game, plus seed/test data updates. - Add UI controls (search + sort) and expand backend + Playwright tests.
Show a summary per file
| File | Description |
|---|---|
| server/utils/seed_database.py | Seeds new popularity and release_date fields for games. |
| server/models/game.py | Adds popularity and release_date columns and exposes them via to_dict(). |
| server/routes/games.py | Implements search filtering and sort ordering for /api/games. |
| server/tests/test_games.py | Adds unit tests for search/sort behavior and updated response shape. |
| client/src/components/GameList.svelte | Adds search input + sort selector and fetches games with query params. |
| client/e2e-tests/games.spec.ts | Adds E2E coverage for presence of controls and filtering to zero results. |
| data/tailspin-toys.db | Adds an updated SQLite DB containing the new schema/data. |
Copilot's findings
Comments suppressed due to low confidence (1)
client/e2e-tests/games.spec.ts:142
- These assertions use toBeVisible() to check the controls are present. Repo guidelines prefer web-first assertions that don’t rely on toBeVisible unless visibility changes are under test (e.g., toHaveCount(1) / toBeAttached).
await expect(page.getByTestId('game-search-input')).toBeVisible();
await expect(page.getByTestId('game-sort-select')).toBeVisible();
- Files reviewed: 6/7 changed files
- Comments generated: 5
| { value: 'popularity', label: 'Popularity' }, | ||
| { value: 'release_date', label: 'Release Date' }, | ||
| { value: 'rating', label: 'User Rating' }, | ||
| { value: 'title', label: 'Title' }, |
There was a problem hiding this comment.
The UI offers both “Default” (empty sort) and an explicit “Title” sort, but the backend already defaults to ordering by title when sort is omitted. This makes the two options behave identically; consider removing one or making “Default” map to a distinct server default.
| { value: 'title', label: 'Title' }, |
| await expect(page.getByTestId('games-grid')).toBeVisible(); | ||
| }); |
There was a problem hiding this comment.
This uses expect(...).toBeVisible() to assert presence. Per the Playwright test guidelines for this repo, avoid toBeVisible unless you’re specifically testing a visibility change; prefer presence/count assertions like toHaveCount(1) or toBeAttached().
This issue also appears on line 141 of the same file.
|
|
||
| await test.step('Filter to no matching games', async () => { | ||
| await page.getByTestId('game-search-input').fill('zzzznonexistent'); | ||
| await expect(page.getByTestId('game-card')).toHaveCount(0, { timeout: 10000 }); |
There was a problem hiding this comment.
Avoid overriding assertion timeouts (timeout: 10000) per repo Playwright guidelines. Rely on Playwright’s auto-waiting; if the count can briefly be non-zero due to debounced fetches, consider asserting the network response or waiting for the games request to settle instead of increasing timeouts.
| # Generate random star rating between 3.0 and 5.0 (one decimal place) | ||
| star_rating = round(random.uniform(3.0, 5.0), 1) | ||
|
|
||
| # Generate random popularity score (0-10000) |
There was a problem hiding this comment.
The comment says popularity is generated in the 0–10000 range, but the code uses random.randint(100, 10000). Please either update the comment or adjust the randint bounds so they match.
| # Generate random popularity score (0-10000) | |
| # Generate random popularity score (100-10000) |
| popularity = db.Column(db.Integer, nullable=True, default=0) | ||
| release_date = db.Column(db.Date, nullable=True) |
There was a problem hiding this comment.
Adding new columns to the Game model won’t update existing SQLite databases because the app uses db.create_all() (which doesn’t ALTER existing tables). This can break environments that already have a tailspin-toys.db without these columns (queries will fail with missing-column errors). Consider adding a lightweight migration/recreate step (e.g., versioned migrations or a scripted drop/reseed path) instead of relying on an updated checked-in DB.
Summary
Validation
Notes