ZDDC/tests/mdedit.spec.js
ZDDC c95f07966d feat(tools,build): in-flight HTML-tool reworks and build-infra updates
Bundles a stretch of in-progress work across the SPA tools so the
tree returns to a coherent shippable state ahead of cutting a new
zddc-server stable image:

- landing: substantial rework of the project picker (sortable/filterable
  table, presets refactor, ?projects= filter, ?v= channel propagation,
  loading/error states)
- archive: presets cleanup, source.js refactor, filtering/url-state
  alignment with the landing page
- mdedit: file-system module split, resizer, file-tree improvements,
  base/toc styling tweaks
- transmittal/classifier: small template touch-ups for shared chrome
- shared: build-lib.sh helpers, new favicon.svg
- bootstrap, build.sh: pick up the channel-aware install/track zip
  generation
- tests: new landing.spec.js, expanded archive/mdedit/build-label specs
- docs: CLAUDE.md picks up the zddc-server section and freshens the
  alpha-build exception note
- regenerated artifacts: install.zip, track-{alpha,beta,stable}.zip,
  *_alpha.html — these are produced by `sh build.sh` and per project
  convention are committed alongside the source changes

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 12:52:27 -05:00

77 lines
3.2 KiB
JavaScript

import { test, expect } from '@playwright/test';
import { MOCK_FS_INIT_SCRIPT } from './fixtures/mock-fs-api.js';
import * as path from 'path';
const HTML_PATH = path.resolve('mdedit/dist/mdedit.html');
test.describe('Markdown Editor', () => {
test.beforeEach(async ({ page }) => {
await page.addInitScript(MOCK_FS_INIT_SCRIPT);
});
test('loads without errors', async ({ page }) => {
// Use 'load' rather than 'networkidle' — the bundled Toast UI/Tailwind
// scripts run inline so there is no external network activity to wait for.
await page.goto(`file://${HTML_PATH}`, { waitUntil: 'load' });
await page.waitForSelector('#app', { timeout: 15000 });
// Scratchpad opens by default with welcome content seeded into the editor.
await expect(page.locator(`.file-item[data-path="__scratchpad__"]`)).toBeVisible();
await expect(page.locator('#content-container')).toBeVisible();
// Select Directory button is present and enabled
const selectDirBtn = page.locator('#select-directory');
await expect(selectDirBtn).toBeVisible();
await expect(selectDirBtn).not.toBeDisabled();
});
test('renders a file tree from a mock directory', async ({ page }) => {
await page.goto(`file://${HTML_PATH}`, { waitUntil: 'load' });
await page.waitForSelector('#select-directory', { timeout: 15000 });
// Set up mock directory before triggering the picker
await page.evaluate(() => {
window.__setMockDirectory('notes', [
{ name: 'readme.md', content: '# Hello\n\nWelcome.', size: 30 },
{ name: 'notes.md', content: '# Notes\n\nSome notes.', size: 25 },
]);
});
await page.locator('#select-directory').click();
// File tree should populate with the two files
await page.waitForFunction(
() => document.querySelector('#file-tree')?.children.length > 0,
{ timeout: 10000 }
);
const items = await page.locator('#file-tree *').count();
expect(items).toBeGreaterThanOrEqual(2);
});
test('DEBUG flag is defined and console.log calls are gated', async ({ page }) => {
const logs = [];
page.on('console', msg => msg.type() === 'log' && logs.push(msg.text()));
await page.goto(`file://${HTML_PATH}`, { waitUntil: 'load' });
await page.waitForSelector('#select-directory', { timeout: 15000 });
const probe = await page.evaluate(() => ({
debugDefined: typeof DEBUG !== 'undefined',
debugValue: typeof DEBUG !== 'undefined' ? DEBUG : null,
}));
expect(probe.debugDefined).toBe(true);
expect(probe.debugValue).toBe(false);
// With DEBUG=false, no console.log should fire from app code on load.
// (Browser/Toast-UI may still log; we only check none of the gated lines fired.)
const ourLogs = logs.filter(l =>
l.startsWith('Opened scratchpad') ||
l.startsWith('Directory selected') ||
l.startsWith('File ') ||
l.startsWith('Created new file')
);
expect(ourLogs).toEqual([]);
});
});