import { expect, fixture, html } from '@open-wc/testing' import { setViewport } from '@web/test-runner-commands' import '../src/data-grist.js' import type { DataGrist } from '../src/data-grist.js' const idle = async (el: DataGrist) => { while (!((await el.updateComplete) && (await el.grist.updateComplete))); await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))) } const rows = [{ id: 'one', title: '첫 업무', description: '긴 업무 설명을 충분한 너비로 읽을 수 있어야 합니다.' }] const config = (button: boolean) => ({ columns: [ ...(button ? [{ type: 'gutter', gutterName: 'button', icon: 'edit', title: '상세', forList: true }] : []), { type: 'string', name: 'title', header: '제목', width: 'minmax(220px, 1fr)' }, { type: 'string', name: 'description', header: '설명', width: 220 }, ...(button ? [{ type: 'string', name: 'action', header: '', width: 40, record: { renderer: () => html`` } }] : []) ], rows: { appendable: false, editable: false, selectable: false }, list: { fields: ['title'], details: ['description'] } }) async function make(mode: string, button: boolean) { const el = await fixture(html``) await idle(el) return el } describe('Office density regression', () => { afterEach(async () => setViewport({ width: 800, height: 600 })) it('an action gutter does not enlarge the grid row on desktop or phone', async () => { for (const width of [1440, 375]) { await setViewport({ width, height: 812 }) const plain = await make('GRID', false) const action = await make('GRID', true) const field = (el: DataGrist) => (el.grist.renderRoot.querySelector('ox-grid-body') as any).renderRoot.querySelector('ox-grid-field') as HTMLElement expect(field(action).getBoundingClientRect().height).to.equal(field(plain).getBoundingClientRect().height) expect(field(action).getBoundingClientRect().height).to.be.at.most(32) const body = action.grist.renderRoot.querySelector('ox-grid-body') as any const buttonCell = Array.from(body.renderRoot.querySelectorAll('ox-grid-field')).find((cell: any) => cell.renderRoot.querySelector('button.icon')) as any expect(buttonCell.renderRoot.querySelector('button.icon').getBoundingClientRect().height).to.equal(26) } }) it('a phone list gives its text a full line and puts actions below it', async () => { await setViewport({ width: 375, height: 812 }) const el = await make('LIST', true) const row = el.grist.renderRoot.querySelector('ox-record-partial') as any await row.updateComplete const content = row.renderRoot.querySelector('[content]') as HTMLElement const action = row.renderRoot.querySelector('ox-list-gutter') as HTMLElement expect(content.getBoundingClientRect().width).to.be.above(320) expect(action.getBoundingClientRect().top).to.be.at.least(content.getBoundingClientRect().bottom) expect(row.scrollWidth).to.be.at.most(row.clientWidth) }) })