Add aliases for shlink-web-component and shlink-frontend-kit packages

This commit is contained in:
Alejandro Celaya
2023-08-04 22:59:33 +02:00
parent 9f2b0f7c6b
commit 93048e3327
93 changed files with 215 additions and 143 deletions

View File

@@ -0,0 +1,72 @@
import { render, screen } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';
import { createMemoryHistory } from 'history';
import { Router } from 'react-router-dom';
import type { MainProps } from '../src/Main';
import { Main as createMain } from '../src/Main';
import { FeaturesProvider } from '../src/utils/features';
type SetUpOptions = {
currentPath: string
createNotFound?: MainProps['createNotFound'];
domainVisitsSupported?: boolean;
};
describe('<Main />', () => {
const Main = createMain(
() => <>TagsList</>,
() => <>ShortUrlsList</>,
() => <>CreateShortUrl</>,
() => <>ShortUrlVisits</>,
() => <>TagVisits</>,
() => <>DomainVisits</>,
() => <>OrphanVisits</>,
() => <>NonOrphanVisits</>,
() => <>OverviewRoute</>,
() => <>EditShortUrl</>,
() => <>ManageDomains</>,
);
const setUp = ({ createNotFound, currentPath, domainVisitsSupported = true }: SetUpOptions) => {
const history = createMemoryHistory();
history.push(currentPath);
return render(
<Router location={history.location} navigator={history}>
<FeaturesProvider value={fromPartial({ domainVisits: domainVisitsSupported })}>
<Main createNotFound={createNotFound} />
</FeaturesProvider>
</Router>,
);
};
it.each([
['/overview', 'OverviewRoute'],
['/list-short-urls/1', 'ShortUrlsList'],
['/create-short-url', 'CreateShortUrl'],
['/short-code/abc123/visits/foo', 'ShortUrlVisits'],
['/short-code/abc123/edit', 'EditShortUrl'],
['/tag/foo/visits/foo', 'TagVisits'],
['/orphan-visits/foo', 'OrphanVisits'],
['/manage-tags', 'TagsList'],
['/domain/domain.com/visits/foo', 'DomainVisits'],
['/non-orphan-visits/foo', 'NonOrphanVisits'],
['/manage-domains', 'ManageDomains'],
])(
'renders expected component based on location and server version',
(currentPath, expectedContent) => {
setUp({ currentPath });
expect(screen.getByText(expectedContent)).toBeInTheDocument();
},
);
it.each([
['/domain/domain.com/visits/foo', false],
['/foo/bar/baz', true],
])('renders not-found when trying to navigate to invalid route', (currentPath, domainVisitsSupported) => {
const createNotFound = () => <>Oops! Route not found.</>;
setUp({ currentPath, domainVisitsSupported, createNotFound });
expect(screen.getByText('Oops! Route not found.')).toBeInTheDocument();
});
});

View File

@@ -1,5 +1,5 @@
import { useToggle } from '@shlinkio/shlink-frontend-kit';
import type { FC, ReactElement } from 'react';
import { useToggle } from '../../../shlink-frontend-kit/src';
interface RenderModalArgs {
isOpen: boolean;

View File

@@ -1,5 +1,5 @@
import { DropdownBtn } from '@shlinkio/shlink-frontend-kit';
import { screen, waitFor } from '@testing-library/react';
import { DropdownBtn } from '../../../../shlink-frontend-kit/src';
import { DateIntervalDropdownItems } from '../../../src/utils/dates/DateIntervalDropdownItems';
import type { DateInterval } from '../../../src/utils/dates/helpers/dateIntervals';
import { DATE_INTERVALS, rangeOrIntervalToString } from '../../../src/utils/dates/helpers/dateIntervals';

View File

@@ -1,25 +0,0 @@
import { parseQuery, stringifyQuery } from '../../../src/utils/helpers/query';
describe('query', () => {
describe('parseQuery', () => {
it.each([
['', {}],
['foo=bar', { foo: 'bar' }],
['?foo=bar', { foo: 'bar' }],
['?foo=bar&baz=123', { foo: 'bar', baz: '123' }],
])('parses query string as expected', (queryString, expectedResult) => {
expect(parseQuery(queryString)).toEqual(expectedResult);
});
});
describe('stringifyQuery', () => {
it.each([
[{}, ''],
[{ foo: 'bar' }, 'foo=bar'],
[{ foo: 'bar', baz: '123' }, 'foo=bar&baz=123'],
[{ bar: 'foo', list: ['one', 'two'] }, encodeURI('bar=foo&list[]=one&list[]=two')],
])('stringifies query as expected', (queryObj, expectedResult) => {
expect(stringifyQuery(queryObj)).toEqual(expectedResult);
});
});
});

View File

@@ -1,5 +1,5 @@
import type { OrderDir } from '@shlinkio/shlink-frontend-kit';
import { render } from '@testing-library/react';
import type { OrderDir } from '../../../../shlink-frontend-kit/src';
import { TableOrderIcon } from '../../../src/utils/table/TableOrderIcon';
describe('<TableOrderIcon />', () => {