@operato/data-grist 10.29.77 → 10.29.79
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 +26 -0
- package/dist/src/data-card/record-card.d.ts +4 -0
- package/dist/src/data-card/record-card.js +62 -20
- package/dist/src/data-card/record-card.js.map +1 -1
- package/dist/src/editors/ox-grist-editor-date.d.ts +2 -0
- package/dist/src/editors/ox-grist-editor-date.js +3 -8
- package/dist/src/editors/ox-grist-editor-date.js.map +1 -1
- package/dist/src/editors/ox-grist-editor-month.d.ts +2 -0
- package/dist/src/editors/ox-grist-editor-month.js +3 -1
- package/dist/src/editors/ox-grist-editor-month.js.map +1 -1
- package/dist/src/editors/ox-grist-editor-week.d.ts +2 -0
- package/dist/src/editors/ox-grist-editor-week.js +3 -1
- package/dist/src/editors/ox-grist-editor-week.js.map +1 -1
- package/dist/src/editors/ox-grist-editor.js +2 -1
- package/dist/src/editors/ox-grist-editor.js.map +1 -1
- package/dist/src/filters/filter-input.d.ts +1 -0
- package/dist/src/filters/filter-input.js +20 -0
- package/dist/src/filters/filter-input.js.map +1 -1
- package/dist/src/filters/filter-range-date.d.ts +7 -0
- package/dist/src/filters/filter-range-date.js +53 -0
- package/dist/src/filters/filter-range-date.js.map +1 -1
- package/dist/src/filters/filter-select-buttons.js +7 -0
- package/dist/src/filters/filter-select-buttons.js.map +1 -1
- package/dist/src/filters/filter-styles.js +8 -2
- package/dist/src/filters/filter-styles.js.map +1 -1
- package/dist/src/filters/filters-form.js +38 -14
- package/dist/src/filters/filters-form.js.map +1 -1
- package/dist/src/filters/pill-choice.d.ts +24 -0
- package/dist/src/filters/pill-choice.js +63 -0
- package/dist/src/filters/pill-choice.js.map +1 -0
- package/dist/test/accessible-name.test.js +324 -0
- package/dist/test/accessible-name.test.js.map +1 -0
- package/dist/test/accumulator-labels.test.d.ts +1 -0
- package/dist/test/accumulator-labels.test.js +32 -0
- package/dist/test/accumulator-labels.test.js.map +1 -0
- package/dist/test/address-intents.test.js +201 -0
- package/dist/test/address-intents.test.js.map +1 -0
- package/dist/test/card-selector.test.js +71 -0
- package/dist/test/card-selector.test.js.map +1 -0
- package/dist/test/card-thumb.test.d.ts +1 -0
- package/dist/test/card-thumb.test.js +44 -0
- package/dist/test/card-thumb.test.js.map +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/cell-button-row-height.test.js +53 -0
- package/dist/test/cell-button-row-height.test.js.map +1 -0
- package/dist/test/column-resize.test.js +153 -0
- package/dist/test/column-resize.test.js.map +1 -0
- package/dist/test/control-heights.test.js +25 -0
- package/dist/test/control-heights.test.js.map +1 -0
- package/dist/test/count-handler.test.js +56 -0
- package/dist/test/count-handler.test.js.map +1 -0
- package/dist/test/create-paste-policy.test.js +159 -0
- package/dist/test/create-paste-policy.test.js.map +1 -0
- package/dist/test/data-integrity.test.js +145 -0
- package/dist/test/data-integrity.test.js.map +1 -0
- package/dist/test/date-fields.test.d.ts +2 -0
- package/dist/test/date-fields.test.js +138 -0
- package/dist/test/date-fields.test.js.map +1 -0
- package/dist/test/destructive-actions.test.js +147 -0
- package/dist/test/destructive-actions.test.js.map +1 -0
- package/dist/test/edit-lifecycle.test.js +270 -0
- package/dist/test/edit-lifecycle.test.js.map +1 -0
- package/dist/test/edit-rebase.test.js +185 -0
- package/dist/test/edit-rebase.test.js.map +1 -0
- package/dist/test/editor-commit.test.js +68 -0
- package/dist/test/editor-commit.test.js.map +1 -0
- package/dist/test/fetch-failure-state.test.js +129 -0
- package/dist/test/fetch-failure-state.test.js.map +1 -0
- package/dist/test/field-contains-content.test.js +101 -0
- package/dist/test/field-contains-content.test.js.map +1 -0
- package/dist/test/field-hint.test.js +54 -0
- package/dist/test/field-hint.test.js.map +1 -0
- package/dist/test/filter-labels.test.js +140 -0
- package/dist/test/filter-labels.test.js.map +1 -0
- package/dist/test/filter-ownership.test.js +83 -0
- package/dist/test/filter-ownership.test.js.map +1 -0
- package/dist/test/filter-select-buttons-count.test.js +36 -0
- package/dist/test/filter-select-buttons-count.test.js.map +1 -0
- package/dist/test/filter-typing.test.js +66 -0
- package/dist/test/filter-typing.test.js.map +1 -0
- package/dist/test/filters-phone-width.test.d.ts +1 -0
- package/dist/test/filters-phone-width.test.js +33 -0
- package/dist/test/filters-phone-width.test.js.map +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/filters-pills.test.d.ts +2 -0
- package/dist/test/filters-pills.test.js +149 -0
- package/dist/test/filters-pills.test.js.map +1 -0
- package/dist/test/first-click-stays.test.js +77 -0
- package/dist/test/first-click-stays.test.js.map +1 -0
- package/dist/test/fixed-column-opaque.test.js +134 -0
- package/dist/test/fixed-column-opaque.test.js.map +1 -0
- package/dist/test/flexible-columns.test.js +134 -0
- package/dist/test/flexible-columns.test.js.map +1 -0
- package/dist/test/grid-single-scroller.test.js +107 -0
- package/dist/test/grid-single-scroller.test.js.map +1 -0
- package/dist/test/group-heading.test.js +208 -0
- package/dist/test/group-heading.test.js.map +1 -0
- package/dist/test/latest-fetch-wins.test.js +91 -0
- package/dist/test/latest-fetch-wins.test.js.map +1 -0
- package/dist/test/list-defaults.test.js +146 -0
- package/dist/test/list-defaults.test.js.map +1 -0
- package/dist/test/list-records.test.js +46 -0
- package/dist/test/list-records.test.js.map +1 -0
- package/dist/test/office-density.test.js +52 -0
- package/dist/test/office-density.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.js +163 -0
- package/dist/test/paste-integrity.test.js.map +1 -0
- package/dist/test/record-card-height.test.js +15 -0
- package/dist/test/record-card-height.test.js.map +1 -0
- package/dist/test/record-view-popup-editor.test.js +71 -0
- package/dist/test/record-view-popup-editor.test.js.map +1 -0
- package/dist/test/renderer-date-calendar-day.test.js +48 -0
- package/dist/test/renderer-date-calendar-day.test.js.map +1 -0
- package/dist/test/request-generation.test.js +153 -0
- package/dist/test/request-generation.test.js.map +1 -0
- package/dist/test/resubmit.test.js +83 -0
- package/dist/test/resubmit.test.js.map +1 -0
- package/dist/test/row-hover-visible.test.js +139 -0
- package/dist/test/row-hover-visible.test.js.map +1 -0
- package/dist/test/search-term.test.js +108 -0
- package/dist/test/search-term.test.js.map +1 -0
- package/dist/test/searchable-select.test.js +65 -0
- package/dist/test/searchable-select.test.js.map +1 -0
- package/dist/test/select-empty-value.test.js +61 -0
- package/dist/test/select-empty-value.test.js.map +1 -0
- package/dist/test/shift-range-select.test.js +100 -0
- package/dist/test/shift-range-select.test.js.map +1 -0
- package/dist/test/sparkline-renderer.test.js +36 -0
- package/dist/test/sparkline-renderer.test.js.map +1 -0
- package/dist/test/wheel-one-scroller.test.js +275 -0
- package/dist/test/wheel-one-scroller.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/test/card-selector.test.ts +18 -4
- package/test/date-fields.test.ts +163 -0
- package/test/filter-select-buttons-count.test.ts +2 -1
- package/test/filters-phone-width.test.ts +35 -0
- package/test/filters-pills.test.ts +162 -0
- package/test/list-defaults.test.ts +2 -1
- package/translations/en.json +8 -1
- package/translations/es.json +8 -1
- package/translations/ja.json +8 -1
- package/translations/ko.json +8 -1
- package/translations/ms.json +8 -1
- package/translations/zh.json +8 -1
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
import '../src/editors/ox-grist-editor-select.js';
|
|
5
|
+
import { buildColumn } from '../src/configure/column-builder.js';
|
|
6
|
+
/*
|
|
7
|
+
* A select column with `record.searchable` edits through the popup list with a search box on top, as select2 does
|
|
8
|
+
* (2026-10-25, the user: 「셀렉트는 전부 select2 처럼 상단에 검색이 가능한 select였으면」). Without it the cell keeps the
|
|
9
|
+
* browser's own <select>, so grids that did not ask do not change.
|
|
10
|
+
*/
|
|
11
|
+
const GRADES = [
|
|
12
|
+
{ display: 'one', value: 1 },
|
|
13
|
+
{ display: 'two', value: 2 }
|
|
14
|
+
];
|
|
15
|
+
const mount = async (record, searchable = true) => {
|
|
16
|
+
const editor = (await fixture(html `${Object.assign(document.createElement('ox-grist-editor-select'), {
|
|
17
|
+
column: buildColumn({ type: 'select', name: 'grade', record: { editable: true, searchable, options: GRADES } }),
|
|
18
|
+
record,
|
|
19
|
+
row: 0
|
|
20
|
+
})}`));
|
|
21
|
+
await editor.updateComplete;
|
|
22
|
+
const changes = [];
|
|
23
|
+
editor.addEventListener('field-change', event => changes.push(event.detail));
|
|
24
|
+
return { editor, changes };
|
|
25
|
+
};
|
|
26
|
+
/* What the list does when it closes: its value is the picked option's value attribute, and ox-select tells a change. */
|
|
27
|
+
const close = (editor, value) => {
|
|
28
|
+
const select = editor.renderRoot.querySelector('ox-select');
|
|
29
|
+
select.value = value;
|
|
30
|
+
select.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: value }));
|
|
31
|
+
};
|
|
32
|
+
describe('a searchable select cell', () => {
|
|
33
|
+
it('draws the popup list with a search box, not a native select', async () => {
|
|
34
|
+
const { editor } = await mount({ grade: 1 });
|
|
35
|
+
expect(editor.renderRoot.querySelector('select') === null).to.equal(true);
|
|
36
|
+
const list = editor.renderRoot.querySelector('ox-select ox-popup-list');
|
|
37
|
+
expect(!!list && list.hasAttribute('with-search')).to.equal(true);
|
|
38
|
+
expect(list.querySelectorAll('[option]').length).to.equal(2);
|
|
39
|
+
});
|
|
40
|
+
it('keeps the native select when the column does not ask', async () => {
|
|
41
|
+
const { editor } = await mount({ grade: 1 }, false);
|
|
42
|
+
expect(editor.renderRoot.querySelector('select') !== null).to.equal(true);
|
|
43
|
+
expect(editor.renderRoot.querySelector('ox-select') === null).to.equal(true);
|
|
44
|
+
});
|
|
45
|
+
it('commits a pick at once, as the option value and not its text', async () => {
|
|
46
|
+
const { editor, changes } = await mount({ grade: 1 });
|
|
47
|
+
close(editor, '2');
|
|
48
|
+
expect(changes.length).to.equal(1);
|
|
49
|
+
expect(changes[0].after).to.equal(2);
|
|
50
|
+
});
|
|
51
|
+
/* Picking the shown value is still told, as no change: it supersedes an edit of the cell still being validated. */
|
|
52
|
+
it('a list closed on the value it had commits no change', async () => {
|
|
53
|
+
const { editor, changes } = await mount({ grade: 1 });
|
|
54
|
+
close(editor, '1');
|
|
55
|
+
editor.flush();
|
|
56
|
+
editor._onfocusout();
|
|
57
|
+
expect(changes.every(change => change.after === change.before)).to.equal(true);
|
|
58
|
+
});
|
|
59
|
+
it('an untouched cell commits nothing on flush', async () => {
|
|
60
|
+
const { editor, changes } = await mount({ grade: 1 });
|
|
61
|
+
editor.flush();
|
|
62
|
+
expect(changes.length).to.equal(0);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=searchable-select.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searchable-select.test.js","sourceRoot":"","sources":["../../test/searchable-select.test.ts"],"names":[],"mappings":"AAAA,kIAAkI;AAClI,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAE1B,OAAO,0CAA0C,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAA;AAGhE;;;;GAIG;AAEH,MAAM,MAAM,GAAG;IACb,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE;IAC5B,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE;CAC7B,CAAA;AAED,MAAM,KAAK,GAAG,KAAK,EAAE,MAAW,EAAE,UAAU,GAAG,IAAI,EAAE,EAAE;IACrD,MAAM,MAAM,GAAG,CA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CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACtC,CAAC,CAAC,CAAA;IAEF,mHAAmH;IACnH,EAAE,CAAC,qDAAqD,EAAE,KAAK,IAAI,EAAE;QACnE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAA;QACrD,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;QAClB,MAAM,CAAC,KAAK,EAAE,CAAA;QACd,MAAM,CAAC,WAAW,EAAE,CAAA;QACpB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAChF,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;QAC1D,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAA;QACrD,MAAM,CAAC,KAAK,EAAE,CAAA;QACd,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["/* Elements are compared by presence, not by value: a failing element comparison makes chai render the DOM and hang the runner. */\nimport { expect, fixture } from '@open-wc/testing'\nimport { html } from 'lit'\n\nimport '../src/editors/ox-grist-editor-select.js'\nimport { buildColumn } from '../src/configure/column-builder.js'\nimport { OxGristEditor } from '../src/editors/ox-grist-editor.js'\n\n/*\n * A select column with `record.searchable` edits through the popup list with a search box on top, as select2 does\n * (2026-10-25, the user: 「셀렉트는 전부 select2 처럼 상단에 검색이 가능한 select였으면」). Without it the cell keeps the\n * browser's own <select>, so grids that did not ask do not change.\n */\n\nconst GRADES = [\n { display: 'one', value: 1 },\n { display: 'two', value: 2 }\n]\n\nconst mount = async (record: any, searchable = true) => {\n const editor = (await fixture(\n html`${Object.assign(document.createElement('ox-grist-editor-select'), {\n column: buildColumn({ type: 'select', name: 'grade', record: { editable: true, searchable, options: GRADES } }),\n record,\n row: 0\n })}`\n )) as OxGristEditor\n await editor.updateComplete\n const changes: any[] = []\n editor.addEventListener('field-change', event => changes.push((event as CustomEvent).detail))\n return { editor, changes }\n}\n\n/* What the list does when it closes: its value is the picked option's value attribute, and ox-select tells a change. */\nconst close = (editor: OxGristEditor, value: string) => {\n const select = editor.renderRoot.querySelector('ox-select') as any\n select.value = value\n select.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: value }))\n}\n\ndescribe('a searchable select cell', () => {\n it('draws the popup list with a search box, not a native select', async () => {\n const { editor } = await mount({ grade: 1 })\n expect(editor.renderRoot.querySelector('select') === null).to.equal(true)\n const list = editor.renderRoot.querySelector('ox-select ox-popup-list')\n expect(!!list && list.hasAttribute('with-search')).to.equal(true)\n expect(list!.querySelectorAll('[option]').length).to.equal(2)\n })\n\n it('keeps the native select when the column does not ask', async () => {\n const { editor } = await mount({ grade: 1 }, false)\n expect(editor.renderRoot.querySelector('select') !== null).to.equal(true)\n expect(editor.renderRoot.querySelector('ox-select') === null).to.equal(true)\n })\n\n it('commits a pick at once, as the option value and not its text', async () => {\n const { editor, changes } = await mount({ grade: 1 })\n close(editor, '2')\n expect(changes.length).to.equal(1)\n expect(changes[0].after).to.equal(2)\n })\n\n /* Picking the shown value is still told, as no change: it supersedes an edit of the cell still being validated. */\n it('a list closed on the value it had commits no change', async () => {\n const { editor, changes } = await mount({ grade: 1 })\n close(editor, '1')\n editor.flush()\n editor._onfocusout()\n expect(changes.every(change => change.after === change.before)).to.equal(true)\n })\n\n it('an untouched cell commits nothing on flush', async () => {\n const { editor, changes } = await mount({ grade: 1 })\n editor.flush()\n expect(changes.length).to.equal(0)\n })\n})\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
import '../src/editors/ox-grist-editor-select.js';
|
|
5
|
+
import { buildColumn } from '../src/configure/column-builder.js';
|
|
6
|
+
/*
|
|
7
|
+
* An empty cell of a select column (the new row at the bottom of an appendable grid) must take its first option. The
|
|
8
|
+
* browser tells a change only when the picked option differs from the shown one, so the editor must not open showing
|
|
9
|
+
* the first option as picked (2026-11-08, 물품 대장 「종류」: 「처음에 "노트북.PC"를 선택해도 변화 이벤트가 발생하지 않아서」).
|
|
10
|
+
*/
|
|
11
|
+
const KINDS = [
|
|
12
|
+
{ display: '노트북.PC', value: 'COMPUTER' },
|
|
13
|
+
{ display: '모니터', value: 'MONITOR' }
|
|
14
|
+
];
|
|
15
|
+
const mount = async (record, mandatory = true) => {
|
|
16
|
+
const editor = (await fixture(html `${Object.assign(document.createElement('ox-grist-editor-select'), {
|
|
17
|
+
column: buildColumn({ type: 'select', name: 'kind', record: { editable: true, mandatory, options: KINDS } }),
|
|
18
|
+
record,
|
|
19
|
+
row: 0
|
|
20
|
+
})}`));
|
|
21
|
+
await editor.updateComplete;
|
|
22
|
+
const changes = [];
|
|
23
|
+
editor.addEventListener('field-change', event => changes.push(event.detail));
|
|
24
|
+
return { editor, changes, select: editor.renderRoot.querySelector('select') };
|
|
25
|
+
};
|
|
26
|
+
/* What the browser does on a pick: it tells input and change only when the picked option is not the shown one. */
|
|
27
|
+
const pick = (select, value) => {
|
|
28
|
+
if (select.value === value)
|
|
29
|
+
return;
|
|
30
|
+
select.value = value;
|
|
31
|
+
select.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
|
|
32
|
+
select.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
|
33
|
+
};
|
|
34
|
+
describe('a select cell with no value', () => {
|
|
35
|
+
for (const record of [{}, { kind: null }, { kind: '' }]) {
|
|
36
|
+
it(`takes the first option when it is picked (${JSON.stringify(record)})`, async () => {
|
|
37
|
+
const { editor, changes, select } = await mount(record);
|
|
38
|
+
pick(select, 'COMPUTER');
|
|
39
|
+
editor.flush();
|
|
40
|
+
expect(changes.length).to.equal(1);
|
|
41
|
+
expect(changes[0].after).to.equal('COMPUTER');
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
it('lists only the real options to pick from', async () => {
|
|
45
|
+
const { select } = await mount({});
|
|
46
|
+
const pickable = Array.from(select.options).filter(option => !option.hidden);
|
|
47
|
+
expect(pickable.map(option => option.value)).to.deep.equal(['COMPUTER', 'MONITOR']);
|
|
48
|
+
});
|
|
49
|
+
it('an untouched empty cell commits nothing', async () => {
|
|
50
|
+
const { editor, changes } = await mount({});
|
|
51
|
+
editor.flush();
|
|
52
|
+
editor._onfocusout();
|
|
53
|
+
expect(changes.length).to.equal(0);
|
|
54
|
+
});
|
|
55
|
+
it('a cell with a value opens on that value, with no blank option', async () => {
|
|
56
|
+
const { select } = await mount({ kind: 'MONITOR' });
|
|
57
|
+
expect(select.value).to.equal('MONITOR');
|
|
58
|
+
expect(select.options.length).to.equal(2);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=select-empty-value.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select-empty-value.test.js","sourceRoot":"","sources":["../../test/select-empty-value.test.ts"],"names":[],"mappings":"AAAA,kIAAkI;AAClI,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAE1B,OAAO,0CAA0C,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAA;AAGhE;;;;GAIG;AAEH,MAAM,KAAK,GAAG;IACZ,EAAE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,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,CAAA;IACrF,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;QACvD,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,KAAK,CAAC,EAAE,CAAC,CAAA;QAC3C,MAAM,CAAC,KAAK,EAAE,CAAA;QACd,MAAM,CAAC,WAAW,EAAE,CAAA;QACpB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,+DAA+D,EAAE,KAAK,IAAI,EAAE;QAC7E,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;QACnD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;QACxC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAC3C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["/* Elements are compared by presence, not by value: a failing element comparison makes chai render the DOM and hang the runner. */\nimport { expect, fixture } from '@open-wc/testing'\nimport { html } from 'lit'\n\nimport '../src/editors/ox-grist-editor-select.js'\nimport { buildColumn } from '../src/configure/column-builder.js'\nimport { OxGristEditor } from '../src/editors/ox-grist-editor.js'\n\n/*\n * An empty cell of a select column (the new row at the bottom of an appendable grid) must take its first option. The\n * browser tells a change only when the picked option differs from the shown one, so the editor must not open showing\n * the first option as picked (2026-11-08, 물품 대장 「종류」: 「처음에 \"노트북.PC\"를 선택해도 변화 이벤트가 발생하지 않아서」).\n */\n\nconst KINDS = [\n { display: '노트북.PC', value: 'COMPUTER' },\n { display: '모니터', value: 'MONITOR' }\n]\n\nconst mount = async (record: any, mandatory = true) => {\n const editor = (await fixture(\n html`${Object.assign(document.createElement('ox-grist-editor-select'), {\n column: buildColumn({ type: 'select', name: 'kind', record: { editable: true, mandatory, options: KINDS } }),\n record,\n row: 0\n })}`\n )) as OxGristEditor\n await editor.updateComplete\n const changes: any[] = []\n editor.addEventListener('field-change', event => changes.push((event as CustomEvent).detail))\n return { editor, changes, select: editor.renderRoot.querySelector('select') as HTMLSelectElement }\n}\n\n/* What the browser does on a pick: it tells input and change only when the picked option is not the shown one. */\nconst pick = (select: HTMLSelectElement, value: string) => {\n if (select.value === value) return\n select.value = value\n select.dispatchEvent(new Event('input', { bubbles: true, composed: true }))\n select.dispatchEvent(new Event('change', { bubbles: true, composed: true }))\n}\n\ndescribe('a select cell with no value', () => {\n for (const record of [{}, { kind: null }, { kind: '' }]) {\n it(`takes the first option when it is picked (${JSON.stringify(record)})`, async () => {\n const { editor, changes, select } = await mount(record)\n pick(select, 'COMPUTER')\n editor.flush()\n expect(changes.length).to.equal(1)\n expect(changes[0].after).to.equal('COMPUTER')\n })\n }\n\n it('lists only the real options to pick from', async () => {\n const { select } = await mount({})\n const pickable = Array.from(select.options).filter(option => !option.hidden)\n expect(pickable.map(option => option.value)).to.deep.equal(['COMPUTER', 'MONITOR'])\n })\n\n it('an untouched empty cell commits nothing', async () => {\n const { editor, changes } = await mount({})\n editor.flush()\n editor._onfocusout()\n expect(changes.length).to.equal(0)\n })\n\n it('a cell with a value opens on that value, with no blank option', async () => {\n const { select } = await mount({ kind: 'MONITOR' })\n expect(select.value).to.equal('MONITOR')\n expect(select.options.length).to.equal(2)\n })\n})\n"]}
|
|
@@ -0,0 +1,100 @@
|
|
|
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 { resetMouse, sendKeys, sendMouse } from '@web/test-runner-commands';
|
|
4
|
+
import { html } from 'lit';
|
|
5
|
+
import '../src/data-grist.js';
|
|
6
|
+
import { selectionChange } from '../src/utils/select-range.js';
|
|
7
|
+
const settle = (ms = 150) => new Promise(resolve => setTimeout(resolve, ms));
|
|
8
|
+
describe('selection by range', () => {
|
|
9
|
+
const rows = () => Array.from({ length: 6 }, (_, i) => ({ id: String(i) }));
|
|
10
|
+
it('a plain click names its rows and becomes the anchor', () => {
|
|
11
|
+
const records = rows();
|
|
12
|
+
expect(selectionChange(records, { added: [records[2]] })).to.deep.equal({ on: [records[2]], off: [], anchor: records[2] });
|
|
13
|
+
});
|
|
14
|
+
it('a shift-click gives every row from the anchor the clicked row’s new state, either way round', () => {
|
|
15
|
+
const records = rows();
|
|
16
|
+
expect(selectionChange(records, { added: [records[4]], range: true }, records[1]).on.map(one => one.id)).to.deep.equal(['1', '2', '3', '4']);
|
|
17
|
+
expect(selectionChange(records, { added: [records[0]], range: true }, records[3]).on.map(one => one.id)).to.deep.equal(['0', '1', '2', '3']);
|
|
18
|
+
expect(selectionChange(records, { removed: [records[5]], range: true }, records[2]).off.map(one => one.id)).to.deep.equal(['2', '3', '4', '5']);
|
|
19
|
+
});
|
|
20
|
+
it('without an anchor in the rows a shift-click is a plain click', () => {
|
|
21
|
+
const records = rows();
|
|
22
|
+
expect(selectionChange(records, { added: [records[3]], range: true }).on).to.deep.equal([records[3]]);
|
|
23
|
+
expect(selectionChange(records, { added: [records[3]], range: true }, { id: 'read before' }).on).to.deep.equal([records[3]]);
|
|
24
|
+
});
|
|
25
|
+
describe('on a grid', () => {
|
|
26
|
+
const ignoreResizeLoop = (e) => {
|
|
27
|
+
if (String(e.message).includes('ResizeObserver loop')) {
|
|
28
|
+
e.stopImmediatePropagation();
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
let previousOnError = null;
|
|
33
|
+
before(() => {
|
|
34
|
+
window.addEventListener('error', ignoreResizeLoop, true);
|
|
35
|
+
previousOnError = window.onerror;
|
|
36
|
+
window.onerror = (message, ...rest) => String(message).includes('ResizeObserver loop') ? true : previousOnError === null || previousOnError === void 0 ? void 0 : previousOnError.call(window, message, ...rest);
|
|
37
|
+
});
|
|
38
|
+
after(async function () {
|
|
39
|
+
this.timeout(10000);
|
|
40
|
+
await settle(300);
|
|
41
|
+
window.removeEventListener('error', ignoreResizeLoop, true);
|
|
42
|
+
window.onerror = previousOnError;
|
|
43
|
+
await resetMouse();
|
|
44
|
+
});
|
|
45
|
+
const grid = async (rowClick) => {
|
|
46
|
+
const records = Array.from({ length: 8 }, (_, i) => ({ id: String(i), name: 'row ' + i }));
|
|
47
|
+
const el = (await fixture(html `
|
|
48
|
+
<ox-grist
|
|
49
|
+
style="display: flex; width: 500px; height: 400px"
|
|
50
|
+
mode="GRID"
|
|
51
|
+
.config=${{
|
|
52
|
+
rows: { appendable: false, selectable: { multiple: true }, ...(rowClick ? { handlers: { click: 'select-row-toggle' } } : {}) },
|
|
53
|
+
columns: [
|
|
54
|
+
{ type: 'gutter', gutterName: 'row-selector', multiple: true },
|
|
55
|
+
{ type: 'string', name: 'name', header: 'name', width: 200 }
|
|
56
|
+
],
|
|
57
|
+
pagination: { pages: [100] }
|
|
58
|
+
}}
|
|
59
|
+
.fetchHandler=${async () => ({ total: records.length, records })}
|
|
60
|
+
></ox-grist>
|
|
61
|
+
`));
|
|
62
|
+
await el.fetch();
|
|
63
|
+
await settle();
|
|
64
|
+
const grist = el.renderRoot.querySelector('#grist');
|
|
65
|
+
const body = grist.renderRoot.querySelector('ox-grid-body');
|
|
66
|
+
await body.updateComplete;
|
|
67
|
+
const row = (index) => body.renderRoot.querySelectorAll('div[grid-row]')[index];
|
|
68
|
+
const click = async (target, shift = false) => {
|
|
69
|
+
const box = target.getBoundingClientRect();
|
|
70
|
+
if (shift)
|
|
71
|
+
await sendKeys({ down: 'Shift' });
|
|
72
|
+
await sendMouse({ type: 'click', position: [Math.round(box.left + box.width / 2), Math.round(box.top + box.height / 2)] });
|
|
73
|
+
if (shift)
|
|
74
|
+
await sendKeys({ up: 'Shift' });
|
|
75
|
+
await settle();
|
|
76
|
+
};
|
|
77
|
+
return { el, row, click };
|
|
78
|
+
};
|
|
79
|
+
it('shift-click on a checkbox selects the rows between', async function () {
|
|
80
|
+
var _a, _b, _c, _d;
|
|
81
|
+
this.timeout(10000);
|
|
82
|
+
const { el, row, click } = await grid(false);
|
|
83
|
+
await click((_b = (_a = row(1).querySelector('ox-grid-field').shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('input')) !== null && _b !== void 0 ? _b : row(1).querySelector('input'));
|
|
84
|
+
await click((_d = (_c = row(4).querySelector('ox-grid-field').shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelector('input')) !== null && _d !== void 0 ? _d : row(4).querySelector('input'), true);
|
|
85
|
+
expect(el.selected.map(one => one.id)).to.deep.equal(['1', '2', '3', '4']);
|
|
86
|
+
});
|
|
87
|
+
it('shift-click on a cell of a row-click grid selects the rows between, and clears them the same way', async function () {
|
|
88
|
+
this.timeout(10000);
|
|
89
|
+
const { el, row, click } = await grid(true);
|
|
90
|
+
const cell = (index) => row(index).querySelectorAll('ox-grid-field')[1];
|
|
91
|
+
await click(cell(5));
|
|
92
|
+
await click(cell(2), true);
|
|
93
|
+
expect(el.selected.map(one => one.id)).to.deep.equal(['2', '3', '4', '5']);
|
|
94
|
+
await click(cell(3));
|
|
95
|
+
await click(cell(5), true);
|
|
96
|
+
expect(el.selected.map(one => one.id)).to.deep.equal(['2']);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
//# sourceMappingURL=shift-range-select.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shift-range-select.test.js","sourceRoot":"","sources":["../../test/shift-range-select.test.ts"],"names":[],"mappings":"AAAA,kIAAkI;AAClI,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,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C,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;YAC1E,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;YACpB,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;YAC1B,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;QAC7D,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["/* Elements are compared by presence, not by value: a failing element comparison makes chai render the DOM and hang the runner. */\nimport { expect, fixture } from '@open-wc/testing'\nimport { resetMouse, sendKeys, sendMouse } from '@web/test-runner-commands'\nimport { html } from 'lit'\n\nimport '../src/data-grist.js'\nimport { selectionChange } from '../src/utils/select-range.js'\n\n/**\n * Shift-click selects a range, as a list does: the rows from the last one clicked to the clicked one take its new\n * state - from a row's checkbox and, on a grid whose row click toggles selection, from any cell of the row.\n */\n\ntype Root = HTMLElement & { renderRoot: ShadowRoot; updateComplete: Promise<unknown> }\n\nconst settle = (ms = 150) => new Promise(resolve => setTimeout(resolve, ms))\n\ndescribe('selection by range', () => {\n const rows = () => Array.from({ length: 6 }, (_, i) => ({ id: String(i) }))\n\n it('a plain click names its rows and becomes the anchor', () => {\n const records = rows()\n expect(selectionChange(records, { added: [records[2]] })).to.deep.equal({ on: [records[2]], off: [], anchor: records[2] })\n })\n it('a shift-click gives every row from the anchor the clicked row’s new state, either way round', () => {\n const records = rows()\n expect(selectionChange(records, { added: [records[4]], range: true }, records[1]).on.map(one => one.id)).to.deep.equal(['1', '2', '3', '4'])\n expect(selectionChange(records, { added: [records[0]], range: true }, records[3]).on.map(one => one.id)).to.deep.equal(['0', '1', '2', '3'])\n expect(selectionChange(records, { removed: [records[5]], range: true }, records[2]).off.map(one => one.id)).to.deep.equal(['2', '3', '4', '5'])\n })\n it('without an anchor in the rows a shift-click is a plain click', () => {\n const records = rows()\n expect(selectionChange(records, { added: [records[3]], range: true }).on).to.deep.equal([records[3]])\n expect(selectionChange(records, { added: [records[3]], range: true }, { id: 'read before' }).on).to.deep.equal([records[3]])\n })\n\n describe('on a grid', () => {\n const ignoreResizeLoop = (e: ErrorEvent) => {\n if (String(e.message).includes('ResizeObserver loop')) {\n e.stopImmediatePropagation()\n e.preventDefault()\n }\n }\n let previousOnError: OnErrorEventHandler = null\n before(() => {\n window.addEventListener('error', ignoreResizeLoop, true)\n previousOnError = window.onerror\n window.onerror = (message, ...rest) =>\n String(message).includes('ResizeObserver loop') ? true : previousOnError?.call(window, message, ...rest)\n })\n after(async function () {\n this.timeout(10000)\n await settle(300)\n window.removeEventListener('error', ignoreResizeLoop, true)\n window.onerror = previousOnError\n await resetMouse()\n })\n\n const grid = async (rowClick: boolean) => {\n const records = Array.from({ length: 8 }, (_, i) => ({ id: String(i), name: 'row ' + i }))\n const el = (await fixture(html`\n <ox-grist\n style=\"display: flex; width: 500px; height: 400px\"\n mode=\"GRID\"\n .config=${{\n rows: { appendable: false, selectable: { multiple: true }, ...(rowClick ? { handlers: { click: 'select-row-toggle' } } : {}) },\n columns: [\n { type: 'gutter', gutterName: 'row-selector', multiple: true },\n { type: 'string', name: 'name', header: 'name', width: 200 }\n ],\n pagination: { pages: [100] }\n }}\n .fetchHandler=${async () => ({ total: records.length, records })}\n ></ox-grist>\n `)) as Root & { fetch(): Promise<void>; selected: any[] }\n await el.fetch()\n await settle()\n const grist = el.renderRoot.querySelector('#grist') as Root\n const body = grist.renderRoot.querySelector('ox-grid-body') as Root\n await body.updateComplete\n const row = (index: number) => body.renderRoot.querySelectorAll('div[grid-row]')[index] as HTMLElement\n const click = async (target: HTMLElement, shift = false) => {\n const box = target.getBoundingClientRect()\n if (shift) await sendKeys({ down: 'Shift' })\n await sendMouse({ type: 'click', position: [Math.round(box.left + box.width / 2), Math.round(box.top + box.height / 2)] })\n if (shift) await sendKeys({ up: 'Shift' })\n await settle()\n }\n return { el, row, click }\n }\n\n it('shift-click on a checkbox selects the rows between', async function () {\n this.timeout(10000)\n const { el, row, click } = await grid(false)\n await click(row(1).querySelector('ox-grid-field')!.shadowRoot?.querySelector('input') ?? (row(1).querySelector('input') as HTMLElement))\n await click(row(4).querySelector('ox-grid-field')!.shadowRoot?.querySelector('input') ?? (row(4).querySelector('input') as HTMLElement), true)\n expect(el.selected.map(one => one.id)).to.deep.equal(['1', '2', '3', '4'])\n })\n\n it('shift-click on a cell of a row-click grid selects the rows between, and clears them the same way', async function () {\n this.timeout(10000)\n const { el, row, click } = await grid(true)\n const cell = (index: number) => row(index).querySelectorAll('ox-grid-field')[1] as HTMLElement\n await click(cell(5))\n await click(cell(2), true)\n expect(el.selected.map(one => one.id)).to.deep.equal(['2', '3', '4', '5'])\n await click(cell(3))\n await click(cell(5), true)\n expect(el.selected.map(one => one.id)).to.deep.equal(['2'])\n })\n })\n})\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { expect, fixture, html } from '@open-wc/testing';
|
|
2
|
+
import '../src/renderers/ox-grist-renderer-sparkline.js';
|
|
3
|
+
import { OxGristRendererSparkline, sparklineRuns } from '../src/renderers/ox-grist-renderer-sparkline.js';
|
|
4
|
+
/* A sparkline in a cell: a gap where a month has no value, the months to come dashed, the last value a dot. */
|
|
5
|
+
describe('sparkline renderer', () => {
|
|
6
|
+
it('★ splits at a missing month and puts the highest value at the top', () => {
|
|
7
|
+
const runs = sparklineRuns([1, 3, null, 2]);
|
|
8
|
+
expect(runs.actual.length).to.equal(2);
|
|
9
|
+
expect(runs.actual[0].length).to.equal(2);
|
|
10
|
+
expect(runs.actual[0][1][1]).to.equal(2, 'the highest value is at the top');
|
|
11
|
+
expect(runs.actual[1].length).to.equal(1);
|
|
12
|
+
expect(runs.last[0]).to.equal(98, 'the last value is at the right end');
|
|
13
|
+
});
|
|
14
|
+
it('draws the months to come from the last value, apart', () => {
|
|
15
|
+
const runs = sparklineRuns({ values: [10, 20], expected: [20, 30] });
|
|
16
|
+
expect(runs.expected.length).to.equal(1);
|
|
17
|
+
expect(runs.expected[0].length).to.equal(3, 'joined to the last value');
|
|
18
|
+
expect(sparklineRuns({ values: [10, null], expected: [30] }).expected[0].length).to.equal(1, 'not joined across a gap');
|
|
19
|
+
});
|
|
20
|
+
it('a flat line is in the middle; nothing draws nothing', () => {
|
|
21
|
+
expect(sparklineRuns([5, 5, 5]).actual[0].every(([, y]) => y === 12)).to.be.true;
|
|
22
|
+
expect(sparklineRuns([]).actual).to.deep.equal([]);
|
|
23
|
+
expect(sparklineRuns(null).last).to.equal(null);
|
|
24
|
+
});
|
|
25
|
+
it('renders its lines and the tooltip the column gives', async () => {
|
|
26
|
+
const element = new OxGristRendererSparkline();
|
|
27
|
+
element.value = { values: [1, 2, null, 4], expected: [5] };
|
|
28
|
+
element.column = { type: 'sparkline', name: 'trend', record: { options: { title: () => '1, 2, -, 4 → 5' } } };
|
|
29
|
+
const shown = await fixture(html `${element}`);
|
|
30
|
+
const svgElement = shown.shadowRoot.querySelector('svg');
|
|
31
|
+
expect(svgElement.querySelectorAll('path:not(.expected)').length).to.equal(1);
|
|
32
|
+
expect(svgElement.querySelectorAll('path.expected').length).to.equal(1);
|
|
33
|
+
expect(svgElement.querySelector('title').textContent).to.equal('1, 2, -, 4 → 5');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=sparkline-renderer.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sparkline-renderer.test.js","sourceRoot":"","sources":["../../test/sparkline-renderer.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,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AE,CAAA;QAC1D,OAAO,CAAC,MAAM,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,gBAAgB,EAAE,EAAE,EAAS,CAAA;QACpH,MAAM,KAAK,GAAG,MAAM,OAAO,CAA2B,IAAI,CAAA,GAAG,OAAO,EAAE,CAAC,CAAA;QACvE,MAAM,UAAU,GAAG,KAAK,CAAC,UAAW,CAAC,aAAa,CAAC,KAAK,CAAE,CAAA;QAC1D,MAAM,CAAC,UAAU,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAC7E,MAAM,CAAC,UAAU,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QACvE,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC,OAAO,CAAE,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;IACnF,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { expect, fixture, html } from '@open-wc/testing'\n\nimport '../src/renderers/ox-grist-renderer-sparkline.js'\nimport { OxGristRendererSparkline, sparklineRuns } from '../src/renderers/ox-grist-renderer-sparkline.js'\n\n/* A sparkline in a cell: a gap where a month has no value, the months to come dashed, the last value a dot. */\ndescribe('sparkline renderer', () => {\n it('★ splits at a missing month and puts the highest value at the top', () => {\n const runs = sparklineRuns([1, 3, null, 2])\n expect(runs.actual.length).to.equal(2)\n expect(runs.actual[0].length).to.equal(2)\n expect(runs.actual[0][1][1]).to.equal(2, 'the highest value is at the top')\n expect(runs.actual[1].length).to.equal(1)\n expect(runs.last![0]).to.equal(98, 'the last value is at the right end')\n })\n\n it('draws the months to come from the last value, apart', () => {\n const runs = sparklineRuns({ values: [10, 20], expected: [20, 30] })\n expect(runs.expected.length).to.equal(1)\n expect(runs.expected[0].length).to.equal(3, 'joined to the last value')\n expect(sparklineRuns({ values: [10, null], expected: [30] }).expected[0].length).to.equal(1, 'not joined across a gap')\n })\n\n it('a flat line is in the middle; nothing draws nothing', () => {\n expect(sparklineRuns([5, 5, 5]).actual[0].every(([, y]) => y === 12)).to.be.true\n expect(sparklineRuns([]).actual).to.deep.equal([])\n expect(sparklineRuns(null).last).to.equal(null)\n })\n\n it('renders its lines and the tooltip the column gives', async () => {\n const element = new OxGristRendererSparkline()\n element.value = { values: [1, 2, null, 4], expected: [5] }\n element.column = { type: 'sparkline', name: 'trend', record: { options: { title: () => '1, 2, -, 4 → 5' } } } as any\n const shown = await fixture<OxGristRendererSparkline>(html`${element}`)\n const svgElement = shown.shadowRoot!.querySelector('svg')!\n expect(svgElement.querySelectorAll('path:not(.expected)').length).to.equal(1)\n expect(svgElement.querySelectorAll('path.expected').length).to.equal(1)\n expect(svgElement.querySelector('title')!.textContent).to.equal('1, 2, -, 4 → 5')\n })\n})\n"]}
|
|
@@ -0,0 +1,275 @@
|
|
|
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 { executeServerCommand, sendMouse } from '@web/test-runner-commands';
|
|
4
|
+
import { html } from 'lit';
|
|
5
|
+
import '../src/data-grist.js';
|
|
6
|
+
import '../src/data-report.js';
|
|
7
|
+
const settle = (ms = 400) => new Promise(resolve => setTimeout(resolve, ms));
|
|
8
|
+
/** The step a vertical turn over the header moves the columns by. */
|
|
9
|
+
const STEP = 30;
|
|
10
|
+
async function page() {
|
|
11
|
+
const columns = [
|
|
12
|
+
{ type: 'gutter', gutterName: 'sequence' },
|
|
13
|
+
{ type: 'string', name: 'id', hidden: true },
|
|
14
|
+
{ type: 'string', name: 'code', header: 'code', width: 120, fixed: true }
|
|
15
|
+
];
|
|
16
|
+
for (let i = 0; i < 12; i++) {
|
|
17
|
+
columns.push({ type: 'string', name: 'c' + i, header: 'col ' + i, width: 110 });
|
|
18
|
+
}
|
|
19
|
+
const records = Array.from({ length: 60 }, (_, r) => {
|
|
20
|
+
const record = { id: String(r), code: 'C-' + r };
|
|
21
|
+
for (let i = 0; i < 12; i++)
|
|
22
|
+
record['c' + i] = `v${r}-${i}`;
|
|
23
|
+
return record;
|
|
24
|
+
});
|
|
25
|
+
const outer = (await fixture(html `
|
|
26
|
+
<div style="position: fixed; left: 0; top: 0; width: 700px; height: 400px; overflow: auto">
|
|
27
|
+
<div style="height: 50px"></div>
|
|
28
|
+
<ox-grist
|
|
29
|
+
style="width: 600px; height: 300px"
|
|
30
|
+
mode="GRID"
|
|
31
|
+
.config=${{ columns, pagination: { pages: [100] } }}
|
|
32
|
+
.fetchHandler=${async () => ({ total: records.length, records })}
|
|
33
|
+
></ox-grist>
|
|
34
|
+
<div style="height: 1000px"></div>
|
|
35
|
+
</div>
|
|
36
|
+
`));
|
|
37
|
+
const el = outer.querySelector('ox-grist');
|
|
38
|
+
await el.fetch();
|
|
39
|
+
await settle(150);
|
|
40
|
+
await el.updateComplete;
|
|
41
|
+
const grist = el.renderRoot.querySelector('#grist');
|
|
42
|
+
const scroller = grist.renderRoot.querySelector('div[grid]');
|
|
43
|
+
const header = grist.renderRoot.querySelector('ox-grid-header');
|
|
44
|
+
const body = grist.renderRoot.querySelector('ox-grid-body');
|
|
45
|
+
await body.updateComplete;
|
|
46
|
+
/*
|
|
47
|
+
* The ends as the browser lets the grid reach them. scrollWidth - clientWidth overshoots by the
|
|
48
|
+
* vertical scrollbar's gutter here (885 measured, 880 reachable), so it is not trusted.
|
|
49
|
+
*/
|
|
50
|
+
scroller.scrollTop = scroller.scrollLeft = 1e6;
|
|
51
|
+
const maxTop = Math.round(scroller.scrollTop);
|
|
52
|
+
const maxLeft = Math.round(scroller.scrollLeft);
|
|
53
|
+
scroller.scrollTop = scroller.scrollLeft = 0;
|
|
54
|
+
expect(maxTop, 'the rows must overflow, or this measures nothing').to.be.greaterThan(200);
|
|
55
|
+
expect(maxLeft, 'the columns must overflow, or this measures nothing').to.be.greaterThan(200);
|
|
56
|
+
return { outer, scroller, header, body, maxTop, maxLeft };
|
|
57
|
+
}
|
|
58
|
+
/** Where every box stands: the page, and the grid both ways. */
|
|
59
|
+
function where(outer, scroller) {
|
|
60
|
+
return { page: Math.round(outer.scrollTop), top: Math.round(scroller.scrollTop), left: Math.round(scroller.scrollLeft) };
|
|
61
|
+
}
|
|
62
|
+
/*
|
|
63
|
+
* Where to put the pointer, in the viewport. Header and body are as wide as all the columns and the body
|
|
64
|
+
* as tall as all the rows, so their own boxes reach off screen once the grid scrolls — the point is taken
|
|
65
|
+
* from the grid's visible box instead.
|
|
66
|
+
*/
|
|
67
|
+
function overRows(scroller, header) {
|
|
68
|
+
const r = scroller.getBoundingClientRect();
|
|
69
|
+
return { x: Math.round(r.left + r.width / 2), y: Math.round(header.getBoundingClientRect().bottom + 100) };
|
|
70
|
+
}
|
|
71
|
+
function overHeader(scroller, header) {
|
|
72
|
+
const r = scroller.getBoundingClientRect();
|
|
73
|
+
const h = header.getBoundingClientRect();
|
|
74
|
+
return { x: Math.round(r.left + r.width / 2), y: Math.round(h.top + h.height / 2) };
|
|
75
|
+
}
|
|
76
|
+
async function turn(at, deltaY, deltaX = 0) {
|
|
77
|
+
await executeServerCommand('send-wheel', { ...at, deltaX, deltaY });
|
|
78
|
+
await settle();
|
|
79
|
+
}
|
|
80
|
+
describe('one wheel turn moves one box', () => {
|
|
81
|
+
/* Resizing the grid body inside a fixture trips Chrome's benign "ResizeObserver loop" error. */
|
|
82
|
+
const ignoreResizeLoop = (e) => {
|
|
83
|
+
if (String(e.message).includes('ResizeObserver loop')) {
|
|
84
|
+
e.stopImmediatePropagation();
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
let previousOnError = null;
|
|
89
|
+
before(() => {
|
|
90
|
+
window.addEventListener('error', ignoreResizeLoop, true);
|
|
91
|
+
previousOnError = window.onerror;
|
|
92
|
+
window.onerror = (message, ...rest) => String(message).includes('ResizeObserver loop') ? true : previousOnError === null || previousOnError === void 0 ? void 0 : previousOnError.call(window, message, ...rest);
|
|
93
|
+
});
|
|
94
|
+
after(async () => {
|
|
95
|
+
window.removeEventListener('error', ignoreResizeLoop, true);
|
|
96
|
+
window.onerror = previousOnError;
|
|
97
|
+
await sendMouse({ type: 'move', position: [0, 0] });
|
|
98
|
+
});
|
|
99
|
+
describe('over the rows', () => {
|
|
100
|
+
it('a turn moves the rows, nothing else', async () => {
|
|
101
|
+
const { outer, scroller, header } = await page();
|
|
102
|
+
await turn(overRows(scroller, header), 100);
|
|
103
|
+
const now = where(outer, scroller);
|
|
104
|
+
expect(now.top).to.be.greaterThan(0);
|
|
105
|
+
expect(now.page).to.equal(0);
|
|
106
|
+
expect(now.left).to.equal(0);
|
|
107
|
+
});
|
|
108
|
+
it('the turn that reaches the last row stops there', async () => {
|
|
109
|
+
const { outer, scroller, header, maxTop } = await page();
|
|
110
|
+
scroller.scrollTop = maxTop - 10;
|
|
111
|
+
await settle(100);
|
|
112
|
+
await turn(overRows(scroller, header), 100);
|
|
113
|
+
const now = where(outer, scroller);
|
|
114
|
+
expect(now.top).to.be.within(maxTop - 1, maxTop);
|
|
115
|
+
expect(now.page).to.equal(0);
|
|
116
|
+
});
|
|
117
|
+
it('with the rows at their end, the next turn moves the page', async () => {
|
|
118
|
+
const { outer, scroller, header, maxTop } = await page();
|
|
119
|
+
scroller.scrollTop = maxTop;
|
|
120
|
+
scroller.scrollLeft = 100;
|
|
121
|
+
await settle(100);
|
|
122
|
+
await turn(overRows(scroller, header), 100);
|
|
123
|
+
const now = where(outer, scroller);
|
|
124
|
+
expect(now.page).to.be.greaterThan(0);
|
|
125
|
+
expect(now.top).to.be.within(maxTop - 1, maxTop);
|
|
126
|
+
expect(now.left, 'the turn does not become a sideways move').to.equal(100);
|
|
127
|
+
});
|
|
128
|
+
it('with the rows at their start, a turn up moves the page', async () => {
|
|
129
|
+
const { outer, scroller, header } = await page();
|
|
130
|
+
outer.scrollTop = 40;
|
|
131
|
+
await settle(100);
|
|
132
|
+
await turn(overRows(scroller, header), -100);
|
|
133
|
+
const now = where(outer, scroller);
|
|
134
|
+
expect(now.page).to.be.lessThan(40);
|
|
135
|
+
expect(now.top).to.equal(0);
|
|
136
|
+
});
|
|
137
|
+
it('a sideways turn at the last column stays in the grid', async () => {
|
|
138
|
+
const { scroller } = await page();
|
|
139
|
+
const style = getComputedStyle(scroller);
|
|
140
|
+
expect(style.overscrollBehaviorX).to.equal('contain');
|
|
141
|
+
expect(style.overscrollBehaviorY).to.equal('auto');
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
describe('over the header', () => {
|
|
145
|
+
it('a turn down moves the columns right, nothing else', async () => {
|
|
146
|
+
const { outer, scroller, header } = await page();
|
|
147
|
+
scroller.scrollLeft = 100;
|
|
148
|
+
await settle(100);
|
|
149
|
+
await turn(overHeader(scroller, header), 100);
|
|
150
|
+
expect(where(outer, scroller)).to.deep.equal({ page: 0, top: 0, left: 100 + STEP });
|
|
151
|
+
});
|
|
152
|
+
it('a turn up moves the columns left, nothing else', async () => {
|
|
153
|
+
const { outer, scroller, header } = await page();
|
|
154
|
+
scroller.scrollLeft = 100;
|
|
155
|
+
await settle(100);
|
|
156
|
+
await turn(overHeader(scroller, header), -100);
|
|
157
|
+
expect(where(outer, scroller)).to.deep.equal({ page: 0, top: 0, left: 100 - STEP });
|
|
158
|
+
});
|
|
159
|
+
it('the turn that brings the columns to their last one stops there', async () => {
|
|
160
|
+
const { outer, scroller, header, maxLeft } = await page();
|
|
161
|
+
scroller.scrollLeft = maxLeft - 10;
|
|
162
|
+
await settle(100);
|
|
163
|
+
await turn(overHeader(scroller, header), 100);
|
|
164
|
+
const now = where(outer, scroller);
|
|
165
|
+
expect(now.left).to.be.within(maxLeft - 1, maxLeft);
|
|
166
|
+
expect(now.top, 'the rows stay').to.equal(0);
|
|
167
|
+
expect(now.page, 'the page stays').to.equal(0);
|
|
168
|
+
});
|
|
169
|
+
it('the turn that brings the columns to their first one stops there', async () => {
|
|
170
|
+
const { outer, scroller, header } = await page();
|
|
171
|
+
scroller.scrollTop = 100;
|
|
172
|
+
scroller.scrollLeft = 10;
|
|
173
|
+
await settle(100);
|
|
174
|
+
await turn(overHeader(scroller, header), -100);
|
|
175
|
+
expect(where(outer, scroller)).to.deep.equal({ page: 0, top: 100, left: 0 });
|
|
176
|
+
});
|
|
177
|
+
it('with the columns at their last one, a turn down is left to the browser', async () => {
|
|
178
|
+
const { outer, scroller, header, maxLeft } = await page();
|
|
179
|
+
scroller.scrollLeft = maxLeft;
|
|
180
|
+
await settle(100);
|
|
181
|
+
await turn(overHeader(scroller, header), 100);
|
|
182
|
+
const now = where(outer, scroller);
|
|
183
|
+
expect(now.left).to.be.within(maxLeft - 1, maxLeft);
|
|
184
|
+
expect(now.top, 'the rows take the turn').to.be.greaterThan(0);
|
|
185
|
+
expect(now.page).to.equal(0);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
/*
|
|
189
|
+
* The report's header is a box of its own beside the body (they copy each other's scrollLeft), so
|
|
190
|
+
* a turn the header leaves alone goes to the boxes around it. The same rule holds: the columns, or
|
|
191
|
+
* the rest — never both.
|
|
192
|
+
*/
|
|
193
|
+
describe('over the report header', () => {
|
|
194
|
+
async function report() {
|
|
195
|
+
const columns = [
|
|
196
|
+
{ type: 'string', name: 'id', hidden: true },
|
|
197
|
+
{ type: 'string', name: 'kind', header: 'kind', width: 110 }
|
|
198
|
+
];
|
|
199
|
+
for (let i = 0; i < 12; i++) {
|
|
200
|
+
columns.push({ type: 'string', name: 'c' + i, header: 'col ' + i, width: 110 });
|
|
201
|
+
}
|
|
202
|
+
const records = Array.from({ length: 60 }, (_, r) => {
|
|
203
|
+
const record = { id: String(r), kind: 'K' + (r % 4) };
|
|
204
|
+
for (let i = 0; i < 12; i++)
|
|
205
|
+
record['c' + i] = `v${r}-${i}`;
|
|
206
|
+
return record;
|
|
207
|
+
});
|
|
208
|
+
const outer = (await fixture(html `
|
|
209
|
+
<div style="position: fixed; left: 0; top: 0; width: 700px; height: 400px; overflow: auto">
|
|
210
|
+
<div style="height: 50px"></div>
|
|
211
|
+
<ox-report
|
|
212
|
+
style="width: 600px; height: 300px"
|
|
213
|
+
.config=${{ columns, rows: { groups: [{ column: 'kind' }], totals: [] }, pagination: { pages: [100] } }}
|
|
214
|
+
.fetchHandler=${async () => ({ total: records.length, records })}
|
|
215
|
+
></ox-report>
|
|
216
|
+
<div style="height: 1000px"></div>
|
|
217
|
+
</div>
|
|
218
|
+
`));
|
|
219
|
+
const el = outer.querySelector('ox-report');
|
|
220
|
+
await el.fetch();
|
|
221
|
+
await settle(150);
|
|
222
|
+
await el.updateComplete;
|
|
223
|
+
const component = el.renderRoot.querySelector('#report');
|
|
224
|
+
await component.updateComplete;
|
|
225
|
+
const header = component.renderRoot.querySelector('ox-report-header');
|
|
226
|
+
const body = component.renderRoot.querySelector('ox-report-body');
|
|
227
|
+
header.scrollLeft = 1e6;
|
|
228
|
+
const maxLeft = Math.round(header.scrollLeft);
|
|
229
|
+
header.scrollLeft = 0;
|
|
230
|
+
await settle(100);
|
|
231
|
+
expect(maxLeft, 'the columns must overflow, or this measures nothing').to.be.greaterThan(200);
|
|
232
|
+
const r = header.getBoundingClientRect();
|
|
233
|
+
const at = { x: Math.round(r.left + r.width / 2), y: Math.round(r.top + r.height / 2) };
|
|
234
|
+
/* Everything a turn could move. */
|
|
235
|
+
const boxes = () => ({
|
|
236
|
+
page: Math.round(outer.scrollTop),
|
|
237
|
+
left: Math.round(header.scrollLeft),
|
|
238
|
+
rows: Math.round(body.scrollTop),
|
|
239
|
+
wrap: Math.round(el.renderRoot.querySelector('#wrap').scrollTop)
|
|
240
|
+
});
|
|
241
|
+
return { header, body, maxLeft, at, boxes };
|
|
242
|
+
}
|
|
243
|
+
it('a turn down moves the columns right, nothing else', async () => {
|
|
244
|
+
const { header, at, boxes } = await report();
|
|
245
|
+
header.scrollLeft = 100;
|
|
246
|
+
await settle(100);
|
|
247
|
+
await turn(at, 100);
|
|
248
|
+
expect(boxes()).to.deep.equal({ page: 0, left: 140, rows: 0, wrap: 0 });
|
|
249
|
+
});
|
|
250
|
+
it('the turn that brings the columns to their last one stops there', async () => {
|
|
251
|
+
const { header, maxLeft, at, boxes } = await report();
|
|
252
|
+
header.scrollLeft = maxLeft - 10;
|
|
253
|
+
await settle(100);
|
|
254
|
+
await turn(at, 100);
|
|
255
|
+
expect(boxes()).to.deep.equal({ page: 0, left: maxLeft, rows: 0, wrap: 0 });
|
|
256
|
+
});
|
|
257
|
+
it('the turn that brings the columns to their first one stops there', async () => {
|
|
258
|
+
const { header, at, boxes } = await report();
|
|
259
|
+
header.scrollLeft = 10;
|
|
260
|
+
await settle(100);
|
|
261
|
+
await turn(at, -100);
|
|
262
|
+
expect(boxes()).to.deep.equal({ page: 0, left: 0, rows: 0, wrap: 0 });
|
|
263
|
+
});
|
|
264
|
+
it('with the columns at their last one, a turn down is left to the browser', async () => {
|
|
265
|
+
const { header, maxLeft, at, boxes } = await report();
|
|
266
|
+
header.scrollLeft = maxLeft;
|
|
267
|
+
await settle(100);
|
|
268
|
+
await turn(at, 100);
|
|
269
|
+
const now = boxes();
|
|
270
|
+
expect(now.left).to.equal(maxLeft);
|
|
271
|
+
expect(now.page + now.wrap, 'a box around the header takes the turn').to.be.greaterThan(0);
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
//# sourceMappingURL=wheel-one-scroller.test.js.map
|