/* 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 list or card shows the records of its data, whenever its config arrives. The grist hands the data over at once * and the compiled config a render later - and a personal config loads later still - so a list that emptied itself * on a config change showed nothing until the next fetch (2026-10-26). */ const records = [ { id: '1', title: 'one' }, { id: '2', title: 'two' } ] const config = (header: string) => ({ columns: [{ type: 'string', name: 'title', header, record: { editable: true } }], rows: { appendable: false }, list: { fields: ['title'] } }) /* `updateComplete` resolves false while an update set another one going. */ const idle = async (el: DataGrist) => { while (!((await el.updateComplete) && (await el.grist.updateComplete))); } for (const [mode, tag] of [ ['LIST', 'ox-record-partial'], ['CARD', 'ox-record-card'] ] as const) { describe(`a ${mode} and its config`, () => { failOnPageErrors() const shown = (el: DataGrist) => Array.from(el.grist.renderRoot.querySelectorAll(tag) as NodeListOf).map(item => item.record.title) it('shows the records it was given with its config', async () => { const el = await fixture( html`` ) await idle(el) expect(shown(el)).to.eql(['one', 'two']) }) it('keeps its records when the config changes after them', async () => { const el = await fixture( html`` ) await idle(el) el.config = config('renamed') await idle(el) expect(shown(el)).to.eql(['one', 'two']) }) }) }