/* 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/data-grist.js' import { DataGrist } from '../src/data-grist.js' import { failOnPageErrors } from './page-errors.js' /* * A card's checkbox stands beside the title. It sat in the action row under the text, a line of its own far from * what it selects (Office ledgers on a phone, 2026-11-05). */ const records = [{ id: '1', title: 'one', amount: 990000 }] const config = (gutters: any[]) => ({ columns: [ ...gutters, { type: 'string', name: 'title', header: 'title' }, { type: 'integer', name: 'amount', header: 'amount' } ], rows: { appendable: false, selectable: { multiple: true } }, list: { fields: ['title'], details: ['amount'] } }) const idle = async (el: DataGrist) => { while (!((await el.updateComplete) && (await el.grist.updateComplete))); } const cardOf = async (gutters: any[]) => { const el = await fixture( html`` ) await idle(el) const card = el.grist.renderRoot.querySelector('ox-record-card') as any await card.updateComplete /* The icons draw after the card, and the card makes room for them when they do. */ await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))) return card as HTMLElement & { renderRoot: ShadowRoot } } describe('a card and its checkbox', () => { failOnPageErrors() it('stands in the top-right corner, on the title line, and takes no row of its own', async () => { const card = await cardOf([{ type: 'gutter', gutterName: 'row-selector', multiple: true, forList: true }]) const box = card.renderRoot.querySelector('ox-card-gutter') as HTMLElement const title = card.renderRoot.querySelector('ox-card-field[name]') as HTMLElement const detail = card.renderRoot.querySelector('[detail]') as HTMLElement expect(box, 'no checkbox').to.exist const cardBox = card.getBoundingClientRect() const boxRect = box.getBoundingClientRect() const titleRect = title.getBoundingClientRect() expect(boxRect.top, 'the checkbox is not on the title line').to.be.below(titleRect.bottom) expect(cardBox.right - boxRect.right, 'the checkbox is not at the right edge').to.be.below(16) expect(titleRect.right, 'the title runs under the checkbox').to.be.at.most(boxRect.left) expect(cardBox.bottom - detail.getBoundingClientRect().bottom, 'the card keeps a row under its text').to.be.below(16) expect(card.renderRoot.querySelector('[gutters]'), 'an empty action row').to.equal(null) }) /* The edit icon took a row of its own under the text, the column under the checkbox empty (2026-11-10). */ it('stands the other actions under the checkbox, and takes no row under the text', async () => { const card = await cardOf([ { type: 'gutter', gutterName: 'row-selector', multiple: true, forList: true }, { type: 'gutter', gutterName: 'button', icon: 'edit', forList: true } ]) const [box, edit] = Array.from(card.renderRoot.querySelectorAll('ox-card-gutter')) as HTMLElement[] const title = card.renderRoot.querySelector('ox-card-field[name]') as HTMLElement const detail = card.renderRoot.querySelector('[detail]') as HTMLElement expect(edit, 'no edit icon').to.exist const cardBox = card.getBoundingClientRect() const boxRect = box.getBoundingClientRect() const editRect = edit.getBoundingClientRect() expect(editRect.top, 'the edit icon is not under the checkbox').to.be.at.least(boxRect.bottom - 1) expect(editRect.top - boxRect.bottom, 'the edit icon stands far from the checkbox').to.be.below(12) expect(Math.abs((editRect.left + editRect.right) / 2 - (boxRect.left + boxRect.right) / 2), 'not one column').to.be.below(2) expect(title.getBoundingClientRect().right, 'the title runs under the icons').to.be.at.most(editRect.left) expect(editRect.bottom, 'the edit icon hangs out of the card').to.be.at.most(cardBox.bottom) expect(cardBox.bottom - Math.max(detail.getBoundingClientRect().bottom, editRect.bottom), 'a row left under the text').to.be.below(16) }) })