Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
test(dashboard): cover formula neutralization in the Logs export
Yudhi Armyndharisbfbb69186e28
diff --git a/dashboard/src/pages/Logs.test.ts b/dashboard/src/pages/Logs.test.tsindex aef7a5ee2..534b6f723 100644--- a/dashboard/src/pages/Logs.test.ts+++ b/dashboard/src/pages/Logs.test.ts@@ -61,6 +61,8 @@ let exportTotal: number | null = null;let exportThrottledFrom: number | null = null;// When set, the export walks a 300-row table that gains a newest row after its first page is read.let exportGrowsMidWalk = false;+// When set, the export's page walk sees exactly these rows.+let exportRows: AuditLog[] | null = null;// When set, the on-screen list reports this many rows in total, so the page has a pager.let listTotal: number | null = null;// When set, a request for the first on-screen page waits for it before answering.@@ -94,6 +96,9 @@ function installFetchStub(): void {const shifted = [exportRow(-1), ...[...Array(300).keys()].map(exportRow)];return Promise.resolve(jsonResponse({ data: shifted.slice(offset), total: 301 }));}+ if (exportRows && url.includes('limit=200')) {+ return Promise.resolve(jsonResponse({ data: exportRows, total: exportRows.length }));+ }if (listFailure && !url.includes('limit=200')) {return Promise.resolve(new Response(JSON.stringify({ message: 'Bad Gateway' }), { status: listFailure }));}@@ -281,6 +286,27 @@ test('a row written while the export walks the pages is not exported twice', asy}});+// Rows carry request paths and error messages a client chose, and a spreadsheet runs a cell that starts with = + - or @.+test('an exported cell that starts like a formula is neutralized', async () => {+ const { screen, fireEvent, waitFor } = rtl;+ const { downloads, restore } = recordDownloads();+ exportRows = [+ { ...LOG_FAILED_SEND, id: 'row-formula', path: '=HYPERLINK("https://example.test","x")', errorMessage: '+cmd' },+ ];+ try {+ renderLogs();+ await screen.findByText('infra.restart');+ fireEvent.click(screen.getByRole('button', { name: 'Export CSV' }));+ await waitFor(() => assert.equal(downloads.length, 1));+ const csv = await downloads[0].text();+ assert.ok(csv.includes(`"'=HYPERLINK(""https://example.test"",""x"")"`), csv);+ assert.ok(csv.endsWith(",'+cmd"), csv);+ } finally {+ exportRows = null;+ restore();+ }+});+test('the table grid declares one column track per rendered cell', async () => {const container = renderLogs();await rtl.screen.findByText('infra.restart');