|
1 | 1 | import { silenceDebugMessages } from '../../helpers/debugger' |
2 | | -import { namedNode } from 'rdflib' |
| 2 | +import { namedNode, st } from 'rdflib' |
3 | 3 | import ns from '../../../../src/ns' |
4 | 4 | import { store } from 'solid-logic' |
5 | 5 |
|
@@ -594,6 +594,57 @@ describe('buildCheckboxForm', () => { |
594 | 594 | ) |
595 | 595 | ).toBeInstanceOf(HTMLDivElement) |
596 | 596 | }) |
| 597 | + |
| 598 | + it('ignores rapid second click while async update is in progress and reenables button afterward', async () => { |
| 599 | + const dataDoc = namedNode('http://example.com/#doc') |
| 600 | + const form = namedNode('http://example.com/#form') |
| 601 | + const subject = namedNode('http://example.com/#subject') |
| 602 | + const predicate = namedNode('http://example.com/#predicate') |
| 603 | + const object = namedNode('http://example.com/#object') |
| 604 | + const statement = st(subject, predicate, object, dataDoc) |
| 605 | + |
| 606 | + const originalEditable = store.updater.editable |
| 607 | + const originalUpdate = store.updater.update |
| 608 | + |
| 609 | + const updateSpy = jest.fn((_deletes, _inserts, callback) => { |
| 610 | + return new Promise(resolve => { |
| 611 | + setTimeout(() => { |
| 612 | + callback('uri', true, 'ok') |
| 613 | + resolve(true) |
| 614 | + }, 0) |
| 615 | + }) |
| 616 | + }) |
| 617 | + |
| 618 | + store.updater.editable = jest.fn(() => true) as any |
| 619 | + store.updater.update = updateSpy as any |
| 620 | + |
| 621 | + try { |
| 622 | + const box = buildCheckboxForm( |
| 623 | + document, |
| 624 | + store, |
| 625 | + 'label', |
| 626 | + [], |
| 627 | + statement, |
| 628 | + form, |
| 629 | + dataDoc, |
| 630 | + false |
| 631 | + ) |
| 632 | + const checkboxButton = box.querySelector('button') as HTMLButtonElement |
| 633 | + |
| 634 | + checkboxButton.click() |
| 635 | + checkboxButton.click() |
| 636 | + |
| 637 | + expect(updateSpy).toHaveBeenCalledTimes(1) |
| 638 | + expect(checkboxButton.disabled).toEqual(true) |
| 639 | + |
| 640 | + await new Promise(resolve => setTimeout(resolve, 5)) |
| 641 | + |
| 642 | + expect(checkboxButton.disabled).toEqual(false) |
| 643 | + } finally { |
| 644 | + store.updater.editable = originalEditable |
| 645 | + store.updater.update = originalUpdate |
| 646 | + } |
| 647 | + }) |
597 | 648 | }) |
598 | 649 |
|
599 | 650 | describe('newThing', () => { |
|
0 commit comments