/* Elements are compared by presence, not by value: a failing element comparison makes chai render the DOM and hang the runner. */ import { expect, fixture } from '@open-wc/testing' import { html } from 'lit' import '../src/record-view/record-view.js' import { buildColumn } from '../src/configure/column-builder.js' import { OxGristEditor } from '../src/editors/ox-grist-editor.js' import { registerEditor } from '../src/editors/registry.js' /* * In a form (ox-record-view - the 「만들기」 dialog of a grid) a field is pressed to be edited. A field whose editor * opens a popup used to become 「editing」 on the first press but open nothing until its editor was pressed again, * so what was typed after the first press went nowhere (pdf template 「만들기」, body HTML, 2026-10-10). */ let opened = 0 class ProbePopupEditor extends OxGristEditor { static opensPopup = true _onclick(e: Event): void { e.stopPropagation() opened++ } } customElements.define('probe-popup-editor', ProbePopupEditor) registerEditor('probe-popup', ProbePopupEditor) const settle = (ms = 100) => new Promise(resolve => setTimeout(resolve, ms)) describe('a popup field in a form', () => { it('does not emit the old inline value after a popup has confirmed a different value', async () => { const record = { body: 'old' } const editor = await fixture( html`` ) let changes = 0 editor.addEventListener('field-change', () => changes++) record.body = 'confirmed' editor._onfocusout() expect(changes).to.equal(0) expect(record.body).to.equal('confirmed') }) it('opens its popup on the first press', async () => { opened = 0 const columns = [ buildColumn({ type: 'string', name: 'name', header: 'name', record: { editable: true } } as any), buildColumn({ type: 'probe-popup', name: 'body', header: 'body', record: { editable: true } } as any) ] const view = (await fixture(html``)) as any await view.updateComplete await settle() const body = view.renderRoot.querySelector('ox-record-view-body') as any await body.updateComplete const field = Array.from(body.renderRoot.querySelectorAll('ox-grid-field') as NodeListOf).find(one => one.column?.name === 'body') expect(!!field, 'the body field is drawn').to.equal(true) field.click() await settle(200) expect(field.getAttribute('editing'), 'the field is being edited').to.equal('true') expect(opened, 'the popup editor was opened once').to.equal(1) }) it('leaves a field edited in place as it was - nothing extra is pressed', async () => { opened = 0 const columns = [buildColumn({ type: 'string', name: 'name', header: 'name', record: { editable: true } } as any)] const view = (await fixture(html``)) as any await view.updateComplete await settle() const body = view.renderRoot.querySelector('ox-record-view-body') as any await body.updateComplete const field = body.renderRoot.querySelector('ox-grid-field') as any field.click() await settle(200) expect(field.getAttribute('editing')).to.equal('true') expect(opened).to.equal(0) }) })