/* 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 '../src/filters/filters-form.js' /* * Every filter in the form says what it filters, beside its chooser. A select once carried its name only as a * placeholder, which a chosen value replaces - the bar then showed 「진행 중」 with nothing saying it was the status. */ const columns = [ { type: 'string', name: 'name', header: 'name', filter: 'i_like' }, { type: 'select', name: 'status', header: 'status', record: { options: ['', 'OPEN', 'CLOSED'] }, filter: 'in' }, { type: 'select', name: 'kind', header: 'kind', record: { options: ['', 'A', 'B'] }, filter: true }, { type: 'date', name: 'day', header: 'day', filter: 'between' } ] const settle = (ms = 150) => new Promise(resolve => setTimeout(resolve, ms)) describe('필터 라벨', () => { const ignoreResizeLoop = (e: ErrorEvent) => { if (String(e.message).includes('ResizeObserver loop')) { e.stopImmediatePropagation() e.preventDefault() } } let previousOnError: OnErrorEventHandler = null before(() => { window.addEventListener('error', ignoreResizeLoop, true) previousOnError = window.onerror window.onerror = (message, ...rest) => String(message).includes('ResizeObserver loop') ? true : previousOnError?.call(window, message, ...rest) }) after(() => { window.removeEventListener('error', ignoreResizeLoop, true) window.onerror = previousOnError }) it('every filter, a select too, sits in a label that names it', async () => { const el = (await fixture(html` ({ page: 1, limit: 20, total: 0, records: [] })} >
`)) as any await settle() const form = el.querySelector('ox-filters-form') as any await form.updateComplete const root = form.renderRoot as ShadowRoot const named = (name: string) => root.querySelector(`[name="${name}"]`) for (const name of ['name', 'status', 'kind', 'day']) { const chooser = named(name) expect(!!chooser, `${name} is rendered`).to.equal(true) const label = chooser!.closest('label[filter-title]') expect(!!label, `${name} sits in a label`).to.equal(true) expect(label!.querySelector('span')?.textContent?.trim()).to.equal(name) } }) /* * A header may draw more than its words - a help `?` beside them. The filter is not the header: it names the column * by its words, or a press on that `?` would also tick the checkbox around it. */ it('names a filter by the header words when the header draws more', async () => { const drawn = [ { type: 'checkbox', name: 'flag', header: { text: 'flag', renderer: () => html`flag ` }, filter: true }, { type: 'select', name: 'kind', header: { text: 'kind', renderer: () => html`kind ` }, record: { options: ['', 'A'] }, filter: true } ] const el = (await fixture(html` ({ page: 1, limit: 20, total: 0, records: [] })} >
`)) as any await settle() const form = el.querySelector('ox-filters-form') as any await form.updateComplete const root = form.renderRoot as ShadowRoot const deep = (node: ParentNode): boolean => Array.from(node.querySelectorAll('*')).some(one => one.matches('button.extra') || (!!one.shadowRoot && deep(one.shadowRoot))) expect(deep(root), 'the header drawing is not in the filter form').to.equal(false) expect(root.textContent).to.contain('flag') expect(root.textContent).to.contain('kind') }) /* * A phone: the date range takes most of the line, and the name beside it broke a syllable to a line (「올린 / 때」, * 2026-11-05, 375px). The name keeps its line; the choosers give way. */ it('keeps a filter name on one line when the form is narrow', async () => { const el = (await fixture(html` ({ page: 1, limit: 20, total: 0, records: [] })} >
`)) as any await settle() const form = el.querySelector('ox-filters-form') as any await form.updateComplete const name = (form.renderRoot as ShadowRoot).querySelector('label[filter-title] > span') as HTMLElement const lineHeight = parseFloat(getComputedStyle(name).lineHeight) || parseFloat(getComputedStyle(name).fontSize) * 1.6 expect(name.getBoundingClientRect().height < lineHeight * 1.5, `the name stands on ${Math.round(name.getBoundingClientRect().height)}px`).to.equal(true) }) /* * A filter the screen hides is set by the screen's own control (the employee list's department rail). A person's * saved filters never show it: it showed as a field and the address kept it as a raw chip (2026-11-08). */ it('a person\'s saved filters do not show a filter the screen hides', async () => { const hiddenColumns = [ { type: 'string', name: 'name', header: 'name', filter: 'i_like' }, { type: 'string', name: 'departmentId', hidden: true, filter: { operator: 'eq', hidden: true } } ] const el = (await fixture(html` ({ filters: [{ name: 'name' }, { name: 'departmentId', hidden: false }] }), save: (one: any) => one, reset: () => {} }} .fetchHandler=${async () => ({ page: 1, limit: 20, total: 0, records: [] })} >
`)) as any await settle(300) const form = el.querySelector('ox-filters-form') as any form.requestUpdate() await form.updateComplete const root = form.renderRoot as ShadowRoot expect(!!root.querySelector('[name="name"]'), 'the shown filter is drawn').to.equal(true) expect(!!root.querySelector('[name="departmentId"]'), 'the hidden filter is not drawn').to.equal(false) expect(root.querySelectorAll('.external-filters button').length, 'no raw chip').to.equal(0) }) })