Move shlink-web-component tests to their own folder

This commit is contained in:
Alejandro Celaya
2023-08-02 09:01:44 +02:00
parent c48facc863
commit c794ff8b58
124 changed files with 455 additions and 371 deletions

View File

@@ -1,22 +0,0 @@
import { render, screen } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';
import { MemoryRouter } from 'react-router';
import { AsideMenu } from '../../shlink-web-component/src/common/AsideMenu';
describe('<AsideMenu />', () => {
const setUp = () => render(
<MemoryRouter>
<AsideMenu selectedServer={fromPartial({ id: 'abc123', version: '2.8.0' })} />
</MemoryRouter>,
);
it('contains links to different sections', () => {
setUp();
const links = screen.getAllByRole('link');
expect.assertions(links.length + 1);
expect(links).toHaveLength(5);
links.forEach((link) => expect(link.getAttribute('href')).toContain('abc123'));
});
});

View File

@@ -1,24 +0,0 @@
import { fromPartial } from '@total-typescript/shoehorn';
import { ImageDownloader } from '../../../shlink-web-component/src/utils/services/ImageDownloader';
import type { HttpClient } from '../../../src/common/services/HttpClient';
import { windowMock } from '../../__mocks__/Window.mock';
describe('ImageDownloader', () => {
const fetchBlob = vi.fn();
const httpClient = fromPartial<HttpClient>({ fetchBlob });
let imageDownloader: ImageDownloader;
beforeEach(() => {
(global as any).URL = { createObjectURL: () => '' };
imageDownloader = new ImageDownloader(httpClient, windowMock);
});
it('calls URL with response type blob', async () => {
fetchBlob.mockResolvedValue(new Blob());
await imageDownloader.saveImage('/foo/bar.png', 'my-image.png');
expect(fetchBlob).toHaveBeenCalledWith('/foo/bar.png');
});
});

View File

@@ -1,70 +0,0 @@
import type { ExportableShortUrl } from '../../../shlink-web-component/src/short-urls/data';
import { ReportExporter } from '../../../shlink-web-component/src/utils/services/ReportExporter';
import type { NormalizedVisit } from '../../../shlink-web-component/src/visits/types';
import { windowMock } from '../../__mocks__/Window.mock';
describe('ReportExporter', () => {
const jsonToCsv = vi.fn();
let exporter: ReportExporter;
beforeEach(() => {
(global as any).Blob = class Blob {};
(global as any).URL = { createObjectURL: () => '' };
exporter = new ReportExporter(windowMock, jsonToCsv);
});
describe('exportVisits', () => {
it('parses provided visits to CSV', () => {
const visits: NormalizedVisit[] = [
{
browser: 'browser',
city: 'city',
country: 'country',
date: 'date',
latitude: 0,
longitude: 0,
os: 'os',
referer: 'referer',
potentialBot: false,
},
];
exporter.exportVisits('my_visits.csv', visits);
expect(jsonToCsv).toHaveBeenCalledWith(visits);
});
it('skips execution when list of visits is empty', () => {
exporter.exportVisits('my_visits.csv', []);
expect(jsonToCsv).not.toHaveBeenCalled();
});
});
describe('exportShortUrls', () => {
it('parses provided short URLs to CSV', () => {
const shortUrls: ExportableShortUrl[] = [
{
shortUrl: 'shortUrl',
visits: 10,
title: '',
createdAt: '',
longUrl: '',
tags: '',
shortCode: '',
},
];
exporter.exportShortUrls(shortUrls);
expect(jsonToCsv).toHaveBeenCalledWith(shortUrls);
});
it('skips execution when list of visits is empty', () => {
exporter.exportShortUrls([]);
expect(jsonToCsv).not.toHaveBeenCalled();
});
});
});