feat: add quick links filtering and frontmatter enrichment on file load
This commit is contained in:
@@ -0,0 +1,210 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { promises as fs } from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const VAULT_PATH = path.join(process.cwd(), 'vault');
|
||||
const TEST_FILES = {
|
||||
favorite: 'test-favorite.md',
|
||||
template: 'test-template.md',
|
||||
task: 'test-task.md',
|
||||
regular: 'test-regular.md'
|
||||
};
|
||||
|
||||
test.describe('Front-matter Enrichment & Quick Links', () => {
|
||||
|
||||
test.beforeAll(async () => {
|
||||
// Create test files with different front-matter configurations
|
||||
await fs.mkdir(VAULT_PATH, { recursive: true });
|
||||
|
||||
// File with favoris: true
|
||||
await fs.writeFile(
|
||||
path.join(VAULT_PATH, TEST_FILES.favorite),
|
||||
`---
|
||||
titre: Favorite Note
|
||||
favoris: true
|
||||
---
|
||||
|
||||
# Favorite Note
|
||||
This is a favorite note.`,
|
||||
'utf-8'
|
||||
);
|
||||
|
||||
// File with template: true
|
||||
await fs.writeFile(
|
||||
path.join(VAULT_PATH, TEST_FILES.template),
|
||||
`---
|
||||
titre: Template Note
|
||||
template: true
|
||||
---
|
||||
|
||||
# Template Note
|
||||
This is a template note.`,
|
||||
'utf-8'
|
||||
);
|
||||
|
||||
// File with task: true
|
||||
await fs.writeFile(
|
||||
path.join(VAULT_PATH, TEST_FILES.task),
|
||||
`---
|
||||
titre: Task Note
|
||||
task: true
|
||||
---
|
||||
|
||||
# Task Note
|
||||
This is a task note.`,
|
||||
'utf-8'
|
||||
);
|
||||
|
||||
// Regular file without special flags
|
||||
await fs.writeFile(
|
||||
path.join(VAULT_PATH, TEST_FILES.regular),
|
||||
`# Regular Note
|
||||
This is a regular note without front-matter.`,
|
||||
'utf-8'
|
||||
);
|
||||
});
|
||||
|
||||
test('should enrich front-matter on file open', async ({ page }) => {
|
||||
await page.goto('http://localhost:4200');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Open the regular file (without front-matter)
|
||||
await page.click(`text=${TEST_FILES.regular.replace('.md', '')}`);
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
// Check that the file now has front-matter
|
||||
const content = await fs.readFile(path.join(VAULT_PATH, TEST_FILES.regular), 'utf-8');
|
||||
|
||||
expect(content).toContain('---');
|
||||
expect(content).toContain('titre: test-regular');
|
||||
expect(content).toContain('auteur: Bruno Charest');
|
||||
expect(content).toContain('favoris: false');
|
||||
expect(content).toContain('template: false');
|
||||
expect(content).toContain('task: false');
|
||||
});
|
||||
|
||||
test('should display Quick Links with correct counts', async ({ page }) => {
|
||||
await page.goto('http://localhost:4200');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Wait for Quick Links to load
|
||||
await page.waitForSelector('text=Quick Links', { timeout: 5000 });
|
||||
|
||||
// Check if Quick Links section is visible
|
||||
const quickLinksVisible = await page.isVisible('text=Quick Links');
|
||||
expect(quickLinksVisible).toBeTruthy();
|
||||
|
||||
// Check for Favorites count
|
||||
const favoritesText = await page.textContent('text=Favorites');
|
||||
expect(favoritesText).toContain('(1)'); // Should show 1 favorite
|
||||
|
||||
// Check for Templates count
|
||||
const templatesText = await page.textContent('text=Templates');
|
||||
expect(templatesText).toContain('(1)'); // Should show 1 template
|
||||
|
||||
// Check for Tasks count
|
||||
const tasksText = await page.textContent('text=Tasks');
|
||||
expect(tasksText).toContain('(1)'); // Should show 1 task
|
||||
});
|
||||
|
||||
test('should filter notes when clicking Favorites', async ({ page }) => {
|
||||
await page.goto('http://localhost:4200');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Click on Favorites in Quick Links
|
||||
await page.click('text=Favorites');
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
// Check that only favorite notes are displayed in the list
|
||||
const notesList = await page.locator('.text-sm.font-semibold').allTextContents();
|
||||
|
||||
expect(notesList).toContain('Favorite Note');
|
||||
expect(notesList).not.toContain('Template Note');
|
||||
expect(notesList).not.toContain('Task Note');
|
||||
});
|
||||
|
||||
test('should filter notes when clicking Templates', async ({ page }) => {
|
||||
await page.goto('http://localhost:4200');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Click on Templates in Quick Links
|
||||
await page.click('text=Templates');
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
// Check that only template notes are displayed in the list
|
||||
const notesList = await page.locator('.text-sm.font-semibold').allTextContents();
|
||||
|
||||
expect(notesList).toContain('Template Note');
|
||||
expect(notesList).not.toContain('Favorite Note');
|
||||
expect(notesList).not.toContain('Task Note');
|
||||
});
|
||||
|
||||
test('should filter notes when clicking Tasks', async ({ page }) => {
|
||||
await page.goto('http://localhost:4200');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Click on Tasks in Quick Links
|
||||
await page.click('text=Tasks');
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
// Check that only task notes are displayed in the list
|
||||
const notesList = await page.locator('.text-sm.font-semibold').allTextContents();
|
||||
|
||||
expect(notesList).toContain('Task Note');
|
||||
expect(notesList).not.toContain('Favorite Note');
|
||||
expect(notesList).not.toContain('Template Note');
|
||||
});
|
||||
|
||||
test('should clear filters when clicking All pages', async ({ page }) => {
|
||||
await page.goto('http://localhost:4200');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// First, apply a filter
|
||||
await page.click('text=Favorites');
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
// Then click All pages
|
||||
await page.click('text=All pages');
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
// Check that all notes are displayed
|
||||
const notesList = await page.locator('.text-sm.font-semibold').allTextContents();
|
||||
|
||||
expect(notesList.length).toBeGreaterThan(1);
|
||||
});
|
||||
|
||||
test('should preserve front-matter on subsequent opens (idempotence)', async ({ page }) => {
|
||||
await page.goto('http://localhost:4200');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Open the favorite file
|
||||
await page.click('text=Favorite Note');
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
// Read the file content
|
||||
const content1 = await fs.readFile(path.join(VAULT_PATH, TEST_FILES.favorite), 'utf-8');
|
||||
|
||||
// Close and reopen the file
|
||||
await page.click('text=All pages');
|
||||
await page.waitForTimeout(500);
|
||||
await page.click('text=Favorite Note');
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
// Read the file content again
|
||||
const content2 = await fs.readFile(path.join(VAULT_PATH, TEST_FILES.favorite), 'utf-8');
|
||||
|
||||
// Content should be identical (idempotent)
|
||||
expect(content1.trim()).toBe(content2.trim());
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
// Cleanup test files
|
||||
for (const file of Object.values(TEST_FILES)) {
|
||||
try {
|
||||
await fs.unlink(path.join(VAULT_PATH, file));
|
||||
} catch (err) {
|
||||
// Ignore errors
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user