Files
Imhotep/packages/imhotep-playwright/src/presets.test.ts
T

52 lines
2.0 KiB
TypeScript

import assert from 'node:assert'
import { describe, it } from 'node:test'
import { expect as dslExpect } from 'imhotep-dsl'
import type { ImhotepUi } from './public.js'
import {
touchTarget,
toolbarAlignment,
cardSpacing,
formLabelAlignment,
modalContainment,
} from './presets.js'
function createPresetUi(): ImhotepUi {
return {
expect: (subject: string | any) => dslExpect(String(subject)),
} as unknown as ImhotepUi
}
describe('preset contracts', () => {
it('touchTarget emits width and height clauses', () => {
const result = touchTarget(createPresetUi(), '.button')
assert.strictEqual(result.assertions.length, 2)
assert.ok(result.clauses.some((c) => c.relation === 'size.atLeast' && c.options?.dimension === 'width'))
assert.ok(result.clauses.some((c) => c.relation === 'size.atLeast' && c.options?.dimension === 'height'))
})
it('toolbarAlignment emits pairwise spacing and alignment clauses', () => {
const result = toolbarAlignment(createPresetUi(), ['.a', '.b', '.c'])
assert.strictEqual(result.assertions.length, 4)
assert.ok(result.clauses.some((c) => c.relation === 'leftOf'))
assert.ok(result.clauses.some((c) => c.relation === 'alignedWith'))
})
it('cardSpacing emits horizontal gap contract', () => {
const result = cardSpacing(createPresetUi(), '.card-a', '.card-b', { minGap: 20 })
assert.strictEqual(result.assertions.length, 2)
const leftOf = result.clauses.find((c) => c.relation === 'leftOf')
assert.strictEqual(leftOf?.bounds?.minGap, 20)
})
it('formLabelAlignment supports above mode', () => {
const result = formLabelAlignment(createPresetUi(), '.label', '.input', { labelAbove: true })
assert.ok(result.clauses.some((c) => c.relation === 'above'))
})
it('modalContainment emits containment clauses', () => {
const result = modalContainment(createPresetUi(), '.modal')
assert.ok(result.clauses.some((c) => c.relation === 'inside'))
assert.ok(result.clauses.some((c) => c.relation === 'centeredWithin'))
})
})