Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
test(dashboard): assert DOM absence on a boolean in more page tests
Yudhi Armyndharis27041aa926e6
diff --git a/dashboard/src/components/GlobalSearch.test.ts b/dashboard/src/components/GlobalSearch.test.tsindex 343d0f4c6..89fb089a2 100644--- a/dashboard/src/components/GlobalSearch.test.ts+++ b/dashboard/src/components/GlobalSearch.test.ts@@ -197,7 +197,7 @@ test('"more" does not repeat a hit that a newly indexed message pushed onto theawait act(async () => pending.get('refund')!(['refund 39'], 41));await waitFor(() => assert.ok(screen.queryByText('refund 39')));assert.equal(screen.getAllByRole('option').length, 40);- assert.equal(screen.queryByRole('button', { name: /41/ }), null, '"more" stayed up after the last page');+ assert.equal(screen.queryByRole('button', { name: /41/ }) === null, true, '"more" stayed up after the last page');});test('a failed "more" keeps the results already shown and offers the button again', async () => {@@ -218,7 +218,7 @@ test('a failed "more" keeps the results already shown and offers the button agaiawait waitFor(() => assert.deepEqual(offsets, ['0', '20', '20']));await act(async () => pending.get('refund')!(page(20), 40));await waitFor(() => assert.equal(screen.getAllByRole('option').length, 40));- assert.equal(screen.queryByText('Search failed. Try again.'), null);+ assert.equal(screen.queryByText('Search failed. Try again.') === null, true);});test('a failed search shows only the error', async () => {@@ -234,8 +234,8 @@ test('a failed search shows only the error', async () => {await act(async () => failing.get('refunds')!(500));await screen.findByText('Search failed. Try again.');assert.equal(screen.queryAllByRole('option').length, 0, "the previous query's hits stayed on screen");- assert.equal(screen.queryByRole('button', { name: more40 }), null);- assert.equal(screen.queryByText('No messages found.'), null);+ assert.equal(screen.queryByRole('button', { name: more40 }) === null, true);+ assert.equal(screen.queryByText('No messages found.') === null, true);});test('Tab then Enter on "more" keeps the results open and returns focus to the input', async () => {diff --git a/dashboard/src/pages/ApiKeys.test.ts b/dashboard/src/pages/ApiKeys.test.tsindex 71ffa6b06..541338889 100644--- a/dashboard/src/pages/ApiKeys.test.ts+++ b/dashboard/src/pages/ApiKeys.test.ts@@ -194,7 +194,7 @@ test('the create modal stays open until the request settles and then shows the sfireEvent.click(create);const cancel = await screen.findByRole<HTMLButtonElement>('button', { name: 'Cancel' });await rtl.waitFor(() => assert.equal(cancel.disabled, true, 'Cancel is live while the key is being created'));- assert.equal(screen.queryByRole('button', { name: 'Close' }), null, 'the close button is live mid-request');+ assert.equal(screen.queryByRole('button', { name: 'Close' }) === null, true, 'the close button is live mid-request');fireEvent.keyDown(document, { key: 'Escape' });fireEvent.mouseDown(document.querySelector('.modal-overlay') as HTMLElement);screen.getByRole('dialog');@@ -246,7 +246,7 @@ test('switching the new key to admin hides and drops the chat list', async () =>fireEvent.change(screen.getByLabelText('Name'), { target: { value: 'root-key' } });fireEvent.change(screen.getByLabelText('Chat access (optional)'), { target: { value: '[email protected]' } });fireEvent.change(screen.getByLabelText('Role'), { target: { value: 'admin' } });- assert.equal(screen.queryByLabelText('Chat access (optional)'), null);+ assert.equal(screen.queryByLabelText('Chat access (optional)') === null, true);fireEvent.click(create);await waitFor(() => assert.ok(createBody));assert.deepEqual(createBody, { name: 'root-key', role: 'admin' });@@ -282,7 +282,7 @@ test('an active admin key can be edited; a revoked key cannot', async () => {assert.equal(rtl.screen.getAllByTitle('Edit access').length, 1);rtl.fireEvent.click(rtl.screen.getByTitle('Edit access'));// Admin keys stay unscoped in the dashboard: no session or chat fields.- assert.equal(rtl.screen.queryByLabelText('Chat access (optional)'), null);+ assert.equal(rtl.screen.queryByLabelText('Chat access (optional)') === null, true);rtl.screen.getByLabelText('Allowed IP addresses (optional)');});@@ -303,7 +303,7 @@ test('saving an untouched key sends nothing, even with an expiry and lists set',expiresAt: '2027-03-04T05:06:59.000Z',});rtl.fireEvent.click(save);- await rtl.waitFor(() => assert.equal(rtl.screen.queryByRole('button', { name: 'Save' }), null));+ await rtl.waitFor(() => assert.equal(rtl.screen.queryByRole('button', { name: 'Save' }) === null, true));assert.deepEqual(updateBodies, []);});@@ -377,7 +377,7 @@ test('editing the key the dashboard is signed in with warns before saving', asynrtl.cleanup();window.sessionStorage.setItem('openwa_api_key', 'owa_k1zzXXXXYYYYZZZZ');await openEdit(billingBot);- assert.equal(rtl.screen.queryByText(/This dashboard is signed in with this key/), null);+ assert.equal(rtl.screen.queryByText(/This dashboard is signed in with this key/) === null, true);});// A datetime-local with a blank segment reports value '' (as an empty field does) and sets badInput.@@ -472,7 +472,7 @@ test('Remove expiry appears for a partial expiry typed into an empty field', asyassert.deepEqual(updateBodies, []);fireEvent.click(screen.getByRole('button', { name: 'Remove expiry' }));fireEvent.click(save);- await waitFor(() => assert.equal(screen.queryByRole('button', { name: 'Save' }), null));+ await waitFor(() => assert.equal(screen.queryByRole('button', { name: 'Save' }) === null, true));assert.deepEqual(updateBodies, []);});diff --git a/dashboard/src/pages/Chats.test.ts b/dashboard/src/pages/Chats.test.tsindex ad2c0ff8d..c56a61754 100644--- a/dashboard/src/pages/Chats.test.ts+++ b/dashboard/src/pages/Chats.test.ts@@ -524,7 +524,7 @@ test('status compose modal posts a text status with the baileys recipient allow-// Success path: the modal closes and onPosted refetches the status list (one GET from the// tab switch, one from the refetch).- await waitFor(() => assert.equal(screen.queryByRole('dialog'), null));+ await waitFor(() => assert.equal(screen.queryByRole('dialog') === null, true));await waitFor(() => {assert.ok(countFetchCalls('GET', `/api/sessions/${SESSION.id}/status`) >= 2,@@ -576,7 +576,7 @@ test('a typed draft survives closing and reopening the room', async () => {// Close the room with the back button (aria-label = common.back); the composer unmounts.fireEvent.click(screen.getByRole('button', { name: 'Back' }));- assert.equal(screen.queryByRole('button', { name: 'Back' }), null);+ assert.equal(screen.queryByRole('button', { name: 'Back' }) === null, true);// Reopen the same chat (room closed → 'Alice' matches only the sidebar row): the draft must// still be in the input — the page owns messageInput precisely so it survives this round trip.@@ -602,12 +602,16 @@ test('Escape dismisses the emoji picker instead of the conversation behind it',// inside the picker, so a handler bound to the picker element would never see this event. One// press must do both things, dismiss the picker and leave the conversation open.fireEvent.keyDown(document, { key: 'Escape' });- await waitFor(() => assert.equal(container.querySelector('.chats-emoji-picker'), null, 'the picker stayed open'));+ await waitFor(() =>+ assert.equal(container.querySelector('.chats-emoji-picker') === null, true, 'the picker stayed open'),+ );assert.ok(screen.queryByRole('button', { name: 'Back' }), 'Escape closed the room while the picker owned it');// With the picker gone the key belongs to the room again, which is what it must not keep.fireEvent.keyDown(document, { key: 'Escape' });- await waitFor(() => assert.equal(screen.queryByRole('button', { name: 'Back' }), null, 'the room stayed open'));+ await waitFor(() =>+ assert.equal(screen.queryByRole('button', { name: 'Back' }) === null, true, 'the room stayed open'),+ );});test('the emoji picker yields Escape to a surface layered above it', async () => {@@ -640,7 +644,9 @@ test('the emoji picker yields Escape to a surface layered above it', async () =>// And once that surface is gone the picker answers again.fireEvent.keyDown(document, { key: 'Escape' });- await waitFor(() => assert.equal(container.querySelector('.chats-emoji-picker'), null, 'the picker stayed open'));+ await waitFor(() =>+ assert.equal(container.querySelector('.chats-emoji-picker') === null, true, 'the picker stayed open'),+ );});test('Escape closes the open room, and is left alone while a dialog owns it', async () => {@@ -663,7 +669,7 @@ test('Escape closes the open room, and is left alone while a dialog owns it', asdialog.remove();fireEvent.keyDown(document, { key: 'Escape' });await waitFor(() =>- assert.equal(screen.queryByRole('button', { name: 'Back' }), null, 'Escape did not close the room'),+ assert.equal(screen.queryByRole('button', { name: 'Back' }) === null, true, 'Escape did not close the room'),);});@@ -734,7 +740,7 @@ test('an operator key on whatsapp-web.js posts a status without the admin-only econst postButton = within(dialog).getByRole('button', { name: 'Post' }) as HTMLButtonElement;await waitFor(() => assert.equal(postButton.disabled, false, 'Post never enabled for an operator key'));// whatsapp-web.js has no recipient list, so the picker stays hidden and none are sent.- assert.equal(within(dialog).queryByRole('checkbox'), null);+ assert.equal(within(dialog).queryByRole('checkbox') === null, true);fireEvent.click(postButton);await waitFor(() => {@@ -758,7 +764,7 @@ test('an operator key on whatsapp-web.js lists its channels', async () => {await screen.findByText('Main (15551234567)');fireEvent.click(screen.getByRole('tab', { name: 'Channels' }));await screen.findByText(CHANNEL.name);- assert.equal(screen.queryByText('Channels are not supported on the Baileys engine.'), null);+ assert.equal(screen.queryByText('Channels are not supported on the Baileys engine.') === null, true);} finally {window.sessionStorage.setItem('openwa_user_role', 'admin');window.sessionStorage.setItem('openwa_engine_type', 'baileys');@@ -1246,7 +1252,7 @@ test('a staged attachment survives closing and reopening the same room', async (// Close the room: ChatComposer unmounts, so the file only survives because the page owns it.fireEvent.click(screen.getByRole('button', { name: 'Back' }));- assert.equal(container.querySelector('.attachment-preview-banner'), null);+ assert.equal(container.querySelector('.attachment-preview-banner') === null, true);fireEvent.click(screen.getByText('Alice'));await within(container.querySelector('.room-messages') as HTMLElement).findByText('hello from alice');@@ -1277,7 +1283,11 @@ test('text typed with an audio attachment stays in the input instead of showingawait flush();assert.equal(input.value, 'not a caption', 'the text that was not sent was cleared');- assert.equal(within(thread).queryByText('not a caption'), null, 'the audio bubble shows text that was never sent');+ assert.equal(+ within(thread).queryByText('not a caption') === null,+ true,+ 'the audio bubble shows text that was never sent',+ );});test('sends answered with no message id each keep their own bubble', async () => {@@ -1400,8 +1410,8 @@ test('a staged attachment is dropped when a different chat is opened', async ()fireEvent.click(screen.getByText('Carol'));await within(container.querySelector('.room-header') as HTMLElement).findByText('Carol');assert.equal(- container.querySelector('.attachment-preview-banner'),- null,+ container.querySelector('.attachment-preview-banner') === null,+ true,"Alice's attachment followed the user into Carol's room",);});@@ -1465,7 +1475,7 @@ async function reopenAfterSessionSwitch(): Promise<void> {// have missed messages by the time it is selected again.selectSession(SESSION_2.id);await screen.findByText('Carol');- await waitFor(() => assert.equal(screen.queryByText('Alice'), null));+ await waitFor(() => assert.equal(screen.queryByText('Alice') === null, true));selectSession(SESSION.id);fireEvent.click(await screen.findByText('Alice'));await within(container.querySelector('.room-messages') as HTMLElement).findByText('hello from alice');@@ -1527,7 +1537,7 @@ test('a staged reply is dropped when another session is opened', async () => {fireEvent.change(container.querySelector('select.session-selector') as HTMLSelectElement, {target: { value: SESSION_2.id },});- await waitFor(() => assert.equal(container.querySelector('.room-header'), null));+ await waitFor(() => assert.equal(container.querySelector('.room-header') === null, true));fireEvent.click(await screen.findByText('Alice'));await within(container.querySelector('.room-header') as HTMLElement).findByText('Alice');assert.equal(@@ -1638,7 +1648,11 @@ test("a chat list that answers after a switch leaves the new session's spinner ureleaseSecond();await screen.findByText('Carol');- assert.equal(container.querySelector('.chats-list-loading'), null, 'the list stayed on the loading spinner');+ assert.equal(+ container.querySelector('.chats-list-loading') === null,+ true,+ 'the list stayed on the loading spinner',+ );} finally {twoSessions = false;}@@ -1697,7 +1711,11 @@ test("a failed background refetch during a session switch keeps the spinner overreleaseSecond();await screen.findByText('Carol');- assert.equal(container.querySelector('.chats-list-loading'), null, 'the list stayed on the loading spinner');+ assert.equal(+ container.querySelector('.chats-list-loading') === null,+ true,+ 'the list stayed on the loading spinner',+ );} finally {twoSessions = false;}@@ -1736,7 +1754,7 @@ test('a chat list refetch lands while a newer one is out, and an older answer ne// The first answer is the newest one applied so far, so it lands although newer calls are still out.answers[0]();await screen.findByText('carol v1');- assert.equal(container.querySelector('.chats-list-loading'), null, 'the list stayed on the loading spinner');+ assert.equal(container.querySelector('.chats-list-loading') === null, true, 'the list stayed on the loading spinner');answers[2]();await screen.findByText('carol v3');@@ -2040,7 +2058,7 @@ test('a search hit in another session on the chat open in this one opens it therawait screen.findByText('Carol');const select = container.querySelector('select.session-selector') as HTMLSelectElement;fireEvent.change(select, { target: { value: SESSION_2.id } });- await waitFor(() => assert.equal(screen.queryByText('Carol'), null));+ await waitFor(() => assert.equal(screen.queryByText('Carol') === null, true));await openAlice();fireEvent.change(select, { target: { value: SESSION.id } });await screen.findByText('Carol');@@ -2361,7 +2379,7 @@ test('scrolling to the top of a long thread pulls exactly one older page, then sconst { container } = renderChats();const thread = await openPagedChat(container);- assert.equal(within(thread).queryByText('paged message 0'), null);+ assert.equal(within(thread).queryByText('paged message 0') === null, true);assert.equal(countFetchCalls('GET', pagedMessagesPath(0)), 1);makeScrollable(thread, 0);@@ -2394,8 +2412,12 @@ test('a failed older-page fetch does not blank an already-loaded thread', async// the 100 already-loaded bubbles with the full-screen error placeholder — and the collapsed// container could then never regain enough height to retry by scrolling.await waitFor(() => assert.ok(within(thread).queryByText('paged message 119')));- assert.equal(within(thread).queryByText(/couldn.t load messages/i), null, 'the full-screen error must not render');- assert.equal(container.querySelector('.messages-empty'), null, 'the full-screen error must not render');+ assert.equal(+ within(thread).queryByText(/couldn.t load messages/i) === null,+ true,+ 'the full-screen error must not render',+ );+ assert.equal(container.querySelector('.messages-empty') === null, true, 'the full-screen error must not render');// The failure shows inline, where the spinner would have — with a retry hint, since the// container never collapsed and scrolling up again is still possible.@@ -2459,7 +2481,7 @@ test('the reading position is held across the commit that lands an older page',releaseOlderPage();await within(thread).findByText('paged message 0');- await waitFor(() => assert.equal(thread.querySelector('.messages-loading-older'), null));+ await waitFor(() => assert.equal(thread.querySelector('.messages-loading-older') === null, true));// The thread grew upward by the new bubbles, so the row the user was reading has to move down by// exactly that much. The regression this locks out: measuring the growth on the first commit that@@ -2487,7 +2509,7 @@ test('leaving without scrolling again restores the corrected position, not the sreleaseOlderPage();await within(thread).findByText('paged message 0');- await waitFor(() => assert.equal(thread.querySelector('.messages-loading-older'), null));+ await waitFor(() => assert.equal(thread.querySelector('.messages-loading-older') === null, true));const corrected = thread.scrollTop;assert.ok(corrected > 0, 'expected the older-page correction to have moved scrollTop off 0');diff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.tsindex ade142d62..08e273f17 100644--- a/dashboard/src/pages/Infrastructure.test.ts+++ b/dashboard/src/pages/Infrastructure.test.ts@@ -477,7 +477,7 @@ test('a failed first /status read shows the status error card and no form', asynrenderInfrastructure();await rtl.screen.findByText(STATUS_LOAD_ERROR);- assert.equal(rtl.screen.queryByRole('button', { name: 'Save Configuration' }), null);+ assert.equal(rtl.screen.queryByRole('button', { name: 'Save Configuration' }) === null, true);});test('a failed background /status refetch keeps the form and the restart modal on screen', async () => {@@ -495,7 +495,7 @@ test('a failed background /status refetch keeps the form and the restart modal oawait new Promise(resolve => setTimeout(resolve, 50));assert.ok(screen.queryByRole('dialog'), 'the restart modal must stay open');- assert.equal(screen.queryByText(STATUS_LOAD_ERROR), null);+ assert.equal(screen.queryByText(STATUS_LOAD_ERROR) === null, true);screen.getByRole('button', { name: 'Save Configuration' });});@@ -823,7 +823,7 @@ test('a refused restart shows the server reason and never polls readiness', { ti// Past the first readiness poll (3s), which a restart assumed to be under way would have sent.await new Promise(resolve => setTimeout(resolve, 3500));assert.equal(findFetchCall('GET', '/api/health/ready'), undefined);- assert.equal(within(dialog).queryByText('Server ready'), null);+ assert.equal(within(dialog).queryByText('Server ready') === null, true);});test(@@ -859,8 +859,8 @@ test(await within(dialog).findByText('The proxy returned an error before the server answered, so it is not known whether the restart is in progress. Reload in a minute to check.',);- assert.equal(within(dialog).queryByText('Restart failed'), null);- assert.equal(within(dialog).queryByText('HTTP 504'), null);+ assert.equal(within(dialog).queryByText('Restart failed') === null, true);+ assert.equal(within(dialog).queryByText('HTTP 504') === null, true);assert.ok(within(dialog).getByText('Please wait…'), 'the unknown outcome has no neutral title');assert.ok(within(dialog).getByRole('button', { name: 'Reload Page' }), 'no way to reload by hand');// Past the first readiness poll (3s) and the reload a confirmed restart schedules 2s after it.@@ -898,7 +898,7 @@ test('a proxy 502 without a gateway code on the restart request reports an unknoawait within(dialog).findByText('The proxy returned an error before the server answered, so it is not known whether the restart is in progress. Reload in a minute to check.',);- assert.equal(within(dialog).queryByText('Restart failed'), null);+ assert.equal(within(dialog).queryByText('Restart failed') === null, true);});test('a 502 the gateway stamped with a code is a refusal, not an unknown outcome', async () => {@@ -964,7 +964,10 @@ test(await within(dialog).findByText('Server ready', {}, { timeout: 5_000 });assert.ok(within(dialog).getByText(failure), 'the orchestration error is not shown');assert.ok(within(dialog).getByRole('button', { name: 'Reload Page' }), 'no way to reload after reading');- assert.equal(within(dialog).queryByText('Server is back online! The page will reload automatically.'), null);+ assert.equal(+ within(dialog).queryByText('Server is back online! The page will reload automatically.') === null,+ true,+ );// Past the 2s after which a clean restart reloads the page.await new Promise(resolve => setTimeout(resolve, 2500));assert.deepEqual(navigations, [], 'the page reloaded over the warning');diff --git a/dashboard/src/pages/Logs.test.ts b/dashboard/src/pages/Logs.test.tsindex e1214264e..aef7a5ee2 100644--- a/dashboard/src/pages/Logs.test.ts+++ b/dashboard/src/pages/Logs.test.ts@@ -213,7 +213,11 @@ test('an export stopped by the throttle says to wait, not to narrow the filter',fireEvent.click(screen.getByRole('button', { name: 'Export CSV' }));// The walk retries the refused page after one second and after two more before it stops.await screen.findByText(/newest 400 entries because the gateway is rate-limiting/, {}, { timeout: 10_000 });- assert.equal(screen.queryByText(/Narrow the severity filter/), null, 'the throttle was reported as the row cap');+ assert.equal(+ screen.queryByText(/Narrow the severity filter/) === null,+ true,+ 'the throttle was reported as the row cap',+ );assert.equal(downloads.length, 1, 'the rows fetched before the throttle are still downloaded');} finally {exportTotal = null;@@ -247,7 +251,11 @@ test('a truncated export whose search matches nothing names the entries it scannfireEvent.change(screen.getByPlaceholderText('Search logs...'), { target: { value: 'no-such-action' } });fireEvent.click(screen.getByRole('button', { name: 'Export CSV' }));await screen.findByText(/None of the newest 10,000 entries scanned match the search/, {}, { timeout: 10_000 });- assert.equal(screen.queryByText(/The export covers only/), null, 'the warning reads as if a file was produced');+ assert.equal(+ screen.queryByText(/The export covers only/) === null,+ true,+ 'the warning reads as if a file was produced',+ );assert.equal(downloads.length, 0, 'an empty export was downloaded');} finally {exportTotal = null;diff --git a/dashboard/src/pages/MessageTester.test.ts b/dashboard/src/pages/MessageTester.test.tsindex 4d83f8a10..a5d761b8a 100644--- a/dashboard/src/pages/MessageTester.test.ts+++ b/dashboard/src/pages/MessageTester.test.ts@@ -225,7 +225,7 @@ test('cancelling a group send stops the groups still waiting', async () => {assert.ok(rtl.screen.getByText('1/2 sent'));// One of two groups sent is not a success.assert.ok(rtl.screen.getByText('Failed'));- assert.equal(rtl.screen.queryByText('Success'), null);+ assert.equal(rtl.screen.queryByText('Success') === null, true);assert.equal(window.document.getElementById('mt-2')?.matches(':disabled'), false);});@@ -774,7 +774,7 @@ test('a media file that cannot be read is reported and not attached', async () =pickMedia(container, new window.File(['x'], 'broken.png', { type: 'image/png' }));await rtl.screen.findByText('File read failed');- assert.equal(rtl.screen.queryByText('broken.png'), null);+ assert.equal(rtl.screen.queryByText('broken.png') === null, true);} finally {globalThis.FileReader.prototype.readAsDataURL = readAsDataURL;}@@ -796,7 +796,7 @@ test('a failed sessions read is reported, not shown as "no ready sessions"', asyconst alert = await rtl.screen.findByRole('alert');rtl.within(alert).getByText(/Failed to load data/);rtl.within(alert).getByText(/gateway restarting/);- assert.equal(rtl.screen.queryByRole('option', { name: 'No ready sessions' }), null);+ assert.equal(rtl.screen.queryByRole('option', { name: 'No ready sessions' }) === null, true);});test('a failed groups read is reported, not shown as "no groups found"', async () => {@@ -814,7 +814,7 @@ test('a failed groups read is reported, not shown as "no groups found"', async (const alert = await rtl.screen.findByRole('alert');rtl.within(alert).getByText(/Failed to load data/);- assert.equal(rtl.screen.queryByText('No groups found'), null);+ assert.equal(rtl.screen.queryByText('No groups found') === null, true);});test('Send stays disabled while a batch cancel is in flight, so its answer cannot land on a newer batch', async () => {