@operato/data-grist 10.29.67 → 10.29.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/src/accumulator/accumulator.d.ts +3 -1
- package/dist/src/accumulator/accumulator.js +9 -0
- package/dist/src/accumulator/accumulator.js.map +1 -1
- package/dist/src/data-card/data-card-field.js +41 -4
- package/dist/src/data-card/data-card-field.js.map +1 -1
- package/dist/src/data-card/data-card-gutter.js +0 -4
- package/dist/src/data-card/data-card-gutter.js.map +1 -1
- package/dist/src/data-card/data-card.d.ts +1 -0
- package/dist/src/data-card/data-card.js +65 -0
- package/dist/src/data-card/data-card.js.map +1 -1
- package/dist/src/data-card/record-card.js +85 -13
- package/dist/src/data-card/record-card.js.map +1 -1
- package/dist/src/data-consumer.d.ts +2 -1
- package/dist/src/data-consumer.js.map +1 -1
- package/dist/src/data-grid/data-grid-body-style.js +14 -0
- package/dist/src/data-grid/data-grid-body-style.js.map +1 -1
- package/dist/src/data-grid/data-grid-body.js +16 -8
- package/dist/src/data-grid/data-grid-body.js.map +1 -1
- package/dist/src/data-grid/data-grid-field.d.ts +2 -0
- package/dist/src/data-grid/data-grid-field.js +35 -0
- package/dist/src/data-grid/data-grid-field.js.map +1 -1
- package/dist/src/data-grist.d.ts +11 -0
- package/dist/src/data-grist.js +38 -12
- package/dist/src/data-grist.js.map +1 -1
- package/dist/src/data-provider.js +1 -1
- package/dist/src/data-provider.js.map +1 -1
- package/dist/src/data-report.d.ts +1 -1
- package/dist/src/data-report.js +1 -1
- package/dist/src/data-report.js.map +1 -1
- package/dist/src/filters/filters-form.js +14 -5
- package/dist/src/filters/filters-form.js.map +1 -1
- package/dist/src/group-heading.d.ts +10 -0
- package/dist/src/group-heading.js +34 -0
- package/dist/src/group-heading.js.map +1 -0
- package/dist/src/renderers/ox-grist-renderer-text.js +2 -1
- package/dist/src/renderers/ox-grist-renderer-text.js.map +1 -1
- package/dist/test/card-selector.test.d.ts +1 -0
- package/dist/test/card-selector.test.js +58 -0
- package/dist/test/card-selector.test.js.map +1 -0
- package/dist/test/card-totals-narrow.test.d.ts +1 -0
- package/dist/test/card-totals-narrow.test.js +103 -0
- package/dist/test/card-totals-narrow.test.js.map +1 -0
- package/dist/test/filter-labels.test.js +22 -0
- package/dist/test/filter-labels.test.js.map +1 -1
- package/dist/test/filters-phone-wrap.test.d.ts +1 -0
- package/dist/test/filters-phone-wrap.test.js +17 -0
- package/dist/test/filters-phone-wrap.test.js.map +1 -0
- package/dist/test/group-heading.test.d.ts +1 -0
- package/dist/test/group-heading.test.js +187 -0
- package/dist/test/group-heading.test.js.map +1 -0
- package/dist/test/request-generation.test.js +1 -1
- package/dist/test/request-generation.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/test/card-selector.test.ts +68 -0
- package/test/card-totals-narrow.test.ts +128 -0
- package/test/filter-labels.test.ts +23 -0
- package/test/filters-phone-wrap.test.ts +22 -0
- package/test/group-heading.test.ts +221 -0
- package/test/request-generation.test.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@operato/data-grist",
|
|
3
|
-
"version": "10.29.
|
|
3
|
+
"version": "10.29.68",
|
|
4
4
|
"description": "User interface for grid (desktop) and list (mobile)",
|
|
5
5
|
"author": "heartyoh",
|
|
6
6
|
"type": "module",
|
|
@@ -78,13 +78,13 @@
|
|
|
78
78
|
"@material/web": "^2.0.0",
|
|
79
79
|
"@operato/headroom": "^10.29.1",
|
|
80
80
|
"@operato/i18n": "^10.29.27",
|
|
81
|
-
"@operato/input": "^10.29.
|
|
82
|
-
"@operato/layout": "^10.29.
|
|
81
|
+
"@operato/input": "^10.29.68",
|
|
82
|
+
"@operato/layout": "^10.29.68",
|
|
83
83
|
"@operato/list-state": "^10.29.61",
|
|
84
|
-
"@operato/p13n": "^10.29.
|
|
85
|
-
"@operato/popup": "^10.29.
|
|
84
|
+
"@operato/p13n": "^10.29.68",
|
|
85
|
+
"@operato/popup": "^10.29.68",
|
|
86
86
|
"@operato/pull-to-refresh": "^10.29.23",
|
|
87
|
-
"@operato/styles": "^10.29.
|
|
87
|
+
"@operato/styles": "^10.29.68",
|
|
88
88
|
"@operato/time-calculator": "^10.29.1",
|
|
89
89
|
"@operato/utils": "^10.29.61",
|
|
90
90
|
"i18next": "^24.2.1",
|
|
@@ -125,5 +125,5 @@
|
|
|
125
125
|
"prettier --write"
|
|
126
126
|
]
|
|
127
127
|
},
|
|
128
|
-
"gitHead": "
|
|
128
|
+
"gitHead": "28edfb19074463ffa10f36bdc9a3fb899c496e8a"
|
|
129
129
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/* Elements are compared by presence, not by value: a failing element comparison makes chai render the DOM and hang the runner. */
|
|
2
|
+
import { expect, fixture } from '@open-wc/testing'
|
|
3
|
+
import { html } from 'lit'
|
|
4
|
+
|
|
5
|
+
import '../src/data-grist.js'
|
|
6
|
+
import { DataGrist } from '../src/data-grist.js'
|
|
7
|
+
import { failOnPageErrors } from './page-errors.js'
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* A card's checkbox stands beside the title. It sat in the action row under the text, a line of its own far from
|
|
11
|
+
* what it selects (Office ledgers on a phone, 2026-11-05).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const records = [{ id: '1', title: 'one', amount: 990000 }]
|
|
15
|
+
const config = (gutters: any[]) => ({
|
|
16
|
+
columns: [
|
|
17
|
+
...gutters,
|
|
18
|
+
{ type: 'string', name: 'title', header: 'title' },
|
|
19
|
+
{ type: 'integer', name: 'amount', header: 'amount' }
|
|
20
|
+
],
|
|
21
|
+
rows: { appendable: false, selectable: { multiple: true } },
|
|
22
|
+
list: { fields: ['title'], details: ['amount'] }
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const idle = async (el: DataGrist) => {
|
|
26
|
+
while (!((await el.updateComplete) && (await el.grist.updateComplete)));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const cardOf = async (gutters: any[]) => {
|
|
30
|
+
const el = await fixture<DataGrist>(
|
|
31
|
+
html`<ox-grist style="width:340px;height:300px" mode="CARD" .config=${config(gutters)} .data=${{ records }}></ox-grist>`
|
|
32
|
+
)
|
|
33
|
+
await idle(el)
|
|
34
|
+
const card = el.grist.renderRoot.querySelector('ox-record-card') as any
|
|
35
|
+
await card.updateComplete
|
|
36
|
+
return card as HTMLElement & { renderRoot: ShadowRoot }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe('a card and its checkbox', () => {
|
|
40
|
+
failOnPageErrors()
|
|
41
|
+
|
|
42
|
+
it('stands in the top-right corner, on the title line, and takes no row of its own', async () => {
|
|
43
|
+
const card = await cardOf([{ type: 'gutter', gutterName: 'row-selector', multiple: true, forList: true }])
|
|
44
|
+
const box = card.renderRoot.querySelector('ox-card-gutter') as HTMLElement
|
|
45
|
+
const title = card.renderRoot.querySelector('ox-card-field[name]') as HTMLElement
|
|
46
|
+
const detail = card.renderRoot.querySelector('[detail]') as HTMLElement
|
|
47
|
+
expect(box, 'no checkbox').to.exist
|
|
48
|
+
|
|
49
|
+
const cardBox = card.getBoundingClientRect()
|
|
50
|
+
const boxRect = box.getBoundingClientRect()
|
|
51
|
+
const titleRect = title.getBoundingClientRect()
|
|
52
|
+
expect(boxRect.top, 'the checkbox is not on the title line').to.be.below(titleRect.bottom)
|
|
53
|
+
expect(cardBox.right - boxRect.right, 'the checkbox is not at the right edge').to.be.below(16)
|
|
54
|
+
expect(titleRect.right, 'the title runs under the checkbox').to.be.at.most(boxRect.left)
|
|
55
|
+
expect(cardBox.bottom - detail.getBoundingClientRect().bottom, 'the card keeps a row under its text').to.be.below(16)
|
|
56
|
+
expect(card.renderRoot.querySelector('[gutters]'), 'an empty action row').to.equal(null)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('leaves the other gutters in the action row', async () => {
|
|
60
|
+
const card = await cardOf([
|
|
61
|
+
{ type: 'gutter', gutterName: 'row-selector', multiple: true, forList: true },
|
|
62
|
+
{ type: 'gutter', gutterName: 'button', icon: 'edit', forList: true }
|
|
63
|
+
])
|
|
64
|
+
const row = card.renderRoot.querySelector('[gutters]') as HTMLElement
|
|
65
|
+
expect(row, 'no action row').to.exist
|
|
66
|
+
expect(row.querySelectorAll('ox-card-gutter').length).to.equal(1)
|
|
67
|
+
})
|
|
68
|
+
})
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/* Elements are compared by presence, not by value: a failing element comparison makes chai render the DOM and hang the runner. */
|
|
2
|
+
import { expect, fixture } from '@open-wc/testing'
|
|
3
|
+
import { html } from 'lit'
|
|
4
|
+
|
|
5
|
+
import '../src/data-grist.js'
|
|
6
|
+
import { DataGrist } from '../src/data-grist.js'
|
|
7
|
+
import { failOnPageErrors } from './page-errors.js'
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* A report read on a phone (2026-11-06). The grid's totals row is drawn as a totals card after the cards, and a
|
|
11
|
+
* grist with a narrow mode draws it while its own width is under narrowWidth - a table on a wide screen, cards on a
|
|
12
|
+
* phone, from one config.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const records = [
|
|
16
|
+
{ id: '1', name: 'one', shares: 15250, since: '2020-01-01' },
|
|
17
|
+
{ id: '2', name: 'two', shares: 5600, since: '2026-03-17' }
|
|
18
|
+
]
|
|
19
|
+
const config = (accumulator: boolean) => ({
|
|
20
|
+
columns: [
|
|
21
|
+
{ type: 'string', name: 'name', header: 'Name' },
|
|
22
|
+
{ type: 'integer', name: 'shares', header: 'Shares', accumulator: 'sum' }
|
|
23
|
+
],
|
|
24
|
+
rows: { appendable: false, editable: false, selectable: false, accumulator },
|
|
25
|
+
list: { fields: ['name'], details: ['shares'] }
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const idle = async (el: DataGrist) => {
|
|
29
|
+
while (!((await el.updateComplete) && (await el.grist.updateComplete)));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const frame = (width: number) => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)))
|
|
33
|
+
|
|
34
|
+
describe('a card list and its totals', () => {
|
|
35
|
+
failOnPageErrors()
|
|
36
|
+
|
|
37
|
+
it('draws the totals card after the cards, each total naming its column', async () => {
|
|
38
|
+
const el = await fixture<DataGrist>(
|
|
39
|
+
html`<ox-grist style="width:340px;height:400px" mode="CARD" .config=${config(true)} .data=${{ records }}></ox-grist>`
|
|
40
|
+
)
|
|
41
|
+
await idle(el)
|
|
42
|
+
const totals = el.grist.renderRoot.querySelector('[totals]') as HTMLElement
|
|
43
|
+
expect(totals, 'no totals card').to.exist
|
|
44
|
+
const shares = totals.querySelector('[total="shares"]') as HTMLElement
|
|
45
|
+
expect(shares.querySelector('label')!.textContent).to.equal('Shares')
|
|
46
|
+
expect(shares.textContent).to.contain('20850')
|
|
47
|
+
expect(totals.querySelector('[total="name"]'), 'a column with no accumulator is totalled').to.equal(null)
|
|
48
|
+
|
|
49
|
+
const cards = el.grist.renderRoot.querySelectorAll('ox-record-card')
|
|
50
|
+
expect(totals.getBoundingClientRect().top, 'the totals stand above a card').to.be.at.least(cards[cards.length - 1].getBoundingClientRect().bottom)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('draws no totals card when the rows do not accumulate', async () => {
|
|
54
|
+
const el = await fixture<DataGrist>(
|
|
55
|
+
html`<ox-grist style="width:340px;height:400px" mode="CARD" .config=${config(false)} .data=${{ records }}></ox-grist>`
|
|
56
|
+
)
|
|
57
|
+
await idle(el)
|
|
58
|
+
expect(el.grist.renderRoot.querySelector('[totals]')).to.equal(null)
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
describe('a grist with a narrow mode', () => {
|
|
63
|
+
failOnPageErrors()
|
|
64
|
+
|
|
65
|
+
it('draws its mode when wide and its narrow mode when narrow, by its own width', async () => {
|
|
66
|
+
const el = await fixture<DataGrist>(
|
|
67
|
+
html`<ox-grist style="display:flex;width:900px;height:400px" mode="GRID" narrow-mode="CARD" .config=${config(true)} .data=${{ records }}></ox-grist>`
|
|
68
|
+
)
|
|
69
|
+
await frame(0)
|
|
70
|
+
await idle(el)
|
|
71
|
+
expect(el.shownMode).to.equal('GRID')
|
|
72
|
+
expect(el.renderRoot.querySelector('ox-grid'), 'not a grid while wide').to.exist
|
|
73
|
+
|
|
74
|
+
el.style.width = '340px'
|
|
75
|
+
await frame(0)
|
|
76
|
+
await idle(el)
|
|
77
|
+
expect(el.shownMode).to.equal('CARD')
|
|
78
|
+
expect(el.renderRoot.querySelector('ox-card'), 'not cards while narrow').to.exist
|
|
79
|
+
expect(el.mode, 'the requested mode was overwritten').to.equal('GRID')
|
|
80
|
+
|
|
81
|
+
el.style.width = '900px'
|
|
82
|
+
await frame(0)
|
|
83
|
+
await idle(el)
|
|
84
|
+
expect(el.renderRoot.querySelector('ox-grid'), 'not a grid again once wide').to.exist
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('keeps its mode at every width when no narrow mode is set', async () => {
|
|
88
|
+
const el = await fixture<DataGrist>(
|
|
89
|
+
html`<ox-grist style="display:flex;width:340px;height:400px" mode="GRID" .config=${config(true)} .data=${{ records }}></ox-grist>`
|
|
90
|
+
)
|
|
91
|
+
await frame(0)
|
|
92
|
+
await idle(el)
|
|
93
|
+
expect(el.renderRoot.querySelector('ox-grid')).to.exist
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
describe('a card detail with a label', () => {
|
|
98
|
+
failOnPageErrors()
|
|
99
|
+
|
|
100
|
+
it('keeps the label whole when details stand in a row', async () => {
|
|
101
|
+
const labelled = {
|
|
102
|
+
...config(false),
|
|
103
|
+
columns: [
|
|
104
|
+
{ type: 'string', name: 'name', header: 'Name' },
|
|
105
|
+
{ type: 'string', name: 'since', header: 'Since', label: { renderer: () => '취득일' } }
|
|
106
|
+
],
|
|
107
|
+
list: { fields: ['name'], details: ['since'] }
|
|
108
|
+
}
|
|
109
|
+
const el = await fixture<DataGrist>(
|
|
110
|
+
html`<ox-grist style="width:340px;height:400px;font-size:13px;--data-card-detail-direction:row;--data-card-item-etc-label-font:400 11.5px sans-serif" mode="CARD" .config=${labelled} .data=${{ records }}></ox-grist>`
|
|
111
|
+
)
|
|
112
|
+
await idle(el)
|
|
113
|
+
const card = el.grist.renderRoot.querySelector('ox-record-card') as any
|
|
114
|
+
const field = card.renderRoot.querySelector('[detail] ox-card-field') as HTMLElement & { renderRoot: ShadowRoot }
|
|
115
|
+
const label = field.renderRoot.querySelector('label') as HTMLElement
|
|
116
|
+
expect(label.scrollWidth, 'the label is cut').to.be.at.most(label.clientWidth)
|
|
117
|
+
const range = document.createRange()
|
|
118
|
+
range.setStartAfter(label)
|
|
119
|
+
range.setEnd(field.renderRoot, field.renderRoot.childNodes.length)
|
|
120
|
+
const words = document.createRange()
|
|
121
|
+
words.selectNodeContents(label)
|
|
122
|
+
expect(range.getBoundingClientRect().left - words.getBoundingClientRect().right, 'the label touches its value').to.be.at.least(4)
|
|
123
|
+
const value = Array.from(field.renderRoot.children).find(child => child !== label && child.tagName !== 'STYLE') as HTMLElement
|
|
124
|
+
const text = document.createRange()
|
|
125
|
+
text.selectNodeContents(value)
|
|
126
|
+
expect(value.getBoundingClientRect().width, 'the value is cut').to.be.at.least(text.getBoundingClientRect().width - 0.01)
|
|
127
|
+
})
|
|
128
|
+
})
|
|
@@ -96,4 +96,27 @@ describe('필터 라벨', () => {
|
|
|
96
96
|
expect(root.textContent).to.contain('flag')
|
|
97
97
|
expect(root.textContent).to.contain('kind')
|
|
98
98
|
})
|
|
99
|
+
/*
|
|
100
|
+
* A phone: the date range takes most of the line, and the name beside it broke a syllable to a line (「올린 / 때」,
|
|
101
|
+
* 2026-11-05, 375px). The name keeps its line; the choosers give way.
|
|
102
|
+
*/
|
|
103
|
+
it('keeps a filter name on one line when the form is narrow', async () => {
|
|
104
|
+
const el = (await fixture(html`
|
|
105
|
+
<ox-grist
|
|
106
|
+
style="height: 300px; width: 240px"
|
|
107
|
+
mode="GRID"
|
|
108
|
+
.config=${{ columns: [{ type: 'date', name: 'day', header: '올린 때', filter: 'between' }], pagination: { pages: [20] } }}
|
|
109
|
+
.fetchHandler=${async () => ({ page: 1, limit: 20, total: 0, records: [] })}
|
|
110
|
+
>
|
|
111
|
+
<div slot="headroom"><ox-filters-form without-search></ox-filters-form></div>
|
|
112
|
+
</ox-grist>
|
|
113
|
+
`)) as any
|
|
114
|
+
await settle()
|
|
115
|
+
|
|
116
|
+
const form = el.querySelector('ox-filters-form') as any
|
|
117
|
+
await form.updateComplete
|
|
118
|
+
const name = (form.renderRoot as ShadowRoot).querySelector('label[filter-title] > span') as HTMLElement
|
|
119
|
+
const lineHeight = parseFloat(getComputedStyle(name).lineHeight) || parseFloat(getComputedStyle(name).fontSize) * 1.6
|
|
120
|
+
expect(name.getBoundingClientRect().height < lineHeight * 1.5, `the name stands on ${Math.round(name.getBoundingClientRect().height)}px`).to.equal(true)
|
|
121
|
+
})
|
|
99
122
|
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { expect } from '@open-wc/testing'
|
|
2
|
+
|
|
3
|
+
import { OxFiltersForm } from '../src/filters/filters-form.js'
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Filters stand side by side and wrap to the next line on a phone as on a desk. A phone rule stacked them one to a
|
|
7
|
+
* line, so a ledger's ten filters took half the screen with its right half empty (2026-11-05, 375px).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const text = (styles: unknown) =>
|
|
11
|
+
(Array.isArray(styles) ? styles : [styles]).map(s => String((s as { cssText?: string }).cssText ?? s)).join('\n')
|
|
12
|
+
|
|
13
|
+
describe('filters on a phone', () => {
|
|
14
|
+
it('wrap in rows; no phone rule turns the form into a column', () => {
|
|
15
|
+
const css = text(OxFiltersForm.styles)
|
|
16
|
+
const form = css.slice(css.indexOf('form {'), css.indexOf('}', css.indexOf('form {')))
|
|
17
|
+
expect(form).to.contain('flex-flow: row wrap;')
|
|
18
|
+
|
|
19
|
+
const phone = css.slice(css.indexOf('@media only screen and (max-width: 460px)'))
|
|
20
|
+
expect(phone).not.to.match(/(^|\s)form \{[^}]*column/)
|
|
21
|
+
})
|
|
22
|
+
})
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/* Elements are compared by presence, not by value: a failing element comparison makes chai render the DOM and hang the runner. */
|
|
2
|
+
import { expect, fixture } from '@open-wc/testing'
|
|
3
|
+
import { html } from 'lit'
|
|
4
|
+
|
|
5
|
+
import '../src/data-grist.js'
|
|
6
|
+
import { DataGrist } from '../src/data-grist.js'
|
|
7
|
+
import { failOnPageErrors } from './page-errors.js'
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* Group headings (rows.groups): the management check reads 「자금 지연」 above its late money, in a table on a wide
|
|
11
|
+
* screen and over the cards on a phone (2026-11-06). A heading stands wherever the group value changes, written by
|
|
12
|
+
* the group column's renderer.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const NAMES: Record<string, string> = { funds: 'Late money', books: 'Books' }
|
|
16
|
+
const records = [
|
|
17
|
+
{ id: '1', group: 'funds', what: 'Overdue collections', count: 23 },
|
|
18
|
+
{ id: '2', group: 'funds', what: 'Unpaid VAT', count: 1 },
|
|
19
|
+
{ id: '3', group: 'books', what: 'Lines without an account', count: 4 }
|
|
20
|
+
]
|
|
21
|
+
const config = (groups: any[]) => ({
|
|
22
|
+
columns: [
|
|
23
|
+
{ type: 'string', name: 'group', header: 'Group', hidden: true, record: { renderer: (value: string) => NAMES[value] } },
|
|
24
|
+
{ type: 'string', name: 'what', header: 'What' },
|
|
25
|
+
{ type: 'integer', name: 'count', header: 'Count' }
|
|
26
|
+
],
|
|
27
|
+
rows: { appendable: false, editable: false, selectable: false, groups },
|
|
28
|
+
list: { fields: ['what'], details: ['count'] }
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const idle = async (el: DataGrist) => {
|
|
32
|
+
while (!((await el.updateComplete) && (await el.grist.updateComplete)));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const mount = async (mode: 'GRID' | 'CARD', groups: any[]) => {
|
|
36
|
+
const el = await fixture<DataGrist>(
|
|
37
|
+
html`<ox-grist style="display:flex;width:700px;height:400px" mode=${mode} .config=${config(groups)} .data=${{ records }}></ox-grist>`
|
|
38
|
+
)
|
|
39
|
+
await idle(el)
|
|
40
|
+
/* The grid draws its rows in ox-grid-body. */
|
|
41
|
+
const root = (mode == 'GRID' ? (el.grist.renderRoot.querySelector('ox-grid-body') as any).renderRoot : el.grist.renderRoot) as ShadowRoot
|
|
42
|
+
return root
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe('group headings', () => {
|
|
46
|
+
failOnPageErrors()
|
|
47
|
+
|
|
48
|
+
for (const mode of ['GRID', 'CARD'] as const) {
|
|
49
|
+
it(`stand where the group changes, in the group column's words (${mode})`, async () => {
|
|
50
|
+
const root = await mount(mode, [{ column: 'group' }])
|
|
51
|
+
const headings = Array.from(root.querySelectorAll('[group-heading]')) as HTMLElement[]
|
|
52
|
+
expect(headings.map(one => one.textContent!.trim())).to.deep.equal(['Late money', 'Books'])
|
|
53
|
+
|
|
54
|
+
/* Each heading stands above the first row of its group and spans the whole row. */
|
|
55
|
+
const rows = Array.from(root.querySelectorAll(mode == 'GRID' ? 'ox-grid-field[role="gridcell"]' : 'ox-record-card')) as HTMLElement[]
|
|
56
|
+
const firstOf = (text: string) =>
|
|
57
|
+
rows.find((one: any) => one.record?.what === text && (mode == 'CARD' || one.column?.name === 'what'))!.getBoundingClientRect()
|
|
58
|
+
const box = (one: HTMLElement) => (mode == 'GRID' ? (one.firstElementChild as HTMLElement) : one).getBoundingClientRect()
|
|
59
|
+
expect(box(headings[0]).bottom).to.be.at.most(firstOf('Overdue collections').top + 0.5)
|
|
60
|
+
expect(box(headings[1]).top).to.be.at.least(firstOf('Unpaid VAT').bottom - 0.5)
|
|
61
|
+
expect(box(headings[1]).bottom).to.be.at.most(firstOf('Lines without an account').top + 0.5)
|
|
62
|
+
expect(box(headings[1]).width, 'the heading does not span the row').to.be.above(600)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it(`are not drawn when the rows are not grouped (${mode})`, async () => {
|
|
66
|
+
const root = await mount(mode, [])
|
|
67
|
+
expect(root.querySelector('[group-heading]')).to.equal(null)
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
describe('a link a renderer returns', () => {
|
|
73
|
+
failOnPageErrors()
|
|
74
|
+
|
|
75
|
+
for (const mode of ['GRID', 'CARD'] as const) {
|
|
76
|
+
it(`reads as the text around it, not the browser's blue underline (${mode})`, async () => {
|
|
77
|
+
const linked = {
|
|
78
|
+
...config([]),
|
|
79
|
+
columns: [
|
|
80
|
+
{ type: 'string', name: 'what', header: 'What', record: { renderer: (value: string) => html`<a href="#open">${value}</a>` } },
|
|
81
|
+
{ type: 'integer', name: 'count', header: 'Count' }
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
const el = await fixture<DataGrist>(
|
|
85
|
+
html`<ox-grist style="display:flex;width:700px;height:400px;color:rgb(10, 20, 30)" mode=${mode} .config=${linked} .data=${{ records }}></ox-grist>`
|
|
86
|
+
)
|
|
87
|
+
await idle(el)
|
|
88
|
+
const root = (mode == 'GRID' ? (el.grist.renderRoot.querySelector('ox-grid-body') as any).renderRoot : el.grist.renderRoot) as ShadowRoot
|
|
89
|
+
const fields = Array.from(root.querySelectorAll(mode == 'GRID' ? 'ox-grid-field' : 'ox-record-card')) as any[]
|
|
90
|
+
const holder = mode == 'GRID' ? fields.find(one => one.column?.name === 'what') : fields[0].renderRoot.querySelector('ox-card-field')
|
|
91
|
+
const link = holder.renderRoot.querySelector('a') as HTMLElement
|
|
92
|
+
const style = getComputedStyle(link)
|
|
93
|
+
expect(style.textDecorationLine).to.equal('none')
|
|
94
|
+
expect(style.color).to.equal(getComputedStyle(link.parentElement ?? holder).color)
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
describe('a card field with nothing to show', () => {
|
|
100
|
+
failOnPageErrors()
|
|
101
|
+
|
|
102
|
+
it('takes no place - no label stands alone', async () => {
|
|
103
|
+
const labelled = {
|
|
104
|
+
...config([]),
|
|
105
|
+
columns: [
|
|
106
|
+
{ type: 'string', name: 'what', header: 'What' },
|
|
107
|
+
{ type: 'integer', name: 'count', header: 'Count', label: { renderer: () => 'Count' }, record: { renderer: (value: any) => value ?? '' } }
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
const el = await fixture<DataGrist>(
|
|
111
|
+
html`<ox-grist style="display:flex;width:700px;height:400px" mode="CARD" .config=${labelled} .data=${{ records: [{ id: '1', what: 'Azure' }, { id: '2', what: 'VAT', count: 1 }] }}></ox-grist>`
|
|
112
|
+
)
|
|
113
|
+
await idle(el)
|
|
114
|
+
const cards = Array.from(el.grist.renderRoot.querySelectorAll('ox-record-card')) as any[]
|
|
115
|
+
const countOf = (card: any) => card.renderRoot.querySelector('[detail] ox-card-field') as HTMLElement
|
|
116
|
+
expect(countOf(cards[0]).getBoundingClientRect().width, 'an empty field stands').to.equal(0)
|
|
117
|
+
expect(countOf(cards[1]).getBoundingClientRect().width, 'a field with a value is gone').to.be.above(0)
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
describe('the rows under a row (tree.childrenProperty)', () => {
|
|
122
|
+
failOnPageErrors()
|
|
123
|
+
|
|
124
|
+
const tree = [
|
|
125
|
+
{ id: '1', group: 'funds', what: 'Planned money not seen', count: 3, children: [{ id: '1a', what: 'Azure', count: 7 }, { id: '1b', what: 'Office 365' }] },
|
|
126
|
+
{ id: '2', group: 'funds', what: 'Unpaid VAT', count: 1 },
|
|
127
|
+
{ id: '3', group: 'books', what: 'Lines without an account', count: 4 }
|
|
128
|
+
]
|
|
129
|
+
const treeConfig = { ...config([{ column: 'group' }]), tree: { childrenProperty: 'children', expanded: () => true } }
|
|
130
|
+
|
|
131
|
+
const mount = async (mode: 'GRID' | 'CARD') => {
|
|
132
|
+
const el = await fixture<DataGrist>(
|
|
133
|
+
html`<ox-grist style="display:flex;width:700px;height:500px" mode=${mode} .config=${treeConfig} .data=${{ records: tree }}></ox-grist>`
|
|
134
|
+
)
|
|
135
|
+
await idle(el)
|
|
136
|
+
return el
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
it('stand inside the parent card on a card list, not as cards of their own', async () => {
|
|
140
|
+
const el = await mount('CARD')
|
|
141
|
+
const cards = Array.from(el.grist.renderRoot.querySelectorAll('ox-record-card')) as any[]
|
|
142
|
+
expect(cards.map(card => card.record.what)).to.deep.equal(['Planned money not seen', 'Unpaid VAT', 'Lines without an account'])
|
|
143
|
+
const children = Array.from(cards[0].renderRoot.querySelectorAll('[child]')) as HTMLElement[]
|
|
144
|
+
expect(children.map(child => (child.querySelector('ox-card-field') as any).record.what)).to.deep.equal(['Azure', 'Office 365'])
|
|
145
|
+
expect(cards[1].renderRoot.querySelector('[children]'), 'a row with no children shows a children block').to.equal(null)
|
|
146
|
+
/* A child's title takes its own line; its details stand under it. */
|
|
147
|
+
const [title, detail] = Array.from(children[0].querySelectorAll('ox-card-field')) as HTMLElement[]
|
|
148
|
+
const titleBox = title.getBoundingClientRect()
|
|
149
|
+
expect(detail.getBoundingClientRect().top, 'the details stand beside the title').to.be.above(titleBox.top + titleBox.height / 2)
|
|
150
|
+
/* The room between two children is wider than the room between a child's two lines. */
|
|
151
|
+
const between = children[1].getBoundingClientRect().top - children[0].getBoundingClientRect().bottom
|
|
152
|
+
const within = detail.getBoundingClientRect().top - titleBox.bottom
|
|
153
|
+
expect(between, 'the children run together').to.be.at.least(within + 8)
|
|
154
|
+
const headings = Array.from(el.grist.renderRoot.querySelectorAll('[group-heading]')) as HTMLElement[]
|
|
155
|
+
expect(headings.map(one => one.textContent!.trim())).to.deep.equal(['Late money', 'Books'])
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('stand as rows under the parent in the grid, and do not open a group again', async () => {
|
|
159
|
+
const el = await mount('GRID')
|
|
160
|
+
const body = (el.grist.renderRoot.querySelector('ox-grid-body') as any).renderRoot as ShadowRoot
|
|
161
|
+
const whats = (Array.from(body.querySelectorAll('ox-grid-field[role="gridcell"]')) as any[]).filter(one => one.column?.name === 'what').map(one => one.record.what)
|
|
162
|
+
expect(whats).to.deep.equal(['Planned money not seen', 'Azure', 'Office 365', 'Unpaid VAT', 'Lines without an account'])
|
|
163
|
+
/* A child steps in under its parent at its first column, and only there. */
|
|
164
|
+
const cell = (what: string, name: string) =>
|
|
165
|
+
(Array.from(body.querySelectorAll('ox-grid-field[role="gridcell"]')) as any[]).find(one => one.record.what === what && one.column?.name === name)
|
|
166
|
+
const pad = (one: HTMLElement) => parseFloat(getComputedStyle(one).paddingLeft)
|
|
167
|
+
expect(pad(cell('Azure', 'what')), 'a child does not step in').to.be.above(pad(cell('Planned money not seen', 'what')) + 8)
|
|
168
|
+
expect(pad(cell('Azure', 'count'))).to.equal(pad(cell('Planned money not seen', 'count')))
|
|
169
|
+
const headings = Array.from(body.querySelectorAll('[group-heading]')) as HTMLElement[]
|
|
170
|
+
expect(headings.map(one => one.textContent!.trim())).to.deep.equal(['Late money', 'Books'])
|
|
171
|
+
})
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
describe('a page button a renderer returns', () => {
|
|
175
|
+
failOnPageErrors()
|
|
176
|
+
|
|
177
|
+
for (const mode of ['GRID', 'CARD'] as const) {
|
|
178
|
+
it(`takes the page's quiet look, not the filled gutter button (${mode})`, async () => {
|
|
179
|
+
const acting = {
|
|
180
|
+
...config([]),
|
|
181
|
+
columns: [
|
|
182
|
+
{ type: 'string', name: 'what', header: 'What' },
|
|
183
|
+
{ type: 'string', name: 'act', header: '', record: { renderer: () => html`<button quiet small>Open</button>` } }
|
|
184
|
+
],
|
|
185
|
+
list: { fields: ['what'], details: ['act'] }
|
|
186
|
+
}
|
|
187
|
+
const el = await fixture<DataGrist>(
|
|
188
|
+
html`<ox-grist style="display:flex;width:700px;height:400px" mode=${mode} .config=${acting} .data=${{ records }}></ox-grist>`
|
|
189
|
+
)
|
|
190
|
+
await idle(el)
|
|
191
|
+
const root = (mode == 'GRID' ? (el.grist.renderRoot.querySelector('ox-grid-body') as any).renderRoot : el.grist.renderRoot) as ShadowRoot
|
|
192
|
+
const fields = Array.from(root.querySelectorAll(mode == 'GRID' ? 'ox-grid-field' : 'ox-record-card')) as any[]
|
|
193
|
+
const holder = mode == 'GRID' ? fields.find(one => one.column?.name === 'act') : fields[0].renderRoot.querySelector('[detail] ox-card-field')
|
|
194
|
+
const button = holder.renderRoot.querySelector('button') as HTMLElement
|
|
195
|
+
expect(getComputedStyle(button).backgroundColor, 'a quiet button is filled').to.be.oneOf(['rgba(0, 0, 0, 0)', 'transparent'])
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
describe('an empty text detail on a card', () => {
|
|
201
|
+
failOnPageErrors()
|
|
202
|
+
|
|
203
|
+
it('takes no place with the default text renderer', async () => {
|
|
204
|
+
const texts = {
|
|
205
|
+
...config([]),
|
|
206
|
+
columns: [
|
|
207
|
+
{ type: 'string', name: 'what', header: 'What' },
|
|
208
|
+
{ type: 'string', name: 'summary', header: 'Summary', label: { renderer: () => 'Summary' } }
|
|
209
|
+
],
|
|
210
|
+
list: { fields: ['what'], details: ['summary'] }
|
|
211
|
+
}
|
|
212
|
+
const el = await fixture<DataGrist>(
|
|
213
|
+
html`<ox-grist style="display:flex;width:700px;height:400px" mode="CARD" .config=${texts} .data=${{ records: [{ id: '1', what: 'one' }, { id: '2', what: 'two', summary: 'said' }] }}></ox-grist>`
|
|
214
|
+
)
|
|
215
|
+
await idle(el)
|
|
216
|
+
const cards = Array.from(el.grist.renderRoot.querySelectorAll('ox-record-card')) as any[]
|
|
217
|
+
const summaryOf = (card: any) => card.renderRoot.querySelector('[detail] ox-card-field') as HTMLElement
|
|
218
|
+
expect(summaryOf(cards[0]).getBoundingClientRect().width, 'an empty summary stands').to.equal(0)
|
|
219
|
+
expect(summaryOf(cards[1]).getBoundingClientRect().width).to.be.above(0)
|
|
220
|
+
})
|
|
221
|
+
})
|