From e44520b2c2f54e8c0992596268dda89a4ce3339a Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 13 Mar 2022 19:07:33 +0100 Subject: [PATCH] Enhanced ReportExporter test --- src/utils/SearchField.scss | 2 +- src/utils/SearchField.tsx | 6 ++--- test/common/services/ReportExporter.test.ts | 26 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/utils/SearchField.scss b/src/utils/SearchField.scss index 5877b9ce..513844b4 100644 --- a/src/utils/SearchField.scss +++ b/src/utils/SearchField.scss @@ -28,6 +28,6 @@ .search-field__close { @include vertical-align(); - right: 15px; + right: 10px; cursor: pointer; } diff --git a/src/utils/SearchField.tsx b/src/utils/SearchField.tsx index e76fa1ee..e3997e83 100644 --- a/src/utils/SearchField.tsx +++ b/src/utils/SearchField.tsx @@ -47,13 +47,11 @@ const SearchField = ({ onChange, className, large = true, noBorder = false, init /> + /> ); }; diff --git a/test/common/services/ReportExporter.test.ts b/test/common/services/ReportExporter.test.ts index f8848bc3..300a2168 100644 --- a/test/common/services/ReportExporter.test.ts +++ b/test/common/services/ReportExporter.test.ts @@ -3,6 +3,7 @@ import { CsvJson } from 'csvjson'; import { ReportExporter } from '../../../src/common/services/ReportExporter'; import { NormalizedVisit } from '../../../src/visits/types'; import { windowMock } from '../../mocks/WindowMock'; +import { ExportableShortUrl } from '../../../src/short-urls/data'; describe('ReportExporter', () => { const toCSV = jest.fn(); @@ -44,4 +45,29 @@ describe('ReportExporter', () => { expect(toCSV).not.toHaveBeenCalled(); }); }); + + describe('exportShortUrls', () => { + it('parses provided short URLs to CSV', () => { + const shortUrls: ExportableShortUrl[] = [ + { + shortUrl: 'shortUrl', + visits: 10, + title: '', + createdAt: '', + longUrl: '', + tags: '', + }, + ]; + + exporter.exportShortUrls(shortUrls); + + expect(toCSV).toHaveBeenCalledWith(shortUrls, { headers: 'key', wrap: true }); + }); + + it('skips execution when list of visits is empty', () => { + exporter.exportShortUrls([]); + + expect(toCSV).not.toHaveBeenCalled(); + }); + }); });