Skip to content

Add clean game search and sorting#139

Open
sombaner wants to merge 1 commit intogithub-samples:mainfrom
sombaner:feature/sort-games-clean
Open

Add clean game search and sorting#139
sombaner wants to merge 1 commit intogithub-samples:mainfrom
sombaner:feature/sort-games-clean

Conversation

@sombaner
Copy link
Copy Markdown

Summary

  • add search and sort support to GET /api/games
  • add search input and sort selector to the game list UI
  • extend the game model and seed data with popularity and release date
  • add backend and Playwright coverage for the new behavior

Validation

  • ./scripts/run-server-tests.sh
  • cd client && npm run build
  • cd client && npx playwright test e2e-tests/games.spec.ts

Notes

  • this PR replaces the original feature/sort-games merge path, which is blocked by unrelated commits and merge conflicts against main

Copilot AI review requested due to automatic review settings April 19, 2026 18:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/games to support search and sort query 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' },
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
{ value: 'title', label: 'Title' },

Copilot uses AI. Check for mistakes.
Comment on lines +137 to +138
await expect(page.getByTestId('games-grid')).toBeVisible();
});
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot generated this review using guidance from repository custom instructions.

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 });
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot generated this review using guidance from repository custom instructions.
# 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)
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# Generate random popularity score (0-10000)
# Generate random popularity score (100-10000)

Copilot uses AI. Check for mistakes.
Comment thread server/models/game.py
Comment on lines +12 to +13
popularity = db.Column(db.Integer, nullable=True, default=0)
release_date = db.Column(db.Date, nullable=True)
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants