Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/arverma/Bihar-Police-Notebook/llms.txt

Use this file to discover all available pages before exploring further.

Bihar Police Notebook uses two complementary test layers: fast Vitest unit tests that validate transliteration logic in isolation, and Playwright end-to-end tests that drive a real browser against the static editor/ folder. Because the app has no build step, Playwright simply spins up a local file server and opens the HTML directly — no bundler or compilation required before running either suite.

Prerequisites

Install the dev dependencies once after cloning:
npm install
This installs both vitest@^3.2.7 and @playwright/test@^1.62.1. After that, download the Playwright browser binaries:
npx playwright install

Running the Tests

npm test
Runs vitest run editor/ — Vitest discovers every *.test.js file inside the editor/ directory and exits with a pass/fail code. No browser is involved.

Unit Tests — Vitest

The unit suite lives in editor/js/translit.test.js and covers the core transliteration helpers imported from translit.js.

shouldSkipTransliteration()

This function decides whether a typed token should bypass the Hindi phonetic engine entirely. The tests pin down three important rules:

Legal Acronyms

Tokens like IPC, CrPC, and FIR — all-caps or mixed-caps legal abbreviations — must be skipped so they appear verbatim in the document.

Numbers & Punctuation

Pure numeric strings (123, 12.3) and comma-separated numbers (45,67) are skipped, preserving numerals and decimal separators as typed.

Hinglish Words

Lowercase romanised Hindi words like bihar and patna must not be skipped — they should be fed into the transliteration pipeline.
// editor/js/translit.test.js (excerpt)
import { expect, test } from 'vitest';
import { shouldSkipTransliteration } from './translit.js';

test('shouldSkipTransliteration skips english uppercase acronyms', () => {
    expect(shouldSkipTransliteration('IPC')).toBe(true);
    expect(shouldSkipTransliteration('CrPC')).toBe(true);
    expect(shouldSkipTransliteration('FIR')).toBe(true);
});

test('shouldSkipTransliteration skips pure numbers and punctuation', () => {
    expect(shouldSkipTransliteration('123')).toBe(true);
    expect(shouldSkipTransliteration('12.3')).toBe(true);
    expect(shouldSkipTransliteration('45,67')).toBe(true);
});

test('shouldSkipTransliteration does NOT skip lowercase hinglish words', () => {
    expect(shouldSkipTransliteration('bihar')).toBe(false);
    expect(shouldSkipTransliteration('patna')).toBe(false);
});

End-to-End Tests — Playwright

All E2E specs live in the tests/ directory and are run against Chromium (Desktop Chrome profile). The full list of spec files:
FileWhat it covers
tests/app.spec.jsApp load, page title, transliteration toggle
tests/punctuation.spec.jsPunctuation panel rendering, clipboard copy, focus preservation
tests/focus-test.spec.jsEditor focus behaviour
tests/btn-focus-test.spec.jsButton focus interactions
tests/label-focus-test.spec.jsLabel focus state
tests/label-restore-test.spec.jsLabel state restoration
tests/label-timeout-test.spec.jsLabel timeout logic
tests/mousedown-test.spec.jsMousedown event handling
tests/toggle-state.spec.jsToggle state persistence

Playwright Configuration

playwright.config.js defines the key settings:
// playwright.config.js
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  testDir: './tests',
  fullyParallel: true,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  workers: process.env.CI ? 1 : undefined,
  reporter: 'html',
  use: {
    baseURL: 'http://localhost:8080',
    trace: 'on-first-retry',
  },
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
  ],
  webServer: {
    command: 'cd editor && python3 -m http.server 8080',
    url: 'http://localhost:8080',
    reuseExistingServer: !process.env.CI,
  },
});
On a developer machine, reuseExistingServer: true means Playwright will reuse any server already running on port 8080 rather than starting a new one. Start your own server with cd editor && python3 -m http.server 8080 before running tests to speed up repeated runs.

Key E2E Scenarios

1

App loads with correct title

app.spec.js navigates to / and asserts page.title() matches /Bihar Police Notebook/. This catches broken HTML or missing <title> tags immediately.
2

Transliteration toggle works

The #translitToggle checkbox starts checked (phonetic mode on). Clicking .toggle-slider flips it to unchecked, confirming the toggle state machine updates correctly.
3

Punctuation panel renders 9 tiles

punctuation.spec.js waits for .punctuation-grid to be visible, then counts .punctuation-tile elements. Exactly 9 essential punctuation buttons — including the Hindi purna viram — must be present.
4

Clipboard copy on tile click

Clicking the first punctuation tile reads navigator.clipboard.readText() and asserts the clipboard text matches the tile’s visible symbol. The spec requests clipboard-read and clipboard-write permissions via test.use().
5

Punctuation clicks preserve editor focus

After the editor (.ql-editor) receives focus, clicking a punctuation tile must not move focus away from the editor. This ensures officers can insert punctuation without losing their caret position.

Viewing the HTML Report

After any Playwright run, open the generated HTML report:
npx playwright show-report
The report shows pass/fail status, screenshots on failure, and traces (captured on first retry) for debugging flaky behaviour.
On CI, workers is forced to 1 and forbidOnly is true. If a spec containing test.only is accidentally committed, the CI run will fail immediately to prevent skipping part of the suite.

Build docs developers (and LLMs) love