import { expect, fixture } from '@open-wc/testing' import { html } from 'lit' import '../src/data-grid/data-grid-body.js' import '../src/data-grid/data-grid-header.js' import { buildColumn } from '../src/configure/column-builder.js' import { ZERO_CONFIG, ZERO_DATA } from '../src/configure/zero-config.js' /* * A column says what it takes and the limit the server checks (record.hint). A grid has no room under a cell, so the * sentence shows under the focused cell while it can be edited, as a spreadsheet's input message, and on the header * when the pointer rests there. The focused cell's input names it for a screen reader. */ const columns = [ { type: 'number', name: 'share', header: '배분율', record: { editable: true, hint: '0보다 크고 100 이하입니다.' } }, { type: 'string', name: 'notes', header: '비고', record: { editable: true } }, { type: 'number', name: 'total', header: '합계', record: { editable: false, hint: '읽기만 합니다.' } } ].map(buildColumn) async function bodyFocusedAt(column: number) { const body: any = await fixture(html` `) await body.updateComplete return { hint: body.renderRoot.querySelector('#field-hint') as HTMLElement, buffer: body.renderRoot.querySelector('#ime-buffer') as HTMLInputElement } } describe('record.hint', () => { it('is the note of the focused editable cell, and its input is described by it', async () => { const { hint, buffer } = await bodyFocusedAt(0) expect(hint.hidden).to.equal(false) expect(hint.textContent!.trim()).to.equal('0보다 크고 100 이하입니다.') expect(buffer.getAttribute('aria-describedby')).to.equal('field-hint') }) it('is absent on a column without one', async () => { const { hint, buffer } = await bodyFocusedAt(1) expect(hint.hidden).to.equal(true) expect(buffer.getAttribute('aria-describedby')).to.equal(null) }) it('is not shown on a cell that cannot be edited', async () => { expect((await bodyFocusedAt(2)).hint.hidden).to.equal(true) }) it('rides the header title as its tooltip', async () => { const header: any = await fixture(html``) await header.updateComplete const titles = [...header.renderRoot.querySelectorAll('span[for-title]')] as HTMLElement[] expect(titles.map(title => title.dataset.tooltip ?? null)).to.deep.equal(['0보다 크고 100 이하입니다.', null, '읽기만 합니다.']) }) })