Enhanced ReportExporter test

This commit is contained in:
Alejandro Celaya 2022-03-13 19:07:33 +01:00
parent 92ddcad753
commit e44520b2c2
3 changed files with 29 additions and 5 deletions

View file

@ -28,6 +28,6 @@
.search-field__close { .search-field__close {
@include vertical-align(); @include vertical-align();
right: 15px; right: 10px;
cursor: pointer; cursor: pointer;
} }

View file

@ -47,13 +47,11 @@ const SearchField = ({ onChange, className, large = true, noBorder = false, init
/> />
<FontAwesomeIcon icon={searchIcon} className="search-field__icon" /> <FontAwesomeIcon icon={searchIcon} className="search-field__icon" />
<div <div
className="close search-field__close" className="close search-field__close btn-close"
hidden={searchTerm === ''} hidden={searchTerm === ''}
id="search-field__close" id="search-field__close"
onClick={() => searchTermChanged('', 0)} onClick={() => searchTermChanged('', 0)}
> />
&times;
</div>
</div> </div>
); );
}; };

View file

@ -3,6 +3,7 @@ import { CsvJson } from 'csvjson';
import { ReportExporter } from '../../../src/common/services/ReportExporter'; import { ReportExporter } from '../../../src/common/services/ReportExporter';
import { NormalizedVisit } from '../../../src/visits/types'; import { NormalizedVisit } from '../../../src/visits/types';
import { windowMock } from '../../mocks/WindowMock'; import { windowMock } from '../../mocks/WindowMock';
import { ExportableShortUrl } from '../../../src/short-urls/data';
describe('ReportExporter', () => { describe('ReportExporter', () => {
const toCSV = jest.fn(); const toCSV = jest.fn();
@ -44,4 +45,29 @@ describe('ReportExporter', () => {
expect(toCSV).not.toHaveBeenCalled(); 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();
});
});
}); });