Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
test(dashboard): cover Number Checker wiring and last-active phrasing
Yudhi Armyndharis86639e78b7fc
diff --git a/dashboard/src/App.test.ts b/dashboard/src/App.test.tsindex f0220aa8c..46e68aa90 100644--- a/dashboard/src/App.test.ts+++ b/dashboard/src/App.test.ts@@ -92,6 +92,14 @@ test('an admin keeps the Logs entry and the route', async () => {assert.equal(window.location.pathname, '/logs');});+test('an operator opening /number-checker gets the Number Checker page', async () => {+ renderAt('/number-checker', 'operator');+ await rtl.waitFor(() => assert.ok(document.querySelector('.number-checker'), 'the page did not render'), {+ timeout: 10_000,+ });+ assert.equal(window.location.pathname, '/number-checker');+});+// API keys, Infrastructure and Plugins read routes that refuse any session-scoped key, so a scoped// admin opening one by URL or reload must be sent home rather than mount a page whose reads all 403.for (const page of ['api-keys', 'infrastructure', 'plugins']) {diff --git a/dashboard/src/components/Layout.test.ts b/dashboard/src/components/Layout.test.tsindex 8e1e58567..b4ff4bb18 100644--- a/dashboard/src/components/Layout.test.ts+++ b/dashboard/src/components/Layout.test.ts@@ -12,8 +12,11 @@ let RoleContext: (typeof import('../hooks/useRole.tsx'))['RoleContext'];// Every URL the layout asked for.const requested: string[] = [];-/** The layout for an admin key, restricted to selected sessions when `scoped` is set. */-function renderLayout(scoped = false): ReturnType<typeof import('@testing-library/react').render> {+/** The layout for a key of `userRole` (admin by default), restricted to selected sessions when `scoped` is set. */+function renderLayout(+ scoped = false,+ userRole: 'admin' | 'operator' | 'viewer' = 'admin',+): ReturnType<typeof import('@testing-library/react').render> {const role = {role: 'admin' as const,setRole: () => undefined,@@ -30,7 +33,7 @@ function renderLayout(scoped = false): ReturnType<typeof import('@testing-librarcreateElement(RoleContext.Provider,{ value: role },- createElement(MemoryRouter, null, createElement(Layout, { onLogout: () => undefined, userRole: 'admin' })),+ createElement(MemoryRouter, null, createElement(Layout, { onLogout: () => undefined, userRole })),),);}@@ -103,3 +106,11 @@ test('an unscoped admin key still checks for a newer release', async () => {assert.ok(rtl.screen.getByRole('link', { name: 'Plugins' }));await rtl.waitFor(() => assert.ok(requested.some(url => url.includes('/infra/update-check'))));});++// The Number Checker is open to every role: a viewer sees the page and why its Check button is off.+for (const userRole of ['admin', 'operator', 'viewer'] as const) {+ test(`the Number Checker is offered to ${userRole} keys`, () => {+ renderLayout(false, userRole);+ assert.equal(rtl.screen.getByRole('link', { name: 'Number Checker' }).getAttribute('href'), '/number-checker');+ });+}diff --git a/dashboard/src/pages/Dashboard.test.ts b/dashboard/src/pages/Dashboard.test.tsindex e2e5bf59e..cbf350bf5 100644--- a/dashboard/src/pages/Dashboard.test.ts+++ b/dashboard/src/pages/Dashboard.test.ts@@ -164,6 +164,15 @@ test('a webhook read still in flight shows the placeholder, not zero webhooks',assert.notEqual(statValue('Webhooks Configured'), '0');});+// A date-only formatter put a session active a few hours ago on a bare date.+test('a session last active a few hours ago reads in hours, not as a date', async () => {+ webhooksStatus = 403;+ sessionList = [{ ...READY_SESSION, lastActive: new Date(Date.now() - 5 * 3_600_000).toISOString() }];+ renderDashboard();+ await rtl.screen.findByText('Main');+ assert.equal(document.querySelector('.last-active')?.textContent, '5 hours ago');+});+test('a read-only key is offered no Disconnect', async () => {webhooksStatus = 403;sessionList = [READY_SESSION];diff --git a/dashboard/src/pages/Sessions.test.ts b/dashboard/src/pages/Sessions.test.tsindex 9d940264d..128968795 100644--- a/dashboard/src/pages/Sessions.test.ts+++ b/dashboard/src/pages/Sessions.test.ts@@ -1033,6 +1033,29 @@ test('a failed status push closes that session QR modal', async () => {await waitFor(() => assert.ok(!screen.queryByRole('dialog'), 'the QR modal stayed open after its session failed'));});+// A date-only formatter put a session active a few hours ago on a bare date.+test('a session last active a few hours ago reads in hours, not as a date', async () => {+ const { screen, within } = rtl;+ resetFetchCalls();+ window.sessionStorage.setItem('openwa_api_key', 'test-key');+ const lastActive = new Date(Date.now() - 5 * 3_600_000).toISOString();+ SESSIONS.push({+ ...SESSION_QR,+ id: 'sess-recent-1',+ name: 'recent',+ status: 'ready',+ phone: '15550004444',+ lastActive,+ });+ try {+ renderSessions();+ const card = (await screen.findByText('recent')).closest('.session-card') as HTMLElement;+ assert.ok(within(card).getByText('5 hours ago'));+ } finally {+ SESSIONS.pop();+ }+});+// The gateway writes the linked phone and lastActive when a session reaches READY; the push carries// only the status, so the card needs a re-read to show them.test('a ready push re-reads the list so a newly linked card shows its phone', async () => {