Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test(dashboard): compare counts, not DOM nodes, in chat tests

Yudhi Armyndharis68c984e0f02b
diff --git a/dashboard/src/components/chats/ChatSidebar.test.ts b/dashboard/src/components/chats/ChatSidebar.test.ts
index 5c6495c4c..d30086e59 100644
--- a/dashboard/src/components/chats/ChatSidebar.test.ts
+++ b/dashboard/src/components/chats/ChatSidebar.test.ts
@@ -125,7 +125,7 @@ test('the quick filters show the active one as pressed, on the Chats tab only',
rtl.cleanup();
const channels = renderSidebar('channels', [], { all: [], shown: [] });
- assert.equal(channels.container.querySelector('.chat-filters'), null);
+ assert.equal(channels.container.querySelectorAll('.chat-filters').length, 0);
});
test('a channel search with no match says so instead of showing a blank list', () => {
diff --git a/dashboard/src/components/chats/ChatThread.test.ts b/dashboard/src/components/chats/ChatThread.test.ts
index 8bfe3d374..eb10940fc 100644
--- a/dashboard/src/components/chats/ChatThread.test.ts
+++ b/dashboard/src/components/chats/ChatThread.test.ts
@@ -395,7 +395,7 @@ test('poll messages display exact choices, including outgoing and legacy polls',
Array.from(container.querySelectorAll('li bdi')).map(node => node.textContent),
[...poll.options, ...poll.options],
);
- assert.equal(container.querySelector('script'), null);
+ assert.equal(container.querySelectorAll('script').length, 0);
assert.ok(container.textContent?.includes('Legacy question'));
});
@@ -1836,5 +1836,5 @@ test('does not label an unedited or revoked message as edited', () => {
{ ...PROMPT, metadata: undefined },
{ ...PROMPT, id: 'revoked', waMessageId: 'revoked', type: 'revoked', metadata: { edited: true } },
]);
- assert.equal(container.querySelector('.message-edited'), null);
+ assert.equal(container.querySelectorAll('.message-edited').length, 0);
});
diff --git a/dashboard/src/pages/Chats.features.test.ts b/dashboard/src/pages/Chats.features.test.ts
index 818d379f4..be47338b1 100644
--- a/dashboard/src/pages/Chats.features.test.ts
+++ b/dashboard/src/pages/Chats.features.test.ts
@@ -1007,7 +1007,11 @@ test("a row's menu sits fixed above the list, and scrolling the list closes it",
const popover = container.querySelector('.chat-row-menu-popover') as HTMLElement;
assert.equal(popover.style.position, 'fixed', 'the menu can be clipped by the scrolling list');
fireEvent.scroll(popover.closest('.chat-item-wrap')?.parentElement as HTMLElement);
- assert.equal(container.querySelector('.chat-row-menu-popover'), null, 'the menu stayed open, adrift from its row');
+ assert.equal(
+ container.querySelectorAll('.chat-row-menu-popover').length,
+ 0,
+ 'the menu stayed open, adrift from its row',
+ );
});
/** The accessible name of the element that has focus: DOM nodes are compared by name, as a failed deepEqual on them hangs. */
@@ -1072,7 +1076,11 @@ test('a row menu stays open while the open thread scrolls, which does not move i
// The list the row sits in does move it.
fireEvent.scroll(container.querySelector('.chats-list') as HTMLElement);
- assert.equal(container.querySelector('.chat-row-menu-popover'), null, 'the menu stayed open, adrift from its row');
+ assert.equal(
+ container.querySelectorAll('.chat-row-menu-popover').length,
+ 0,
+ 'the menu stayed open, adrift from its row',
+ );
});
test("a row's menu is placed by physical edges, so a right-to-left page keeps the position it computed", async () => {
@@ -1223,7 +1231,7 @@ test('a number lookup that answers after the panel closed and the session change
release();
await settle();
- assert.equal(container.querySelector('.room-header'), null, "A's lookup opened a chat on B");
+ assert.equal(container.querySelectorAll('.room-header').length, 0, "A's lookup opened a chat on B");
assert.ok(!screen.queryByText('15550009999'), "A's lookup added a row to B's list");
});
@@ -1243,7 +1251,7 @@ test('a group created after the session changed is not opened on the new session
// Back to the new-chat view, Back again out of the panel, then to the other session.
fireEvent.click(screen.getByRole('button', { name: 'Back' }));
fireEvent.click(screen.getByRole('button', { name: 'Back' }));
- await waitFor(() => assert.equal(container.querySelector('.new-chat-panel'), null, 'the panel stayed open'));
+ await waitFor(() => assert.equal(container.querySelectorAll('.new-chat-panel').length, 0, 'the panel stayed open'));
switchSession(container, SECOND_SESSION.id);
await waitFor(() =>
assert.equal((container.querySelector('select.session-selector') as HTMLSelectElement).value, SECOND_SESSION.id),
@@ -1251,7 +1259,7 @@ test('a group created after the session changed is not opened on the new session
release();
await settle();
- assert.equal(container.querySelector('.room-header'), null, 'the new group opened on the other session');
+ assert.equal(container.querySelectorAll('.room-header').length, 0, 'the new group opened on the other session');
assert.ok(!screen.queryByText('Late team'), "the group was added to the other session's list");
});