From 0fbb321048153e50257e4b5cc6cbb02b247d3010 Mon Sep 17 00:00:00 2001 From: Jessica Ho Date: Mon, 26 Feb 2024 22:40:07 +0000 Subject: [PATCH] more tests wip --- playwright.config.ts | 2 +- prisma/constants.ts | 11 ++-- prisma/seed.ts | 10 ++-- prisma/utils.ts | 12 ++++- .../components/Dashboard/ScheduleTable.svelte | 4 +- src/routes/household/+page.svelte | 50 +++++++++++-------- tests/household.spec.ts | 30 +++++++++++ 7 files changed, 82 insertions(+), 37 deletions(-) create mode 100644 tests/household.spec.ts diff --git a/playwright.config.ts b/playwright.config.ts index fdff474..c54c5b6 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -16,7 +16,7 @@ const config: PlaywrightTestConfig = { expect: { timeout: 3000 }, - // timeout: 10000, + timeout: 10000, testDir: 'tests', use: { locale: 'en-US', diff --git a/prisma/constants.ts b/prisma/constants.ts index 5ce46fe..517fb6e 100644 --- a/prisma/constants.ts +++ b/prisma/constants.ts @@ -1,8 +1,3 @@ -export const PHONES = [ - '+12015550121', - '+12015550122', - '+12015550123', - '+12015550124', - '+12015550125', - '+12015550126' -]; +export const USERS_WITH_NOTHING = [1, 2, 7]; +export const USERS_WITH_EMPTY_HOUSEHOLD = [3, 4]; +export const USERS_WITH_ACTIVE_SESSION = [2, 4, 6, 7]; \ No newline at end of file diff --git a/prisma/seed.ts b/prisma/seed.ts index 23d8467..92c935c 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -1,16 +1,20 @@ import { PrismaClient } from '@prisma/client'; +import { USERS_WITH_ACTIVE_SESSION, USERS_WITH_EMPTY_HOUSEHOLD, USERS_WITH_NOTHING } from './constants'; import SeedUtils from './utils'; const prisma = new PrismaClient(); async function main() { const utils = new SeedUtils(new Date(), prisma); + + await utils.deleteAllHouseholds(); + await Promise.all([ utils.deleteAllFriendRequests(), utils.createExpiredLink(1), - ...[1, 2].map((userInd) => utils.createUserWithNothing(userInd)), - ...[3, 4].map((userInd) => utils.createUserWithEmptyHousehold(userInd)), - ...[2, 4, 6].map((userInd) => utils.createActiveSession(userInd)), + ...USERS_WITH_NOTHING.map((userInd) => utils.createUserWithNothing(userInd)), + ...USERS_WITH_EMPTY_HOUSEHOLD.map((userInd) => utils.createUserWithEmptyHousehold(userInd)), + ...USERS_WITH_ACTIVE_SESSION.map((userInd) => utils.createActiveSession(userInd)), utils.createUserWithEmptyHousehold(5), utils.createUserWithKid(6), ]); diff --git a/prisma/utils.ts b/prisma/utils.ts index ce62c55..7ce1bd0 100644 --- a/prisma/utils.ts +++ b/prisma/utils.ts @@ -9,7 +9,8 @@ export default class SeedUtils { '+12015550123', '+12015550124', '+12015550125', - '+12015550126' + '+12015550126', + '+12015550127' ]; constructor(now: Date, prisma: PrismaClient) { @@ -100,6 +101,15 @@ export default class SeedUtils { .catch(() => console.log('No friend request table to delete')); } + async deleteAllHouseholds() { + await this.#prisma.householdChild + .deleteMany() + .catch(() => console.log('No household child table to delete')); + await this.#prisma.household + .deleteMany() + .catch(() => console.log('No household table to delete')); + } + async createExpiredLink(userInd: number) { const expiredLink = { token: '3e99472f1003794c', diff --git a/src/lib/components/Dashboard/ScheduleTable.svelte b/src/lib/components/Dashboard/ScheduleTable.svelte index c596e81..46a73e4 100644 --- a/src/lib/components/Dashboard/ScheduleTable.svelte +++ b/src/lib/components/Dashboard/ScheduleTable.svelte @@ -66,9 +66,7 @@ .flex { display: flex; } - .border-right { - border-right: 1px solid #dddddd; - } + table { border-collapse: collapse; border: 1px solid #dddddd; diff --git a/src/routes/household/+page.svelte b/src/routes/household/+page.svelte index 78c08dc..c348891 100644 --- a/src/routes/household/+page.svelte +++ b/src/routes/household/+page.svelte @@ -411,7 +411,7 @@ {/if}

Kids

{#each kids as kid, ind} -
+

{kid.firstName} {kid.lastName ?? ''}

Pronouns: {PRONOUNS[kid.pronouns]}

Age: {isNaN(kid.age) ? 'N/A' : kid.age}

@@ -421,26 +421,34 @@ {/each}
- - - - - - - - - - - + + + + + + +
diff --git a/tests/household.spec.ts b/tests/household.spec.ts new file mode 100644 index 0000000..14a5f68 --- /dev/null +++ b/tests/household.spec.ts @@ -0,0 +1,30 @@ +import { expect, test } from '@playwright/test'; +import { run } from '../prisma/seed'; + +const host = 'http://localhost:5173'; + +test.beforeAll(async () => { + await run(); +}); + +test('User can create new kid', async ({ page, context }) => { + await context.addCookies([ + { + name: 'session', + value: 'user7session', + url: host + } + ]); + await page.goto(host); + await page.waitForURL(`${host}/household`); + await page.waitForTimeout(2000) + expect(await page.locator('.kid-card').count()).toBe(0) + + await page.locator('input[name="first-name"]').fill('FIRST_NAME') + await page.locator('input[name="last-name"]').fill('LAST_NAME') + await page.locator('select[name="pronouns"]').selectOption('SHE_HER_HERS'); + + await page.getByText('Save Child').click(); + await page.locator('.kid-card').first().waitFor(); + expect(await page.locator('.kid-card').count()).toBe(1) +});