mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
Update zod validation, update tests a bit, and checking type with zod in add to collection and wishlist.
This commit is contained in:
parent
f3d24a15bc
commit
4f89e32b12
7 changed files with 45 additions and 11 deletions
|
|
@ -51,7 +51,7 @@
|
|||
class="thumbnail"
|
||||
href={`/game/${game.id}`}
|
||||
title={`View ${game.name}`}
|
||||
data-sveltekit-prefetch
|
||||
data-sveltekit-preload-data
|
||||
>
|
||||
<Image src={game.thumb_url} alt={`Image of ${game.name}`} />
|
||||
<!-- <img src={game.thumb_url} alt={`Image of ${game.name}`} /> -->
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@
|
|||
</div>
|
||||
|
||||
<nav>
|
||||
<a href="/collection" title="Go to your collection" data-sveltekit-prefetch>Collection</a>
|
||||
<a href="/wishlist" title="Go to your collection" data-sveltekit-prefetch>Wishlist</a>
|
||||
<a href="/collection" title="Go to your collection" data-sveltekit-preload-data>Collection</a>
|
||||
<a href="/wishlist" title="Go to your wishlist" data-sveltekit-preload-data>Wishlist</a>
|
||||
<Profile />
|
||||
</nav>
|
||||
</header>
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ export function mapSavedGameToGame(game: SavedGameType): GameType {
|
|||
const { id, name, thumb_url, players, playtime } = game;
|
||||
console.log({ id, name, thumb_url, players, playtime });
|
||||
|
||||
|
||||
return {
|
||||
id,
|
||||
handle: '',
|
||||
|
|
|
|||
|
|
@ -2,13 +2,24 @@ import { collectionStore } from '$lib/stores/collectionStore';
|
|||
import { toast } from '$lib/components/toast/toast';
|
||||
import { ToastType, type GameType, type SavedGameType } from '$lib/types';
|
||||
import { convertToSavedGame } from './gameMapper';
|
||||
import { saved_game_schema } from '../zodValidation';
|
||||
|
||||
export function addToCollection(game: GameType | SavedGameType) {
|
||||
collectionStore.add(convertToSavedGame(game));
|
||||
toast.send("Added to collection", { duration: 3000, type: ToastType.INFO });
|
||||
try {
|
||||
saved_game_schema.parse(game);
|
||||
collectionStore.add(convertToSavedGame(game));
|
||||
toast.send("Added to collection", { duration: 3000, type: ToastType.INFO });
|
||||
} catch (error) {
|
||||
toast.send('Error adding to collection', { duration: 3000, type: ToastType.ERROR });
|
||||
}
|
||||
}
|
||||
|
||||
export function removeFromCollection(game: GameType | SavedGameType) {
|
||||
collectionStore.remove(game.id);
|
||||
toast.send("Removed from collection", { duration: 3000, type: ToastType.INFO });
|
||||
try {
|
||||
saved_game_schema.parse(game);
|
||||
collectionStore.remove(game.id);
|
||||
toast.send("Removed from collection", { duration: 3000, type: ToastType.INFO });
|
||||
} catch (error) {
|
||||
toast.send('Error removing from collection', { duration: 3000, type: ToastType.ERROR });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ export const saved_game_schema = z.object({
|
|||
name: z.string(),
|
||||
thumb_url: z.string(),
|
||||
players: z.string(),
|
||||
playtime: z.string()
|
||||
playtime: IntegerString(z.number()),
|
||||
});
|
||||
|
||||
// https://github.com/colinhacks/zod/discussions/330
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ export const actions: Actions = {
|
|||
queryParams.random = random;
|
||||
} else {
|
||||
try {
|
||||
console.log('Parsed', search_schema.parse(formData))
|
||||
const {
|
||||
name,
|
||||
minAge,
|
||||
|
|
|
|||
|
|
@ -2,5 +2,30 @@ import { expect, test } from '@playwright/test';
|
|||
|
||||
test('about page has expected h1', async ({ page }) => {
|
||||
await page.goto('/about');
|
||||
expect(await page.textContent('h1')).toBe('About this app');
|
||||
expect(await page.textContent('h1')).toBe('About Bored Game');
|
||||
});
|
||||
|
||||
test('base page has title and header links', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
|
||||
// Expect a title "to contain" a substring
|
||||
await expect(page).toHaveTitle(/Bored Game \|/);
|
||||
|
||||
// create a locator collection
|
||||
const collectionLink = page.getByRole('link', { name: 'COLLECTION' });
|
||||
|
||||
// Expect an attribute "to be strictly equal" to the value.
|
||||
await expect(collectionLink).toHaveAttribute('href', '/collection');
|
||||
|
||||
// create a locator collection
|
||||
const wishlistLink = page.getByRole('link', { name: 'WISHLIST' });
|
||||
|
||||
// Expect an attribute "to be strictly equal" to the value.
|
||||
await expect(wishlistLink).toHaveAttribute('href', '/wishlist');
|
||||
|
||||
// // Click the get started link.
|
||||
// await getStarted.click();
|
||||
|
||||
// // Expects the URL to contain intro.
|
||||
// await expect(page).toHaveURL(/.*intro/);
|
||||
})
|
||||
Loading…
Reference in a new issue