Support current battle choice promises and persistent notices
Verify and publish checkpoint container / container (push) Successful in 11m42s
Verify and publish checkpoint container / container (push) Successful in 11m42s
This commit is contained in:
1 parent
77d02b3231
commit
bd8377d87b
16 files changed
+684
-32
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { Children, isValidElement } from 'react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { ActionableNotice } from '../components/actionable-notice';
|
||||
import { Button } from '../components/ui/button';
|
||||
import { initialActionableNotices, updateActionableNotices } from '../lib/actionable-notices';
|
||||
|
||||
void test('distinct actionable messages stay queued until each Continue, while exact retries coalesce', () => {
|
||||
let queue = initialActionableNotices;
|
||||
const enqueue = (text: string) => { queue = updateActionableNotices(queue, {type:'enqueue',text}); };
|
||||
const dismiss = (id: number) => { queue = updateActionableNotices(queue, {type:'dismiss',id}); };
|
||||
enqueue('Your action may have completed. Check the refreshed table.');
|
||||
const first = queue.items[0];
|
||||
enqueue('Your action may have completed. Check the refreshed table.');
|
||||
enqueue('Second faction added. Switch factions to make each ready.');
|
||||
assert.deepEqual(queue.items.map(item => item.text), [
|
||||
'Your action may have completed. Check the refreshed table.',
|
||||
'Second faction added. Switch factions to make each ready.',
|
||||
]);
|
||||
const firstView = ActionableNotice({notice:first,onDismiss:dismiss}); assert.ok(firstView);
|
||||
const html = renderToStaticMarkup(firstView);
|
||||
assert.match(html, /Your action may have completed/);
|
||||
assert.match(html, /Continue/);
|
||||
assert.doesNotMatch(html, /Second faction added/);
|
||||
const button = Children.toArray(firstView.props.children).filter(isValidElement).find(child => child.type === Button);
|
||||
assert.ok(button);
|
||||
(button.props as {onClick: () => void}).onClick();
|
||||
assert.equal(queue.items[0].text, 'Second faction added. Switch factions to make each ready.');
|
||||
(button.props as {onClick: () => void}).onClick();
|
||||
assert.equal(queue.items.length, 1, 'A stale prior Continue cannot dismiss the next notice');
|
||||
dismiss(queue.items[0].id);
|
||||
assert.deepEqual(queue.items, []);
|
||||
assert.equal(ActionableNotice({notice:null,onDismiss:dismiss}), null);
|
||||
});
|
||||
|
||||
void test('retrying after explicit acknowledgement creates an independent notice identity', () => {
|
||||
let queue = updateActionableNotices(initialActionableNotices, {type:'enqueue',text:'Reconnect required.'});
|
||||
const old = queue.items[0];
|
||||
queue = updateActionableNotices(queue, {type:'dismiss',id:old.id});
|
||||
queue = updateActionableNotices(queue, {type:'enqueue',text:'Reconnect required.'});
|
||||
assert.notEqual(queue.items[0].id, old.id);
|
||||
queue = updateActionableNotices(queue, {type:'dismiss',id:old.id});
|
||||
assert.equal(queue.items.length, 1);
|
||||
queue = updateActionableNotices(queue, {type:'dismiss',id:queue.items[0].id});
|
||||
const next = updateActionableNotices(queue, {type:'enqueue',text:'Another seat.'});
|
||||
assert.ok(next.items[0].id > old.id);
|
||||
assert.deepEqual(initialActionableNotices.items, [], 'The shared initial state was not mutated');
|
||||
});
|
||||
Reference in new issue
Block a user