diff --git a/components/AppNav.vue b/components/AppNav.vue index 4de5ff2..9e81ecb 100644 --- a/components/AppNav.vue +++ b/components/AppNav.vue @@ -26,10 +26,11 @@ const items = [ {{ t(item.label) }} diff --git a/components/LandingActions.vue b/components/LandingActions.vue new file mode 100644 index 0000000..c1412ef --- /dev/null +++ b/components/LandingActions.vue @@ -0,0 +1,40 @@ + + + + + + + {{ t('landing.dashboard') }} + + + + + {{ t('landing.register') }} + + + {{ t('landing.signIn') }} + + + + diff --git a/components/LandingFeature.vue b/components/LandingFeature.vue new file mode 100644 index 0000000..8e47c62 --- /dev/null +++ b/components/LandingFeature.vue @@ -0,0 +1,15 @@ + + + + + + {{ props.title }} + {{ props.text }} + + diff --git a/components/SessionControls.vue b/components/SessionControls.vue index d1015d6..027c422 100644 --- a/components/SessionControls.vue +++ b/components/SessionControls.vue @@ -14,10 +14,11 @@ const session = useSessionStore() > {{ t('auth.signIn') }} + {{ t('auth.signOut') }} diff --git a/docs/BACKLOG.md b/docs/BACKLOG.md index 134c326..9ef973c 100644 --- a/docs/BACKLOG.md +++ b/docs/BACKLOG.md @@ -7,8 +7,12 @@ - **F4 Dates** (list, add, mark done, delete, category filter; cards on all screen sizes): done (PR #18). - **F4/F5 Dates table:** Lastenheft F4 asks for an interactive table. A desktop table view with sorting (`sort` and `order` exist in the API) comes later. - **F7/F8 Dashboard** (countdown, dates created per month, category totals): done (PR #19). -- **F6 Location** (save and delete the own location, distance and midpoint, link to OpenStreetMap; no map): - claimed by `Filionus`, branch `feat/location`, in progress. +- **F6 Location** (save and delete the own location, distance and midpoint, link to OpenStreetMap; no map): done (PR #20). +- **Landing page** (start page `/`, `/en`, `/nl` with register and sign-in; "frontend prompt F10", not requirement F10): + claimed by `Filionus`, branch `feat/landing`, in progress. +- **Landing page, still open:** logo and illustrations from the designer (the page uses a text wordmark so far). + SEO beyond title and description: `hreflang` and canonical links, sitemap, `robots.txt`, Open Graph with a preview + image and structured data. Most of these need a fixed base URL. - **F6 Map view, open requirement (Must):** Lastenheft F6 asks for a map view of both partners' locations, and the course brief asks for geo information. F6 is not fulfilled until the map exists. The map library (Leaflet or MapLibre) is still to be chosen. diff --git a/i18n/__tests__/persistence.spec.ts b/i18n/__tests__/persistence.spec.ts index 4b3781f..ce2e429 100644 --- a/i18n/__tests__/persistence.spec.ts +++ b/i18n/__tests__/persistence.spec.ts @@ -1,5 +1,6 @@ import { fileURLToPath } from 'node:url' import { fetch, setup } from '@nuxt/test-utils/e2e' +import { Window } from 'happy-dom' import { describe, expect, test } from 'vitest' // Builds the app once and sends real HTTP requests to it. @@ -79,17 +80,81 @@ describe('returning visit', () => { }) }) +// What the server has to send for each language. +const landingPages = [ + { + path: '/', + language: 'de-DE', + prefix: '', + title: 'Planer für die Fernbeziehung · Ons', + description: 'Ons ist die Web-App für Paare in einer Fernbeziehung: Dates gemeinsam planen, ' + + 'Entfernung und Mittelpunkt sehen, Countdown bis zum nächsten Date.', + heading: 'Euer Planer für die Fernbeziehung', + actions: ['Registrieren', 'Anmelden'], + features: ['Dates gemeinsam planen', 'Wissen, wie weit es ist', 'Der Countdown läuft'], + }, + { + path: '/en', + language: 'en-GB', + prefix: '/en', + title: 'Planner for long-distance couples · Ons', + description: 'Ons is the web app for long-distance couples: plan dates together, see the distance ' + + 'and midpoint, and count down to your next date.', + heading: 'Your planner for a long-distance relationship', + actions: ['Register', 'Sign in'], + features: ['Plan dates together', 'Know how far it is', 'The countdown is on'], + }, + { + path: '/nl', + language: 'nl-NL', + prefix: '/nl', + title: 'Planner voor een relatie op afstand · Ons', + description: 'Ons is de webapp voor stellen met een relatie op afstand: samen dates plannen, ' + + 'afstand en middelpunt zien, aftellen tot de volgende date.', + heading: 'Jullie planner voor een relatie op afstand', + actions: ['Registreren', 'Inloggen'], + features: ['Samen dates plannen', 'Weten hoe ver het is', 'Het aftellen is begonnen'], + }, +] + +// Reads the HTML the way a search engine would, without running any script. +function parse(html: string) { + const window = new Window() + return new window.DOMParser().parseFromString(html, 'text/html') +} + describe('the landing page', () => { - test.each([ - ['/', 'de-DE', 'Start'], - ['/en', 'en-GB', 'Home'], - ['/nl', 'nl-NL', 'Home'], - ])('%s is rendered on the server in %s', async (path, language, heading) => { - const response = await visit(path, { saved: language.slice(0, 2) }) + test.each(landingPages)('$path is rendered on the server in $language', async (expected) => { + const response = await visit(expected.path, { saved: expected.language.slice(0, 2) }) + const page = parse(response.body) + const texts = (selector: string) => [...page.querySelectorAll(selector)].map(node => node.textContent.trim()) + expect(response.status).toBe(200) - expect(response.body).toContain(`lang="${language}"`) - expect(response.body).toMatch(new RegExp(`]*>${heading}`)) - expect(response.body).toContain(`${heading} · Ons`) + expect(page.documentElement.getAttribute('lang')).toBe(expected.language) + expect(page.title).toBe(expected.title) + expect(texts('h1')).toEqual([expected.heading]) + expect(texts('main h2')).toEqual(expected.features) + + // The server cannot know the session, so it always offers registering and signing in. + expect(texts('main a')).toEqual(expected.actions) + expect([...page.querySelectorAll('main a')].map(link => link.getAttribute('href'))) + .toEqual([`${expected.prefix}/register`, `${expected.prefix}/login`]) + }) + + test.each(landingPages)('$path describes itself for search engines', async (expected) => { + const response = await visit(expected.path, { saved: expected.language.slice(0, 2) }) + + const descriptions = parse(response.body).querySelectorAll('meta[name="description"]') + + expect(descriptions).toHaveLength(1) + expect(descriptions[0]!.getAttribute('content')).toBe(expected.description) + expect(expected.description.length).toBeLessThanOrEqual(160) + }) + + test('no longer links to the health check', async () => { + const response = await visit('/', { saved: 'de' }) + + expect(response.body).not.toContain('/api/health') }) test('contains no SEO link tags yet, because those need a fixed base URL (F10)', async () => { diff --git a/i18n/locales/de.json b/i18n/locales/de.json index 7d4d127..a45cd01 100644 --- a/i18n/locales/de.json +++ b/i18n/locales/de.json @@ -20,11 +20,6 @@ "comingSoon": "Diese Seite folgt bald." }, "pages": { - "home": { - "title": "Start", - "intro": "Euer gemeinsamer Planer für die Fernbeziehung.", - "backendStatus": "Backend-Status" - }, "dates": { "title": "Dates" }, @@ -232,6 +227,30 @@ "done": "Standort gelöscht." } }, + "landing": { + "title": "Planer für die Fernbeziehung", + "description": "Ons ist die Web-App für Paare in einer Fernbeziehung: Dates gemeinsam planen, Entfernung und Mittelpunkt sehen, Countdown bis zum nächsten Date.", + "heading": "Euer Planer für die Fernbeziehung", + "subline": "Für Paare, die weit voneinander entfernt leben: Plant eure Dates gemeinsam und behaltet im Blick, wann das nächste ansteht.", + "register": "Registrieren", + "signIn": "Anmelden", + "dashboard": "Zur Übersicht", + "pairing": "Eine Person erstellt euren Bereich, die andere tritt mit einem Einladungscode bei.", + "features": { + "dates": { + "title": "Dates gemeinsam planen", + "text": "Sammelt eure Ideen in einer gemeinsamen Liste, ordnet sie Kategorien zu und hakt ab, was ihr erlebt habt." + }, + "distance": { + "title": "Wissen, wie weit es ist", + "text": "Speichert eure Standorte und seht, wie viele Kilometer zwischen euch liegen und wo die Mitte ist. Den eigenen Standort könnt ihr jederzeit löschen." + }, + "countdown": { + "title": "Der Countdown läuft", + "text": "Die Übersicht zeigt, wie viele Tage und Stunden es noch bis zu eurem nächsten Date mit Termin sind." + } + } + }, "errors": { "unexpected": "Etwas ist schiefgelaufen. Bitte versuche es erneut.", "network": "Keine Verbindung zum Server. Prüfe deine Internetverbindung und versuche es erneut.", diff --git a/i18n/locales/en.json b/i18n/locales/en.json index 020aded..aaa7106 100644 --- a/i18n/locales/en.json +++ b/i18n/locales/en.json @@ -20,11 +20,6 @@ "comingSoon": "This page is coming soon." }, "pages": { - "home": { - "title": "Home", - "intro": "Your shared planner for a long-distance relationship.", - "backendStatus": "Backend status" - }, "dates": { "title": "Dates" }, @@ -232,6 +227,30 @@ "done": "Location deleted." } }, + "landing": { + "title": "Planner for long-distance couples", + "description": "Ons is the web app for long-distance couples: plan dates together, see the distance and midpoint, and count down to your next date.", + "heading": "Your planner for a long-distance relationship", + "subline": "For couples who live far apart: plan your dates together and always know when the next one is coming up.", + "register": "Register", + "signIn": "Sign in", + "dashboard": "Go to overview", + "pairing": "One of you creates your space, the other joins with an invite code.", + "features": { + "dates": { + "title": "Plan dates together", + "text": "Collect your ideas in a shared list, sort them into categories and tick off what you have done together." + }, + "distance": { + "title": "Know how far it is", + "text": "Save your locations and see how many kilometres lie between you and where the middle is. You can delete your own location at any time." + }, + "countdown": { + "title": "The countdown is on", + "text": "Your overview shows how many days and hours are left until your next date with a set time." + } + } + }, "errors": { "unexpected": "Something went wrong. Please try again.", "network": "The server cannot be reached. Check your internet connection and try again.", diff --git a/i18n/locales/nl.json b/i18n/locales/nl.json index 8e0c7bf..924fe56 100644 --- a/i18n/locales/nl.json +++ b/i18n/locales/nl.json @@ -20,11 +20,6 @@ "comingSoon": "Deze pagina volgt binnenkort." }, "pages": { - "home": { - "title": "Home", - "intro": "Jullie gezamenlijke planner voor een langeafstandsrelatie.", - "backendStatus": "Backendstatus" - }, "dates": { "title": "Dates" }, @@ -232,6 +227,30 @@ "done": "Locatie verwijderd." } }, + "landing": { + "title": "Planner voor een relatie op afstand", + "description": "Ons is de webapp voor stellen met een relatie op afstand: samen dates plannen, afstand en middelpunt zien, aftellen tot de volgende date.", + "heading": "Jullie planner voor een relatie op afstand", + "subline": "Voor stellen die ver van elkaar wonen: plan samen jullie dates en weet altijd wanneer de volgende eraan komt.", + "register": "Registreren", + "signIn": "Inloggen", + "dashboard": "Naar het overzicht", + "pairing": "De een maakt jullie ruimte aan, de ander doet mee met een uitnodigingscode.", + "features": { + "dates": { + "title": "Samen dates plannen", + "text": "Verzamel jullie ideeën in een gedeelde lijst, geef ze een categorie en vink af wat jullie samen hebben gedaan." + }, + "distance": { + "title": "Weten hoe ver het is", + "text": "Sla jullie locaties op en zie hoeveel kilometer er tussen jullie ligt en waar het midden is. Je eigen locatie kun je altijd verwijderen." + }, + "countdown": { + "title": "Het aftellen is begonnen", + "text": "Het overzicht toont hoeveel dagen en uren het nog is tot jullie volgende date met een afgesproken tijd." + } + } + }, "errors": { "unexpected": "Er is iets misgegaan. Probeer het opnieuw.", "network": "De server is niet bereikbaar. Controleer je internetverbinding en probeer het opnieuw.", diff --git a/pages/__tests__/index.nuxt.spec.ts b/pages/__tests__/index.nuxt.spec.ts new file mode 100644 index 0000000..6d4524c --- /dev/null +++ b/pages/__tests__/index.nuxt.spec.ts @@ -0,0 +1,162 @@ +import { mockNuxtImport, mountSuspended } from '@nuxt/test-utils/runtime' +import { enableAutoUnmount, flushPromises } from '@vue/test-utils' +import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest' +import { RouterLink } from 'vue-router' +import { createFakeAuth } from '../../composables/__tests__/fake-auth' +import { resetSession } from '../../composables/__tests__/reset-session' +import { useSessionStore } from '../../stores/session' +import LandingPage from '../index.vue' + +// The HTML that the server sends is checked in i18n/__tests__/persistence.spec.ts. +// Here: what the browser shows once it knows who is looking. + +const supabase = vi.hoisted(() => ({ auth: undefined as unknown })) +mockNuxtImport('useSupabaseAuth', () => () => supabase.auth) + +enableAutoUnmount(afterEach) + +let fake: ReturnType + +function signInAs(email: string | undefined) { + fake = createFakeAuth({ signedInAs: email }) + supabase.auth = fake.auth + resetSession() +} + +beforeEach(async () => { + signInAs(undefined) + await useNuxtApp().$i18n.setLocale('de') + await useRouter().push('/') +}) + +async function open() { + const page = await mountSuspended(LandingPage, { + route: '/', + // The real link component builds the address. + global: { stubs: { RouterLink } }, + }) + await flushPromises() + return page +} + +type Page = Awaited> + +// Every link of the page as [text, address]. +const links = (page: Page) => page.findAll('a').map(link => [link.text(), link.attributes('href')]) + +const signedOutLinks = [['Registrieren', '/register'], ['Anmelden', '/login']] + +describe('what the page says', () => { + test('has one headline that names what Ons is and for whom', async () => { + const page = await open() + + expect(page.findAll('h1').map(heading => heading.text())).toEqual(['Euer Planer für die Fernbeziehung']) + expect(page.text()).toContain('Ons') + expect(page.text()).toContain('Für Paare, die weit voneinander entfernt leben:') + expect(page.text()).toContain('Plant eure Dates gemeinsam und behaltet im Blick, wann das nächste ansteht.') + }) + + test('explains how the two get together', async () => { + const page = await open() + + expect(page.text()).toContain('Eine Person erstellt euren Bereich, die andere tritt mit einem Einladungscode bei.') + }) + + test('shows the three things the app does', async () => { + const page = await open() + + const blocks = page.findAll('li').map(block => [block.get('h2').text(), block.get('p').text()]) + + expect(blocks).toEqual([ + [ + 'Dates gemeinsam planen', + 'Sammelt eure Ideen in einer gemeinsamen Liste, ordnet sie Kategorien zu und hakt ab, was ihr erlebt habt.', + ], + [ + 'Wissen, wie weit es ist', + 'Speichert eure Standorte und seht, wie viele Kilometer zwischen euch liegen und wo die Mitte ist. ' + + 'Den eigenen Standort könnt ihr jederzeit löschen.', + ], + [ + 'Der Countdown läuft', + 'Die Übersicht zeigt, wie viele Tage und Stunden es noch bis zu eurem nächsten Date mit Termin sind.', + ], + ]) + }) + + // Photos, a map and live updates are not built, and there are no prices. + test.each([ + ['de', /foto|\bkarte\b|landkarte|echtzeit|\blive\b|kostenlos|gratis|preis/i], + ['en', /photo|\bmap\b|real.?time|\blive updates?\b|\bfree\b|price/i], + ['nl', /foto|\bkaart\b|realtime|\blive\b|gratis|prijs/i], + ] as const)('claims nothing that is not built (%s)', async (language, unbuilt) => { + const page = await open() + + await useNuxtApp().$i18n.setLocale(language) + await flushPromises() + + expect(page.text()).not.toMatch(unbuilt) + // No numbers either. + expect(page.text()).not.toMatch(/\d/) + }) + + test.each([ + ['en', 'Your planner for a long-distance relationship', [['Register', '/en/register'], ['Sign in', '/en/login']]], + ['nl', 'Jullie planner voor een relatie op afstand', [['Registreren', '/nl/register'], ['Inloggen', '/nl/login']]], + ] as const)('follows the language %s, also in its links', async (language, heading, expected) => { + const page = await open() + + await useNuxtApp().$i18n.setLocale(language) + await flushPromises() + + expect(page.get('h1').text()).toBe(heading) + expect(links(page)).toEqual(expected) + }) +}) + +describe('what a visitor can do', () => { + test('register or sign in when signed out', async () => { + const page = await open() + + expect(links(page)).toEqual(signedOutLinks) + }) + + // The same as in the HTML of the server, so nothing changes for a visitor. + test('see the same while the session is still unknown', async () => { + fake.auth.getSession.mockReturnValue(new Promise(() => {})) + fake.auth.onAuthStateChange.mockReturnValue({ data: { subscription: { unsubscribe: () => true } } }) + + const page = await open() + + expect(useSessionStore().status).toBe('unknown') + expect(links(page)).toEqual(signedOutLinks) + }) + + test('go to the dashboard when signed in', async () => { + signInAs('ann@example.org') + + const page = await open() + + expect(links(page)).toEqual([['Zur Übersicht', '/dashboard']]) + }) + + test('follow the language to the dashboard', async () => { + signInAs('ann@example.org') + const page = await open() + + await useNuxtApp().$i18n.setLocale('nl') + await flushPromises() + + expect(links(page)).toEqual([['Naar het overzicht', '/nl/dashboard']]) + }) + + test('register again after signing out on this page', async () => { + signInAs('ann@example.org') + const page = await open() + + await useSessionStore().signOut() + await flushPromises() + + expect(links(page)).toEqual(signedOutLinks) + }) +}) diff --git a/pages/index.vue b/pages/index.vue index 201fa80..0efcee3 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1,17 +1,42 @@ - - {{ t('pages.home.title') }} - {{ t('pages.home.intro') }} - {{ t('pages.home.backendStatus') }} - + + + + {{ t('app.name') }} + {{ t('landing.heading') }} + {{ t('landing.subline') }} + + {{ t('landing.pairing') }} + + + + + + + + +
{{ props.text }}
{{ t('pages.home.intro') }}
{{ t('app.name') }}
{{ t('landing.subline') }}
{{ t('landing.pairing') }}