Skip to content

Commit d170cd8

Browse files
committed
Add test to cpver editing behavior as it relates to clientRequestId
1 parent b3ee41c commit d170cd8

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

packages/host/tests/acceptance/interact-submode-test.gts

+60
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
currentURL,
44
click,
55
fillIn,
6+
find,
67
triggerKeyEvent,
78
settled,
89
} from '@ember/test-helpers';
@@ -24,10 +25,16 @@ import {
2425
import { Realm } from '@cardstack/runtime-common/realm';
2526

2627
import type CardService from '@cardstack/host/services/card-service';
28+
import type MessageService from '@cardstack/host/services/message-service';
2729
import type OperatorModeStateService from '@cardstack/host/services/operator-mode-state-service';
2830
import { claimsFromRawToken } from '@cardstack/host/services/realm';
2931
import type RecentCardsService from '@cardstack/host/services/recent-cards-service';
3032

33+
import type {
34+
IncrementalIndexEventContent,
35+
RealmEventContent,
36+
} from 'https://cardstack.com/base/matrix-event';
37+
3138
import {
3239
percySnapshot,
3340
setupLocalIndexing,
@@ -1870,6 +1877,59 @@ module('Acceptance | interact submode tests', function (hooks) {
18701877
)
18711878
.doesNotExist('card error state is NOT displayed');
18721879
});
1880+
1881+
test('stack item edit results in index event that is ignored', async function (assert) {
1882+
assert.expect(6);
1883+
await visitOperatorMode({
1884+
stacks: [
1885+
[
1886+
{
1887+
id: `${testRealmURL}Person/fadhlan`,
1888+
format: 'isolated',
1889+
},
1890+
],
1891+
],
1892+
});
1893+
const messageService = this.owner.lookup(
1894+
'service:message-service',
1895+
) as MessageService;
1896+
const receivedEventDeferred = new Deferred<void>();
1897+
messageService.listenerCallbacks
1898+
.get(testRealmURL)!
1899+
.push((ev: RealmEventContent) => {
1900+
if (
1901+
ev.eventName === 'index' &&
1902+
ev.indexType === 'incremental-index-initiation'
1903+
) {
1904+
return; // ignore the index initiation event
1905+
}
1906+
ev = ev as IncrementalIndexEventContent;
1907+
assert.ok(ev.clientRequestId);
1908+
assert.strictEqual(ev.eventName, 'index');
1909+
assert.strictEqual(ev.indexType, 'incremental');
1910+
assert.deepEqual(ev.invalidations, [`${testRealmURL}Person/fadhlan`]); // the card that was edited
1911+
receivedEventDeferred.fulfill();
1912+
});
1913+
await click('[data-test-edit-button]');
1914+
fillIn('[data-test-field="firstName"] input', 'FadhlanXXX');
1915+
let inputElement = find(
1916+
'[data-test-field="firstName"] input',
1917+
) as HTMLInputElement;
1918+
inputElement.focus();
1919+
inputElement.select();
1920+
inputElement.setSelectionRange(0, 3);
1921+
await receivedEventDeferred.promise;
1922+
await settled();
1923+
inputElement = find(
1924+
'[data-test-field="firstName"] input',
1925+
) as HTMLInputElement;
1926+
assert.strictEqual(
1927+
document.activeElement,
1928+
inputElement,
1929+
'focus is preserved on the input element',
1930+
);
1931+
assert.strictEqual(document.getSelection()?.anchorOffset, 3); // selection is preserved
1932+
});
18731933
});
18741934

18751935
module('workspace index card', function () {

0 commit comments

Comments
 (0)