2022-05-06 21:25:48 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2023-04-13 22:48:29 +03:00
|
|
|
import { fromPartial } from '@total-typescript/shoehorn';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { ShlinkVersionsProps } from '../../src/common/ShlinkVersions';
|
|
|
|
import { ShlinkVersions } from '../../src/common/ShlinkVersions';
|
|
|
|
import type { NonReachableServer, NotFoundServer, ReachableServer } from '../../src/servers/data';
|
2020-08-28 21:05:01 +03:00
|
|
|
|
|
|
|
describe('<ShlinkVersions />', () => {
|
2022-05-06 21:25:48 +03:00
|
|
|
const setUp = (props: ShlinkVersionsProps) => render(<ShlinkVersions {...props} />);
|
2020-08-28 21:05:01 +03:00
|
|
|
|
|
|
|
it.each([
|
2023-04-13 22:48:29 +03:00
|
|
|
['1.2.3', fromPartial<ReachableServer>({ version: '1.0.0', printableVersion: 'foo' }), 'v1.2.3', 'foo'],
|
|
|
|
['foo', fromPartial<ReachableServer>({ version: '1.0.0', printableVersion: '1.2.3' }), 'latest', '1.2.3'],
|
|
|
|
['latest', fromPartial<ReachableServer>({ version: '1.0.0', printableVersion: 'latest' }), 'latest', 'latest'],
|
|
|
|
['5.5.0', fromPartial<ReachableServer>({ version: '1.0.0', printableVersion: '0.2.8' }), 'v5.5.0', '0.2.8'],
|
|
|
|
['not-semver', fromPartial<ReachableServer>({ version: '1.0.0', printableVersion: 'some' }), 'latest', 'some'],
|
2020-08-28 21:05:01 +03:00
|
|
|
])(
|
|
|
|
'displays expected versions when selected server is reachable',
|
|
|
|
(clientVersion, selectedServer, expectedClientVersion, expectedServerVersion) => {
|
2022-05-06 21:25:48 +03:00
|
|
|
setUp({ clientVersion, selectedServer });
|
|
|
|
const [serverLink, clientLink] = screen.getAllByRole('link');
|
2020-08-28 21:05:01 +03:00
|
|
|
|
2022-05-06 21:25:48 +03:00
|
|
|
expect(serverLink).toHaveAttribute(
|
|
|
|
'href',
|
|
|
|
`https://github.com/shlinkio/shlink/releases/${expectedServerVersion}`,
|
|
|
|
);
|
|
|
|
expect(serverLink).toHaveTextContent(expectedServerVersion);
|
|
|
|
expect(clientLink).toHaveAttribute(
|
|
|
|
'href',
|
|
|
|
`https://github.com/shlinkio/shlink-web-client/releases/${expectedClientVersion}`,
|
|
|
|
);
|
|
|
|
expect(clientLink).toHaveTextContent(expectedClientVersion);
|
2020-08-28 21:05:01 +03:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
['1.2.3', null],
|
2023-04-13 22:48:29 +03:00
|
|
|
['1.2.3', fromPartial<NotFoundServer>({ serverNotFound: true })],
|
|
|
|
['1.2.3', fromPartial<NonReachableServer>({ serverNotReachable: true })],
|
2020-08-28 21:05:01 +03:00
|
|
|
])('displays only client version when selected server is not reachable', (clientVersion, selectedServer) => {
|
2022-05-06 21:25:48 +03:00
|
|
|
setUp({ clientVersion, selectedServer });
|
|
|
|
const links = screen.getAllByRole('link');
|
2020-08-28 21:05:01 +03:00
|
|
|
|
|
|
|
expect(links).toHaveLength(1);
|
2022-05-06 21:25:48 +03:00
|
|
|
expect(links[0]).toHaveAttribute('href', 'https://github.com/shlinkio/shlink-web-client/releases/v1.2.3');
|
2020-08-28 21:05:01 +03:00
|
|
|
});
|
|
|
|
});
|