import { sanitizeViewName } from '../sanitize-view-name'; describe(`[datadog-rum] ${sanitizeViewName.name}`, () => { const subject = (viewName: string) => { return sanitizeViewName(viewName); }; describe('when view name contains IDs', () => { test.each([ ['/new/reports/123', '/new/reports/{id}'], ['/new/reports/123/summary', '/new/reports/{id}/summary'], ['/new/reports/123/summary/321', '/new/reports/{id}/summary/{id}'], ['/new/reports/123ab/summary/32100--r', '/new/reports/{id}/summary/{id}'], ['/new/reports/10-10-2022/summary/321', '/new/reports/{id}/summary/{id}'], ['/new/reports/null/summary/undefined', '/new/reports/{id}/summary/{id}'], [ '/new/inventory/download-import-errors/Temp%2FDataExportResults%2Fb8ef44acd-d4ed-4d1a-9f9f-a6c21e80ce9e.xlsx/1', '/new/inventory/download-import-errors/{id}/{id}', ], [ '/new/inventory/download-import-errors/Temp%2FDataExportResults%2Fb8ef44acd-d4ed-4d1a-9f9f-a6c21e80ce9e.txt.xlsx/1', '/new/inventory/download-import-errors/{id}/{id}', ], [ '/new/inventory/download-import-errors/hello.txt', '/new/inventory/download-import-errors/{id}', ], ['/AbandonedScorecard/1/2/%20Abandoned', '/abandonedscorecard/{id}/{id}/{id}'], ['/Calls/Caller/%2019104715121', '/calls/caller/{id}'], [ '/dispatch/routes/coordinates=33.5365013%2C-111.944217&name=Richard+Nearhood&address=6767+North+63rd+Place%2C+Paradise+Valley%2C+AZ+85253+USA', '/dispatch/routes/{id}', ], [ '/new/marketing/re/reputationmanagement/id=4716512/hello', '/new/marketing/re/reputationmanagement/{id}/hello', ], ['/KpiMatrix/Office%20Performance', '/kpimatrix/{id}'], ['/ChatCenter/+16193895593+1619-389-5593', '/chatcenter/{id}'], ])('replaces IDs with placeholders (%s -> %s)', (viewName, expected) => { expect(subject(viewName)).toBe(expected); }); }); describe('when view name contain IDs lookalikes', () => { test.each([ ['/new/reports/summary/uundefined', '/new/reports/summary/uundefined'], ['/new/reports/nulll/summary', '/new/reports/nulll/summary'], ['/new/reports/feature2.0/summary', '/new/reports/feature2.0/summary'], ])('does nothing (%s -> %s)', (viewName, expected) => { expect(subject(viewName)).toBe(expected); }); }); describe('when view name contains "#"', () => { test('removes "#"', () => { expect(subject('#/new/reports')).toBe('/new/reports'); }); }); describe('when view name contains IDs and/or /proxy prefix', () => { test.each([ ['/proxyCalls/tenantName', '/calls'], ['/proxyCalls/chat/123/321/tenantName', '/calls/chat/{id}/{id}'], ])( 'replaces IDs with placeholders and removes /proxy and /tenantName (%s -> %s)', (viewName, expected) => { expect(subject(viewName)).toBe(expected); } ); }); describe('when view name contains empty segments', () => { test.each([ ['/new/reports/123/', '/new/reports/{id}'], ['/new/reports/123//', '/new/reports/{id}'], ['/', '/'], ['///', '/'], ['//new///reports//123//', '/new/reports/{id}'], ])('removes duplicate "/" (%s -> %s)', (viewName, expected) => { expect(subject(viewName)).toBe(expected); }); }); describe('when view name is invalid', () => { test("doesn't throw an error", () => { jest.spyOn(console, 'error').mockImplementation(jest.fn()); // suppress error output // @ts-expect-error because number is not a valid argument expect(subject(1)).toBe(1); }); }); });