@operato/data-grist 10.29.38 → 10.29.40
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 +18 -0
- package/coverage/lcov-report/index.html +166 -166
- package/coverage/lcov-report/webpack/bootstrap.html +1 -1
- package/coverage/lcov-report/webpack/index.html +1 -1
- package/coverage/lcov-report/webpack/runtime/define property getters.html +1 -1
- package/coverage/lcov-report/webpack/runtime/global.html +1 -1
- package/coverage/lcov-report/webpack/runtime/hasOwnProperty shorthand.html +1 -1
- package/coverage/lcov-report/webpack/runtime/index.html +1 -1
- package/coverage/lcov-report/webpack/runtime/make namespace object.html +1 -1
- package/coverage/lcov.info +58474 -56991
- package/dist/src/data-consumer.d.ts +7 -1
- package/dist/src/data-consumer.js.map +1 -1
- package/dist/src/data-grist.d.ts +19 -3
- package/dist/src/data-grist.js +163 -39
- package/dist/src/data-grist.js.map +1 -1
- package/dist/src/data-provider.d.ts +8 -1
- package/dist/src/data-provider.js +94 -46
- package/dist/src/data-provider.js.map +1 -1
- package/dist/src/editors/ox-grist-editor.d.ts +2 -0
- package/dist/src/editors/ox-grist-editor.js +17 -4
- package/dist/src/editors/ox-grist-editor.js.map +1 -1
- package/dist/src/filters/filter-checkbox.js +3 -2
- package/dist/src/filters/filter-checkbox.js.map +1 -1
- package/dist/src/filters/filter-input-barcode.js +2 -1
- package/dist/src/filters/filter-input-barcode.js.map +1 -1
- package/dist/src/filters/filter-input.js +2 -1
- package/dist/src/filters/filter-input.js.map +1 -1
- package/dist/src/filters/filter-ownership.d.ts +15 -0
- package/dist/src/filters/filter-ownership.js +48 -0
- package/dist/src/filters/filter-ownership.js.map +1 -0
- package/dist/src/filters/filter-range-date.js +3 -2
- package/dist/src/filters/filter-range-date.js.map +1 -1
- package/dist/src/filters/filter-range-number.js +3 -2
- package/dist/src/filters/filter-range-number.js.map +1 -1
- package/dist/src/filters/filter-select-buttons.js +2 -1
- package/dist/src/filters/filter-select-buttons.js.map +1 -1
- package/dist/src/filters/filters-form.js +80 -22
- package/dist/src/filters/filters-form.js.map +1 -1
- package/dist/src/utils/list-param.d.ts +5 -3
- package/dist/src/utils/list-param.js +6 -37
- package/dist/src/utils/list-param.js.map +1 -1
- package/dist/test/address-intents.test.d.ts +1 -0
- package/dist/test/address-intents.test.js +202 -0
- package/dist/test/address-intents.test.js.map +1 -0
- package/dist/test/filter-ownership.test.d.ts +1 -0
- package/dist/test/filter-ownership.test.js +40 -0
- package/dist/test/filter-ownership.test.js.map +1 -0
- package/dist/test/record-view-popup-editor.test.js +13 -0
- package/dist/test/record-view-popup-editor.test.js.map +1 -1
- package/dist/test/request-generation.test.d.ts +1 -0
- package/dist/test/request-generation.test.js +120 -0
- package/dist/test/request-generation.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -7
- package/test/address-intents.test.ts +203 -0
- package/test/filter-ownership.test.ts +51 -0
- package/test/record-view-popup-editor.test.ts +16 -0
- package/test/request-generation.test.ts +128 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@operato/data-grist",
|
|
3
|
-
"version": "10.29.
|
|
3
|
+
"version": "10.29.40",
|
|
4
4
|
"description": "User interface for grid (desktop) and list (mobile)",
|
|
5
5
|
"author": "heartyoh",
|
|
6
6
|
"type": "module",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"exports": {
|
|
21
21
|
".": "./dist/src/index.js",
|
|
22
22
|
"./package.json": "./package.json",
|
|
23
|
+
"./list-param.js": "./dist/src/utils/list-param.js",
|
|
23
24
|
"./ox-grist.js": "./dist/src/data-grist.js",
|
|
24
25
|
"./ox-report.js": "./dist/src/data-report.js",
|
|
25
26
|
"./ox-empty-note.js": "./dist/src/empty-note.js",
|
|
@@ -32,6 +33,9 @@
|
|
|
32
33
|
},
|
|
33
34
|
"typesVersions": {
|
|
34
35
|
"*": {
|
|
36
|
+
"list-param.js": [
|
|
37
|
+
"dist/src/utils/list-param.d.ts"
|
|
38
|
+
],
|
|
35
39
|
"ox-grist.js": [
|
|
36
40
|
"dist/src/data-grist.d.ts"
|
|
37
41
|
],
|
|
@@ -74,14 +78,14 @@
|
|
|
74
78
|
"@material/web": "^2.0.0",
|
|
75
79
|
"@operato/headroom": "^10.29.1",
|
|
76
80
|
"@operato/i18n": "^10.29.27",
|
|
77
|
-
"@operato/input": "^10.29.
|
|
78
|
-
"@operato/list-state": "^10.29.
|
|
79
|
-
"@operato/p13n": "^10.29.
|
|
80
|
-
"@operato/popup": "^10.29.
|
|
81
|
+
"@operato/input": "^10.29.40",
|
|
82
|
+
"@operato/list-state": "^10.29.39",
|
|
83
|
+
"@operato/p13n": "^10.29.40",
|
|
84
|
+
"@operato/popup": "^10.29.40",
|
|
81
85
|
"@operato/pull-to-refresh": "^10.29.23",
|
|
82
86
|
"@operato/styles": "^10.29.30",
|
|
83
87
|
"@operato/time-calculator": "^10.29.1",
|
|
84
|
-
"@operato/utils": "^10.29.
|
|
88
|
+
"@operato/utils": "^10.29.39",
|
|
85
89
|
"i18next": "^24.2.1",
|
|
86
90
|
"json5": "^2.2.0",
|
|
87
91
|
"lit": "^3.1.2",
|
|
@@ -120,5 +124,5 @@
|
|
|
120
124
|
"prettier --write"
|
|
121
125
|
]
|
|
122
126
|
},
|
|
123
|
-
"gitHead": "
|
|
127
|
+
"gitHead": "54a5aa4812524b56cd5a1b67e76d9fad28abffc8"
|
|
124
128
|
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { expect, fixture } from '@open-wc/testing'
|
|
2
|
+
import { html } from 'lit'
|
|
3
|
+
import { addressController, writeAddress } from '@operato/utils/address.js'
|
|
4
|
+
import { encodeListQuery } from '@operato/utils/list-query.js'
|
|
5
|
+
import type { DataGrist } from '../src/data-grist.js'
|
|
6
|
+
import '../src/data-grist.js'
|
|
7
|
+
|
|
8
|
+
const turn = () => new Promise(resolve => setTimeout(resolve, 0))
|
|
9
|
+
const native = () => (window as any).navigation
|
|
10
|
+
const filters = (month: number) => [{ name: 'month', operator: 'eq', value: month }]
|
|
11
|
+
const address = (month: number) => `?${encodeListQuery({ filters: filters(month) })}`
|
|
12
|
+
async function until(check: () => boolean) {
|
|
13
|
+
for (let i = 0; i < 200; i++) {
|
|
14
|
+
if (check()) return
|
|
15
|
+
await new Promise(resolve => setTimeout(resolve, 5))
|
|
16
|
+
}
|
|
17
|
+
throw new Error('intent sequence did not settle')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Product oracle: only the latest accepted intent changes the query, records, edits or history. */
|
|
21
|
+
class Intended {
|
|
22
|
+
entries: number[] = [10]
|
|
23
|
+
cursor = 0
|
|
24
|
+
edited = false
|
|
25
|
+
reads = [10]
|
|
26
|
+
get month() {
|
|
27
|
+
return this.entries[this.cursor]
|
|
28
|
+
}
|
|
29
|
+
accept(month: number) {
|
|
30
|
+
if (month === this.month) return
|
|
31
|
+
this.entries.splice(++this.cursor)
|
|
32
|
+
this.entries.push(month)
|
|
33
|
+
this.edited = false
|
|
34
|
+
this.reads.push(month)
|
|
35
|
+
}
|
|
36
|
+
back() {
|
|
37
|
+
this.cursor--
|
|
38
|
+
this.edited = false
|
|
39
|
+
this.reads.push(this.month)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe('overlapping user intents against query and displayed state', () => {
|
|
44
|
+
let previousOnError: typeof window.onerror
|
|
45
|
+
const resizeNotice = (event: ErrorEvent) => {
|
|
46
|
+
if (event.message.includes('ResizeObserver loop')) {
|
|
47
|
+
event.preventDefault()
|
|
48
|
+
event.stopImmediatePropagation()
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
before(() => {
|
|
52
|
+
window.addEventListener('error', resizeNotice, true)
|
|
53
|
+
previousOnError = window.onerror
|
|
54
|
+
window.onerror = (message, ...rest) =>
|
|
55
|
+
String(message).includes('ResizeObserver loop') ? true : previousOnError?.call(window, message, ...rest)
|
|
56
|
+
})
|
|
57
|
+
after(() => {
|
|
58
|
+
window.removeEventListener('error', resizeNotice, true)
|
|
59
|
+
window.onerror = previousOnError
|
|
60
|
+
})
|
|
61
|
+
it('checks every edit, question, refusal, supersession, adoption and browser traversal', async () => {
|
|
62
|
+
const controller = addressController()
|
|
63
|
+
controller.registerQuery()
|
|
64
|
+
const coverage = new Set<number>()
|
|
65
|
+
for (let seed = 1; seed <= 12; seed++) {
|
|
66
|
+
await writeAddress(address(10))
|
|
67
|
+
const floorKey = controller.entry.key
|
|
68
|
+
const reads: number[] = []
|
|
69
|
+
let shown: number[] = []
|
|
70
|
+
const grist = await fixture<DataGrist>(
|
|
71
|
+
html`<ox-grist
|
|
72
|
+
style="display:block;width:800px;height:400px"
|
|
73
|
+
.urlParamsSensitive=${true}
|
|
74
|
+
.config=${{ columns: [{ name: 'month', header: 'month' }], pagination: { limit: 20 } }}
|
|
75
|
+
.fetchHandler=${async ({ filters: list }: any) => {
|
|
76
|
+
const month = Number(list.find((filter: any) => filter.name === 'month').value)
|
|
77
|
+
reads.push(month)
|
|
78
|
+
return { records: [{ id: String(month), month }], total: 1 }
|
|
79
|
+
}}
|
|
80
|
+
@list-adopted=${(event: CustomEvent) => {
|
|
81
|
+
shown = event.detail.records.map((row: any) => row.month)
|
|
82
|
+
}}
|
|
83
|
+
></ox-grist>`
|
|
84
|
+
)
|
|
85
|
+
await until(() => grist.data?.records?.[0]?.month === 10)
|
|
86
|
+
const expected = new Intended()
|
|
87
|
+
// Initial configuration may make the initial read once or more; subsequent intent reads must match exactly.
|
|
88
|
+
reads.splice(0, reads.length, 10)
|
|
89
|
+
let decision: ((answer: boolean) => void) | undefined
|
|
90
|
+
let gated = false
|
|
91
|
+
const stopGuard = controller.guard({
|
|
92
|
+
dirty: () => grist.dirtyRecords.length > 0,
|
|
93
|
+
approveSync: () => false,
|
|
94
|
+
approve: change => {
|
|
95
|
+
if (!grist.dirtyRecords.length) return true
|
|
96
|
+
return new Promise<boolean>(resolve => {
|
|
97
|
+
const endQuestion = gated ? controller.beginQuestion() : () => {}
|
|
98
|
+
const finish = (answer: boolean) => {
|
|
99
|
+
endQuestion()
|
|
100
|
+
resolve(answer)
|
|
101
|
+
}
|
|
102
|
+
decision = finish
|
|
103
|
+
change.signal.addEventListener('abort', () => finish(false), { once: true })
|
|
104
|
+
})
|
|
105
|
+
},
|
|
106
|
+
committed: () => grist.reset()
|
|
107
|
+
})
|
|
108
|
+
const verify = async (step: string) => {
|
|
109
|
+
await turn()
|
|
110
|
+
await grist.updateComplete
|
|
111
|
+
expect(grist.filters, step).to.deep.equal(filters(expected.month))
|
|
112
|
+
expect(
|
|
113
|
+
grist.data.records.map(row => row.month),
|
|
114
|
+
step
|
|
115
|
+
).to.deep.equal([expected.month])
|
|
116
|
+
expect(shown, step).to.deep.equal([expected.month])
|
|
117
|
+
expect(grist.dirtyRecords.length > 0, step).to.equal(expected.edited)
|
|
118
|
+
expect(reads, step).to.deep.equal(expected.reads)
|
|
119
|
+
const entries = native().entries()
|
|
120
|
+
const floor = entries.findIndex((entry: any) => entry.key === floorKey)
|
|
121
|
+
expect(floor, step).to.be.at.least(0)
|
|
122
|
+
expect(
|
|
123
|
+
entries
|
|
124
|
+
.slice(floor)
|
|
125
|
+
.map((entry: any) => JSON.parse(new URL(entry.url).searchParams.get('filters')!)[0].value),
|
|
126
|
+
step
|
|
127
|
+
).to.deep.equal(expected.entries)
|
|
128
|
+
expect(native().currentEntry.index - floor, step).to.equal(expected.cursor)
|
|
129
|
+
}
|
|
130
|
+
let random = seed
|
|
131
|
+
try {
|
|
132
|
+
for (let step = 0; step < 18; step++) {
|
|
133
|
+
random = (Math.imul(random, 1664525) + 1013904223) >>> 0
|
|
134
|
+
const action = random % 5
|
|
135
|
+
coverage.add(action)
|
|
136
|
+
const label = `seed ${seed}, step ${step}, action ${action}`
|
|
137
|
+
const next = 20 + seed * 100 + step
|
|
138
|
+
// Real grid edit, independent of the oracle's edit flag.
|
|
139
|
+
grist.dirtyData.records[0].__dirty__ = 'M'
|
|
140
|
+
grist.dirtyData.records[0].memo = label
|
|
141
|
+
grist.refresh()
|
|
142
|
+
expected.edited = true
|
|
143
|
+
await verify(label + ' edited')
|
|
144
|
+
decision = undefined
|
|
145
|
+
gated = action !== 2 && action !== 4
|
|
146
|
+
const first = writeAddress(address(next))
|
|
147
|
+
await turn()
|
|
148
|
+
await verify(label + ' before decision')
|
|
149
|
+
await until(() => !!decision)
|
|
150
|
+
const answerFirst = decision!
|
|
151
|
+
await verify(label + ' question pending')
|
|
152
|
+
if (action === 0) {
|
|
153
|
+
answerFirst(false)
|
|
154
|
+
expect(await first, label).to.equal(false)
|
|
155
|
+
} else if (action === 1) {
|
|
156
|
+
// Requests made under a real modal question are rejected without fetching or changing the view.
|
|
157
|
+
expect(await writeAddress(address(next + 10000)), label).to.equal(false)
|
|
158
|
+
await verify(label + ' outside request refused')
|
|
159
|
+
answerFirst(true)
|
|
160
|
+
expect(await first, label).to.equal(true)
|
|
161
|
+
expected.accept(next)
|
|
162
|
+
} else if (action === 2) {
|
|
163
|
+
// An asynchronous owner decision can be superseded before a dialog is installed.
|
|
164
|
+
decision = undefined
|
|
165
|
+
const second = writeAddress(address(next + 10000))
|
|
166
|
+
await until(() => !!decision)
|
|
167
|
+
decision!(true)
|
|
168
|
+
expect(await second, label).to.equal(true)
|
|
169
|
+
expected.accept(next + 10000)
|
|
170
|
+
answerFirst(true)
|
|
171
|
+
expect(await first, label).to.equal(false)
|
|
172
|
+
} else if (action === 3) {
|
|
173
|
+
answerFirst(true)
|
|
174
|
+
expect(await first, label).to.equal(true)
|
|
175
|
+
expected.accept(next)
|
|
176
|
+
} else {
|
|
177
|
+
if (expected.cursor > 0) {
|
|
178
|
+
// Browser navigation aborts the outstanding application approval; an old yes cannot revive it.
|
|
179
|
+
decision = undefined
|
|
180
|
+
const movement = native().back()
|
|
181
|
+
movement.finished.catch(() => {})
|
|
182
|
+
await until(() => !!decision)
|
|
183
|
+
decision!(true)
|
|
184
|
+
await movement.finished
|
|
185
|
+
expected.back()
|
|
186
|
+
answerFirst(true)
|
|
187
|
+
expect(await first, label).to.equal(false)
|
|
188
|
+
} else {
|
|
189
|
+
answerFirst(false)
|
|
190
|
+
expect(await first, label).to.equal(false)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
await until(() => grist.data.records[0]?.month === expected.month)
|
|
194
|
+
await verify(label + ' completed')
|
|
195
|
+
}
|
|
196
|
+
} finally {
|
|
197
|
+
stopGuard()
|
|
198
|
+
grist.remove()
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
expect([...coverage].sort()).to.deep.equal([0, 1, 2, 3, 4])
|
|
202
|
+
}).timeout(45000)
|
|
203
|
+
})
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { expect } from '@open-wc/testing'
|
|
2
|
+
import { externalFilters, ownedFilterIndex, patchFilterFields } from '../src/filters/filter-ownership.js'
|
|
3
|
+
import type { ColumnConfig, FilterValue } from '../src/types.js'
|
|
4
|
+
|
|
5
|
+
describe('filter field ownership', () => {
|
|
6
|
+
const year = { name: 'year', filter: { operator: 'eq' } } as ColumnConfig
|
|
7
|
+
const month = { name: 'month', filter: { operator: 'eq' } } as ColumnConfig
|
|
8
|
+
const predicate = (name: string, operator: string, value: any) => ({ name, operator, value }) as FilterValue
|
|
9
|
+
|
|
10
|
+
it('changing a month preserves same-name bounds and an external amount', () => {
|
|
11
|
+
const base = [
|
|
12
|
+
predicate('year', 'eq', 2026),
|
|
13
|
+
predicate('year', 'gte', 2025),
|
|
14
|
+
predicate('year', 'lte', 2026),
|
|
15
|
+
predicate('month', 'eq', 10),
|
|
16
|
+
predicate('amount', 'gte', 100000)
|
|
17
|
+
]
|
|
18
|
+
const result = patchFilterFields(
|
|
19
|
+
base,
|
|
20
|
+
[predicate('year', 'eq', 2026), predicate('month', 'eq', 11)],
|
|
21
|
+
[year, month],
|
|
22
|
+
['month']
|
|
23
|
+
)
|
|
24
|
+
expect(result).to.deep.equal([base[0], base[1], base[2], predicate('month', 'eq', 11), base[4]])
|
|
25
|
+
expect(externalFilters(result, [year, month]).map(one => one.filter)).to.deep.equal([base[1], base[2], base[4]])
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('a field changed to the value it holds leaves the filters as they were, order included', () => {
|
|
29
|
+
const base = [predicate('year', 'eq', '2026'), predicate('month', 'eq', '10')]
|
|
30
|
+
const fields = [predicate('year', 'eq', '2026'), predicate('month', 'eq', '10')]
|
|
31
|
+
expect(patchFilterFields(base, fields, [year, month], ['year'])).to.deep.equal(base)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('a field that held nothing adds its predicate after the others', () => {
|
|
35
|
+
const base = [predicate('amount', 'gte', 100000)]
|
|
36
|
+
expect(patchFilterFields(base, [predicate('month', 'eq', '9')], [year, month], ['month'])).to.deep.equal([
|
|
37
|
+
base[0],
|
|
38
|
+
predicate('month', 'eq', '9')
|
|
39
|
+
])
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('ambiguous equalities both stay as chips and leave the field empty', () => {
|
|
43
|
+
const base = [predicate('year', 'eq', 2025), predicate('year', 'eq', 2026)]
|
|
44
|
+
expect(ownedFilterIndex(base, year)).to.equal(-1)
|
|
45
|
+
expect(externalFilters(base, [year]).length).to.equal(2)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('a scalar field does not claim an array predicate', () => {
|
|
49
|
+
expect(ownedFilterIndex([predicate('year', 'eq', [2025, 2026])], year)).to.equal(-1)
|
|
50
|
+
})
|
|
51
|
+
})
|
|
@@ -29,6 +29,22 @@ registerEditor('probe-popup', ProbePopupEditor)
|
|
|
29
29
|
const settle = (ms = 100) => new Promise(resolve => setTimeout(resolve, ms))
|
|
30
30
|
|
|
31
31
|
describe('a popup field in a form', () => {
|
|
32
|
+
it('does not emit the old inline value after a popup has confirmed a different value', async () => {
|
|
33
|
+
const record = { body: 'old' }
|
|
34
|
+
const editor = await fixture<ProbePopupEditor>(
|
|
35
|
+
html`<probe-popup-editor
|
|
36
|
+
.column=${buildColumn({ type: 'probe-popup', name: 'body', record: { editable: true } } as any)}
|
|
37
|
+
.record=${record}
|
|
38
|
+
></probe-popup-editor>`
|
|
39
|
+
)
|
|
40
|
+
let changes = 0
|
|
41
|
+
editor.addEventListener('field-change', () => changes++)
|
|
42
|
+
record.body = 'confirmed'
|
|
43
|
+
editor._onfocusout()
|
|
44
|
+
expect(changes).to.equal(0)
|
|
45
|
+
expect(record.body).to.equal('confirmed')
|
|
46
|
+
})
|
|
47
|
+
|
|
32
48
|
it('opens its popup on the first press', async () => {
|
|
33
49
|
opened = 0
|
|
34
50
|
const columns = [
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { expect } from '@open-wc/testing'
|
|
2
|
+
import { DataProvider } from '../src/data-provider.js'
|
|
3
|
+
import type { DataConsumer } from '../src/data-consumer.js'
|
|
4
|
+
import type { FetchOption, FetchResult } from '../src/types.js'
|
|
5
|
+
|
|
6
|
+
function pending() {
|
|
7
|
+
let resolve!: (result: FetchResult) => void
|
|
8
|
+
let reject!: (error: Error) => void
|
|
9
|
+
const promise = new Promise<FetchResult>((yes, no) => {
|
|
10
|
+
resolve = yes
|
|
11
|
+
reject = no
|
|
12
|
+
})
|
|
13
|
+
return { promise, resolve, reject }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function setup() {
|
|
17
|
+
const calls: { options: FetchOption; result: ReturnType<typeof pending> }[] = []
|
|
18
|
+
const events: any[] = []
|
|
19
|
+
let data: any = { records: [] }
|
|
20
|
+
let spinning = false
|
|
21
|
+
const consumer = Object.assign(new EventTarget(), {
|
|
22
|
+
mode: 'GRID' as const,
|
|
23
|
+
get data() {
|
|
24
|
+
return data
|
|
25
|
+
},
|
|
26
|
+
set data(next) {
|
|
27
|
+
data = next
|
|
28
|
+
},
|
|
29
|
+
_data: data,
|
|
30
|
+
checkDirties() {},
|
|
31
|
+
showSpinner() {
|
|
32
|
+
spinning = true
|
|
33
|
+
},
|
|
34
|
+
hideSpinner() {
|
|
35
|
+
spinning = false
|
|
36
|
+
},
|
|
37
|
+
fetchHandler(options: FetchOption) {
|
|
38
|
+
const result = pending()
|
|
39
|
+
calls.push({ options, result })
|
|
40
|
+
return result.promise
|
|
41
|
+
}
|
|
42
|
+
}) as DataConsumer
|
|
43
|
+
// The grid's dirty copy follows adoption; an append must preserve its edited values.
|
|
44
|
+
consumer.addEventListener('list-adopted', event => {
|
|
45
|
+
const detail = (event as CustomEvent).detail
|
|
46
|
+
events.push(detail)
|
|
47
|
+
consumer._data = { ...detail }
|
|
48
|
+
})
|
|
49
|
+
return { provider: new DataProvider(consumer), consumer, calls, events, spinning: () => spinning }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const answer = (...ids: string[]): FetchResult => ({ total: 100, records: ids.map(id => ({ id })) })
|
|
53
|
+
|
|
54
|
+
describe('query generations', () => {
|
|
55
|
+
it('never appends an old query page to a replacement', async () => {
|
|
56
|
+
const { provider, calls, events } = setup()
|
|
57
|
+
const initial = provider.fetch()
|
|
58
|
+
calls[0].result.resolve(answer('old-1'))
|
|
59
|
+
await initial
|
|
60
|
+
const oldPage = provider.attach()
|
|
61
|
+
const replacement = provider.fetch()
|
|
62
|
+
calls[2].result.resolve(answer('new-1'))
|
|
63
|
+
await replacement
|
|
64
|
+
calls[1].result.resolve(answer('old-2'))
|
|
65
|
+
await oldPage
|
|
66
|
+
expect(provider.records.map(row => row.id)).to.deep.equal(['new-1'])
|
|
67
|
+
expect(events.map(event => event.kind)).to.deep.equal(['replace', 'replace'])
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('coalesces next-page triggers, preserves edits and deduplicates ids', async () => {
|
|
71
|
+
const { provider, consumer, calls, events } = setup()
|
|
72
|
+
const initial = provider.attach(true)
|
|
73
|
+
calls[0].result.resolve(answer('one'))
|
|
74
|
+
await initial
|
|
75
|
+
consumer._data.records[0].edited = true
|
|
76
|
+
const a = provider.attach()
|
|
77
|
+
const b = provider.attach()
|
|
78
|
+
expect(a).to.equal(b)
|
|
79
|
+
expect(calls.length).to.equal(2)
|
|
80
|
+
calls[1].result.resolve(answer('one', 'two', 'two'))
|
|
81
|
+
await a
|
|
82
|
+
expect(provider.records).to.deep.equal([{ id: 'one', edited: true }, { id: 'two' }])
|
|
83
|
+
expect(events[1].page).to.equal(2)
|
|
84
|
+
expect(events[1].records.length).to.equal(2)
|
|
85
|
+
expect(events[1].pageRecords.length).to.equal(3)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('keeps rows and retries the same page after a failed append', async () => {
|
|
89
|
+
const { provider, calls } = setup()
|
|
90
|
+
const initial = provider.fetch()
|
|
91
|
+
calls[0].result.resolve(answer('one'))
|
|
92
|
+
await initial
|
|
93
|
+
const append = provider.attach()
|
|
94
|
+
calls[1].result.reject(new Error('offline'))
|
|
95
|
+
try {
|
|
96
|
+
await append
|
|
97
|
+
} catch {}
|
|
98
|
+
expect(provider.records.map(row => row.id)).to.deep.equal(['one'])
|
|
99
|
+
const retry = provider.attach()
|
|
100
|
+
expect(calls[2].options.page).to.equal(2)
|
|
101
|
+
calls[2].result.resolve(answer('two'))
|
|
102
|
+
await retry
|
|
103
|
+
expect(provider.records.map(row => row.id)).to.deep.equal(['one', 'two'])
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('a stale response cannot stop the current spinner or announce adoption', async () => {
|
|
107
|
+
const { provider, calls, events, spinning } = setup()
|
|
108
|
+
const old = provider.fetch()
|
|
109
|
+
const next = provider.fetch()
|
|
110
|
+
calls[0].result.resolve(answer('old'))
|
|
111
|
+
await old
|
|
112
|
+
expect(spinning()).to.equal(true)
|
|
113
|
+
expect(events.length).to.equal(0)
|
|
114
|
+
calls[1].result.resolve(answer('new'))
|
|
115
|
+
await next
|
|
116
|
+
expect(spinning()).to.equal(false)
|
|
117
|
+
expect(events.length).to.equal(1)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
it('disposal invalidates replacement and append responses', async () => {
|
|
121
|
+
const { provider, calls, events } = setup()
|
|
122
|
+
const request = provider.fetch()
|
|
123
|
+
provider.dispose()
|
|
124
|
+
calls[0].result.resolve(answer('late'))
|
|
125
|
+
await request
|
|
126
|
+
expect(events.length).to.equal(0)
|
|
127
|
+
})
|
|
128
|
+
})
|