Files
Momento/memento-note/tests/favorites-section.spec.ts
Sepehr Ramezani aa6a214f37 feat: rename keep-notes to memento-note, migrate to PostgreSQL, fix MCP bugs
- Rename directory keep-notes -> memento-note with all code references
- Prisma: SQLite -> PostgreSQL (both app and MCP server schemas)
- Sync MCP schema with main app (add missing fields, relations, indexes)
- Delete 17 SQLite migrations (clean slate for PostgreSQL)
- Remove SQLite dependencies (@libsql/client, better-sqlite3, etc.)
- Fix MCP server: hardcoded Windows DB paths -> DATABASE_URL env var
- Fix MCP server: .dockerignore excluded index-sse.js (SSE mode broken)
- MCP Dockerfile: node:20 -> node:22
- Docker Compose: add postgres service, remove SQLite volume
- Generate favicon.ico, icon-192.png, icon-512.png, apple-icon.png
- Update layout.tsx icons and manifest.json for PNG icons
- Update all .env files for PostgreSQL
- Rewrite README.md with updated sections
- Remove mcp-server/node_modules and prisma/client-generated from git tracking

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-20 20:58:04 +02:00

166 lines
5.6 KiB
TypeScript

import { test, expect } from '@playwright/test'
test.describe('Favorites Section', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/')
await page.waitForLoadState('networkidle')
})
test('should not show favorites section when no notes are pinned', async ({ page }) => {
const favoritesSection = page.locator('[data-testid="favorites-section"]')
await expect(favoritesSection).not.toBeVisible()
})
test('should pin a note and show it in favorites section', async ({ page }) => {
const existingNotes = page.locator('[data-testid="note-card"]')
const noteCount = await existingNotes.count()
if (noteCount === 0) {
test.skip(true, 'No notes exist to test pinning')
return
}
const firstNoteCard = existingNotes.first()
await firstNoteCard.hover()
const pinButton = firstNoteCard.locator('[data-testid="pin-button"]')
await expect(pinButton).toBeVisible({ timeout: 5000 })
await pinButton.click()
await expect(page.locator('[data-testid="favorites-section"]')).toBeVisible({ timeout: 10000 })
const sectionTitle = page.locator('[data-testid="favorites-section"] h2')
await expect(sectionTitle).toContainText('Pinned')
const pinnedNotes = page.locator('[data-testid="favorites-section"] [data-testid="note-card"]')
await expect(pinnedNotes.first()).toBeVisible({ timeout: 5000 })
})
test('should unpin a note and remove it from favorites', async ({ page }) => {
const favoritesSection = page.locator('[data-testid="favorites-section"]')
const isFavoritesVisible = await favoritesSection.isVisible().catch(() => false)
if (!isFavoritesVisible) {
test.skip(true, 'No favorites exist to test unpinning')
return
}
const pinnedNotes = favoritesSection.locator('[data-testid="note-card"]')
const pinnedCount = await pinnedNotes.count()
if (pinnedCount === 0) {
test.skip(true, 'No pinned notes to unpin')
return
}
const firstPinnedNote = pinnedNotes.first()
await firstPinnedNote.hover()
const pinButton = firstPinnedNote.locator('[data-testid="pin-button"]')
await pinButton.click()
await page.waitForTimeout(500)
const updatedPinnedCount = await favoritesSection.locator('[data-testid="note-card"]').count().catch(() => 0)
if (pinnedCount === 1) {
await expect(favoritesSection).not.toBeVisible({ timeout: 10000 })
} else {
expect(updatedPinnedCount).toBe(pinnedCount - 1)
}
})
test('should show multiple pinned notes in favorites section', async ({ page }) => {
const existingNotes = page.locator('[data-testid="note-card"]')
const noteCount = await existingNotes.count()
if (noteCount < 2) {
test.skip(true, 'Not enough notes to test multiple pins')
return
}
for (let i = 0; i < 2; i++) {
const noteCard = existingNotes.nth(i)
await noteCard.hover()
const pinButton = noteCard.locator('[data-testid="pin-button"]')
await expect(pinButton).toBeVisible({ timeout: 5000 })
await pinButton.click()
await page.waitForTimeout(500)
}
const favoritesSection = page.locator('[data-testid="favorites-section"]')
await expect(favoritesSection).toBeVisible({ timeout: 10000 })
const pinnedNotes = favoritesSection.locator('[data-testid="note-card"]')
const pinnedCount = await pinnedNotes.count()
expect(pinnedCount).toBeGreaterThanOrEqual(2)
})
test('should show favorites section above main notes', async ({ page }) => {
const existingNotes = page.locator('[data-testid="note-card"]')
const noteCount = await existingNotes.count()
if (noteCount === 0) {
test.skip(true, 'No notes exist to test ordering')
return
}
const firstNoteCard = existingNotes.first()
await firstNoteCard.hover()
const pinButton = firstNoteCard.locator('[data-testid="pin-button"]')
await expect(pinButton).toBeVisible({ timeout: 5000 })
await pinButton.click()
const favoritesSection = page.locator('[data-testid="favorites-section"]')
const mainNotesGrid = page.locator('[data-testid="notes-grid"]')
await expect(favoritesSection).toBeVisible({ timeout: 10000 })
const hasUnpinnedNotes = await mainNotesGrid.isVisible().catch(() => false)
if (hasUnpinnedNotes) {
const favoritesY = await favoritesSection.boundingBox()
const mainNotesY = await mainNotesGrid.boundingBox()
if (favoritesY && mainNotesY) {
expect(favoritesY.y).toBeLessThan(mainNotesY.y)
}
}
})
test('should collapse and expand favorites section', async ({ page }) => {
const favoritesSection = page.locator('[data-testid="favorites-section"]')
const isFavoritesVisible = await favoritesSection.isVisible().catch(() => false)
if (!isFavoritesVisible) {
const existingNotes = page.locator('[data-testid="note-card"]')
const noteCount = await existingNotes.count()
if (noteCount === 0) {
test.skip(true, 'No notes to pin for collapse test')
return
}
const firstNoteCard = existingNotes.first()
await firstNoteCard.hover()
const pinButton = firstNoteCard.locator('[data-testid="pin-button"]')
await pinButton.click()
await expect(favoritesSection).toBeVisible({ timeout: 10000 })
}
const collapseButton = favoritesSection.locator('button').first()
const pinnedNoteCards = favoritesSection.locator('[data-testid="note-card"]')
await expect(pinnedNoteCards.first()).toBeVisible()
await collapseButton.click()
await expect(pinnedNoteCards.first()).not.toBeVisible()
await collapseButton.click()
await expect(pinnedNoteCards.first()).toBeVisible()
})
})