@operato/data-grist 10.29.52 → 10.29.59
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 +19 -0
- package/dist/src/data-card/data-card.js +5 -5
- package/dist/src/data-card/data-card.js.map +1 -1
- package/dist/src/data-grid/data-grid-body.d.ts +8 -0
- package/dist/src/data-grid/data-grid-body.js +44 -27
- package/dist/src/data-grid/data-grid-body.js.map +1 -1
- package/dist/src/data-grid/data-grid.d.ts +1 -1
- package/dist/src/data-grid/data-grid.js +3 -2
- package/dist/src/data-grid/data-grid.js.map +1 -1
- package/dist/src/data-grist.js +17 -17
- package/dist/src/data-grist.js.map +1 -1
- package/dist/src/data-list/data-list.js +5 -5
- package/dist/src/data-list/data-list.js.map +1 -1
- package/dist/src/data-manipulator.d.ts +16 -1
- package/dist/src/data-manipulator.js +57 -14
- package/dist/src/data-manipulator.js.map +1 -1
- package/dist/src/editors/ox-grist-editor-number.js +2 -7
- package/dist/src/editors/ox-grist-editor-number.js.map +1 -1
- package/dist/src/editors/ox-grist-editor.js +15 -13
- package/dist/src/editors/ox-grist-editor.js.map +1 -1
- package/dist/src/utils/field-value.d.ts +11 -0
- package/dist/src/utils/field-value.js +38 -0
- package/dist/src/utils/field-value.js.map +1 -0
- package/dist/test/data-integrity.test.d.ts +1 -0
- package/dist/test/data-integrity.test.js +145 -0
- package/dist/test/data-integrity.test.js.map +1 -0
- package/dist/test/edit-lifecycle.test.d.ts +2 -0
- package/dist/test/edit-lifecycle.test.js +270 -0
- package/dist/test/edit-lifecycle.test.js.map +1 -0
- package/dist/test/list-records.test.d.ts +1 -0
- package/dist/test/list-records.test.js +46 -0
- package/dist/test/list-records.test.js.map +1 -0
- package/dist/test/page-errors.d.ts +1 -0
- package/dist/test/page-errors.js +44 -0
- package/dist/test/page-errors.js.map +1 -0
- package/dist/test/paste-integrity.test.d.ts +1 -0
- package/dist/test/paste-integrity.test.js +163 -0
- package/dist/test/paste-integrity.test.js.map +1 -0
- package/dist/test/searchable-select.test.js +3 -2
- package/dist/test/searchable-select.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/test/data-integrity.test.ts +150 -0
- package/test/edit-lifecycle.test.ts +302 -0
- package/test/list-records.test.ts +58 -0
- package/test/page-errors.ts +43 -0
- package/test/paste-integrity.test.ts +168 -0
- package/test/searchable-select.test.ts +3 -2
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { expect, fixture } from '@open-wc/testing'
|
|
2
|
+
import { html } from 'lit'
|
|
3
|
+
|
|
4
|
+
import '../src/data-grist.js'
|
|
5
|
+
import { DataGrist } from '../src/data-grist.js'
|
|
6
|
+
import { DataGridBody } from '../src/data-grid/data-grid-body.js'
|
|
7
|
+
import { OxGristEditorNumber } from '../src/editors/ox-grist-editor-number.js'
|
|
8
|
+
import { failOnPageErrors } from './page-errors.js'
|
|
9
|
+
|
|
10
|
+
/* The clipboard holds `text` as `mime` while `run` reads it. */
|
|
11
|
+
async function withClipboard<T>(mime: string, text: string, run: () => Promise<T>): Promise<T> {
|
|
12
|
+
const previous = Object.getOwnPropertyDescriptor(navigator, 'clipboard')
|
|
13
|
+
Object.defineProperty(navigator, 'clipboard', { configurable: true, value: {
|
|
14
|
+
read: async () => [{ getType: async (requested: string) => {
|
|
15
|
+
if (requested !== mime) throw Error('no type')
|
|
16
|
+
return new Blob([text], { type: mime })
|
|
17
|
+
} }]
|
|
18
|
+
} })
|
|
19
|
+
try { return await run() }
|
|
20
|
+
finally {
|
|
21
|
+
if (previous) Object.defineProperty(navigator, 'clipboard', previous)
|
|
22
|
+
else delete (navigator as any).clipboard
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* What a paste sends, read off a body that only records its field changes. */
|
|
27
|
+
async function paste(mime: string, text: string, type = 'number', options: any = {}) {
|
|
28
|
+
const changes: any[] = []
|
|
29
|
+
const body: any = {
|
|
30
|
+
focused: { row: options.row ?? 0, column: 0 }, data: { records: options.records || [{ id: 'a', value: 1 }] },
|
|
31
|
+
columns: [{ name: 'value', type, record: { editable: options.editable ?? true } }],
|
|
32
|
+
config: { rows: { appendable: options.appendable ?? false } }, appendRecord: { __dirty__: '+' },
|
|
33
|
+
pasteTargets: (DataGridBody.prototype as any).pasteTargets,
|
|
34
|
+
resetEdit() {}, focus() {}, dispatchEvent(e: CustomEvent) { changes.push(e.detail) }
|
|
35
|
+
}
|
|
36
|
+
await withClipboard(mime, text, () => DataGridBody.prototype.paste.call(body))
|
|
37
|
+
return { body, changes }
|
|
38
|
+
}
|
|
39
|
+
const source = (mime: string, values: string[]) => mime === 'text/html'
|
|
40
|
+
? `<table>${values.map(value => `<tr><td>${value}</td></tr>`).join('')}</table>`
|
|
41
|
+
: values.join('\n')
|
|
42
|
+
|
|
43
|
+
describe('paste and input data contracts', () => {
|
|
44
|
+
for (const mime of ['text/html', 'text/plain']) {
|
|
45
|
+
for (const [type, input, expected] of [
|
|
46
|
+
['number', 'abc', 'abc'], ['number', '1,200', '1,200'],
|
|
47
|
+
['number', ' ', null], ['number', 'Infinity', 'Infinity'],
|
|
48
|
+
['number', '12.5', 12.5], ['integer', '12.5', 12], ['integer', '-1.5', -2],
|
|
49
|
+
['boolean', 'false', false], ['checkbox', 'true', true], ['number', '0', 0]
|
|
50
|
+
] as const) {
|
|
51
|
+
it(`${mime} parses ${type} ${input}`, async () => {
|
|
52
|
+
const { changes } = await paste(mime, source(mime, [input]), type)
|
|
53
|
+
expect(changes[0].after).to.equal(expected)
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
/* A blank cell clears an existing row's field and leaves a new row's to its default; id 0 is an existing row. */
|
|
57
|
+
for (const [type, input, records, row, expected] of [
|
|
58
|
+
['number', ' ', [{ id: 0, value: 1 }], 0, null],
|
|
59
|
+
['string', ' ', [{ id: 'a', value: 'x' }], 1, undefined],
|
|
60
|
+
['number', ' ', [{ id: 'a', value: 1 }], 1, undefined],
|
|
61
|
+
['select', ' ', [{ id: 'a', value: 1 }], 1, undefined]
|
|
62
|
+
] as const) {
|
|
63
|
+
it(`${mime} pastes a blank ${type} into ${row ? 'a new' : 'an existing'} row as ${expected}`, async () => {
|
|
64
|
+
const { changes } = await paste(mime, source(mime, [input]), type, { records, row, appendable: true })
|
|
65
|
+
expect(changes).to.have.length(1)
|
|
66
|
+
expect(changes[0].after).to.equal(expected)
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
it(`${mime} passes the destination row to editable`, async () => {
|
|
70
|
+
const seen: number[] = []
|
|
71
|
+
await paste(mime, source(mime, ['1', '2']), 'number', {
|
|
72
|
+
records: [{ id: 'a' }, { id: 'b' }],
|
|
73
|
+
editable: (_v: any, _c: any, _r: any, row: number) => { seen.push(row); return true }
|
|
74
|
+
})
|
|
75
|
+
expect(seen).to.eql([0, 1])
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
it('integer IME input uses the same conversion as the number editor', () => {
|
|
79
|
+
let after: any
|
|
80
|
+
const column: any = { name: 'value', type: 'integer', record: { editable: true } }
|
|
81
|
+
const body: any = { _imeBuffer: { value: '12.5' }, _resetIMEBuffer() {}, columns: [column],
|
|
82
|
+
data: { records: [{ value: 1 }] }, dispatchEvent(e: CustomEvent) { after = e.detail.after } }
|
|
83
|
+
DataGridBody.prototype._commitIMEBuffer.call(body, 0, 0)
|
|
84
|
+
const expected = OxGristEditorNumber.prototype.formatFromEditor.call({ column } as any, '12.5')
|
|
85
|
+
expect(after).to.equal(expected)
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
/* Pasting into a rendered grid: the rows that end up in the grid, through its own field-change handling. */
|
|
90
|
+
describe('paste into a grid', () => {
|
|
91
|
+
failOnPageErrors()
|
|
92
|
+
|
|
93
|
+
const mount = async (options: { appendable: boolean; editable?: boolean; validation?: () => Promise<boolean> }) => {
|
|
94
|
+
const el = await fixture<DataGrist>(html`<ox-grist
|
|
95
|
+
style="height:300px"
|
|
96
|
+
.config=${{
|
|
97
|
+
columns: [
|
|
98
|
+
{ name: 'amount', type: 'number', header: 'amount', record: { editable: options.editable ?? true }, validation: options.validation },
|
|
99
|
+
{ name: 'memo', type: 'string', header: 'memo', record: { editable: options.editable ?? true } }
|
|
100
|
+
],
|
|
101
|
+
rows: { appendable: options.appendable }
|
|
102
|
+
}}
|
|
103
|
+
.data=${{ records: [{ id: 'a', amount: 1, memo: 'kept' }] }}
|
|
104
|
+
></ox-grist>`)
|
|
105
|
+
await el.updateComplete
|
|
106
|
+
await el.grist.updateComplete
|
|
107
|
+
return el
|
|
108
|
+
}
|
|
109
|
+
const bodyOf = (el: DataGrist) => el.grist.renderRoot.querySelector('ox-grid-body') as any
|
|
110
|
+
const pasteAt = async (el: DataGrist, row: number, mime: string, text: string, column = 0) => {
|
|
111
|
+
const body = bodyOf(el)
|
|
112
|
+
body.focused = { row, column }
|
|
113
|
+
await withClipboard(mime, text, () => body.paste())
|
|
114
|
+
await el.updateComplete
|
|
115
|
+
}
|
|
116
|
+
const table = (mime: string, rows: string[][]) => mime === 'text/html'
|
|
117
|
+
? `<table>${rows.map(cells => `<tr>${cells.map(cell => `<td>${cell}</td>`).join('')}</tr>`).join('')}</table>`
|
|
118
|
+
: rows.map(cells => cells.join('\t')).join('\n')
|
|
119
|
+
const rows = (el: DataGrist) => el.grist.data.records.map(({ amount, memo }) => ({ amount, memo }))
|
|
120
|
+
|
|
121
|
+
for (const mime of ['text/html', 'text/plain']) {
|
|
122
|
+
it(`${mime} stops at the last row when rows cannot be appended`, async () => {
|
|
123
|
+
const el = await mount({ appendable: false })
|
|
124
|
+
await pasteAt(el, 0, mime, table(mime, [['2', 'x'], ['3', 'y']]))
|
|
125
|
+
expect(rows(el)).to.eql([{ amount: 2, memo: 'x' }])
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it(`${mime} appends new rows in order`, async () => {
|
|
129
|
+
const el = await mount({ appendable: true })
|
|
130
|
+
await pasteAt(el, 1, mime, table(mime, [['2', 'x'], ['3', 'y']]))
|
|
131
|
+
expect(rows(el)).to.eql([{ amount: 1, memo: 'kept' }, { amount: 2, memo: 'x' }, { amount: 3, memo: 'y' }])
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it(`${mime} adds no row for read-only cells`, async () => {
|
|
135
|
+
const el = await mount({ appendable: true, editable: false })
|
|
136
|
+
await pasteAt(el, 1, mime, table(mime, [['2', 'x']]))
|
|
137
|
+
expect(el.grist.data.records).to.have.length(1)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it(`${mime} adds no row for a blank new row`, async () => {
|
|
141
|
+
const el = await mount({ appendable: true })
|
|
142
|
+
await pasteAt(el, 1, mime, table(mime, [[' ', ' '], ['4', 'z']]))
|
|
143
|
+
expect(rows(el)).to.eql([{ amount: 1, memo: 'kept' }, { amount: 4, memo: 'z' }])
|
|
144
|
+
expect(el.dirtyRecords).to.have.length(1)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it(`${mime} keeps a new row's cells together while one is being validated`, async () => {
|
|
148
|
+
let resolve!: (valid: boolean) => void
|
|
149
|
+
const el = await mount({ appendable: true, validation: () => new Promise(done => (resolve = done)) })
|
|
150
|
+
await pasteAt(el, 1, mime, table(mime, [['5', 'w']]))
|
|
151
|
+
resolve(true)
|
|
152
|
+
await new Promise(done => setTimeout(done))
|
|
153
|
+
expect(rows(el)).to.eql([{ amount: 1, memo: 'kept' }, { amount: 5, memo: 'w' }])
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it(`${mime} into the append row and a key typed into it while the paste is validated make one row`, async () => {
|
|
157
|
+
let resolve!: (valid: boolean) => void
|
|
158
|
+
const el = await mount({ appendable: true, validation: () => new Promise(done => (resolve = done)) })
|
|
159
|
+
await pasteAt(el, 1, mime, table(mime, [['5']]))
|
|
160
|
+
const body = bodyOf(el)
|
|
161
|
+
body._imeBuffer.value = 'typed'
|
|
162
|
+
body._commitIMEBuffer(1, 1)
|
|
163
|
+
resolve(true)
|
|
164
|
+
await new Promise(done => setTimeout(done))
|
|
165
|
+
expect(rows(el)).to.eql([{ amount: 1, memo: 'kept' }, { amount: 5, memo: 'typed' }])
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
})
|
|
@@ -60,12 +60,13 @@ describe('a searchable select cell', () => {
|
|
|
60
60
|
expect(changes[0].after).to.equal(2)
|
|
61
61
|
})
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
/* Picking the shown value is still told, as no change: it supersedes an edit of the cell still being validated. */
|
|
64
|
+
it('a list closed on the value it had commits no change', async () => {
|
|
64
65
|
const { editor, changes } = await mount({ grade: 1 })
|
|
65
66
|
close(editor, '1')
|
|
66
67
|
editor.flush()
|
|
67
68
|
editor._onfocusout()
|
|
68
|
-
expect(changes.
|
|
69
|
+
expect(changes.every(change => change.after === change.before)).to.equal(true)
|
|
69
70
|
})
|
|
70
71
|
|
|
71
72
|
it('an untouched cell commits nothing on flush', async () => {
|