Updated to airbnb coding styles

This commit is contained in:
Alejandro Celaya
2022-03-26 12:17:42 +01:00
parent 4e9b19afd1
commit a2df486280
239 changed files with 2210 additions and 3549 deletions

View File

@@ -4,19 +4,19 @@ import { ShlinkApiError, ShlinkApiErrorProps } from '../../src/api/ShlinkApiErro
import { InvalidArgumentError, ProblemDetailsError } from '../../src/api/types';
describe('<ShlinkApiError />', () => {
let wrapper: ShallowWrapper;
let commonWrapper: ShallowWrapper;
const createWrapper = (props: ShlinkApiErrorProps) => {
wrapper = shallow(<ShlinkApiError {...props} />);
commonWrapper = shallow(<ShlinkApiError {...props} />);
return wrapper;
return commonWrapper;
};
afterEach(() => wrapper?.unmount());
afterEach(() => commonWrapper?.unmount());
it.each([
[ undefined, 'the fallback', 'the fallback' ],
[ Mock.all<ProblemDetailsError>(), 'the fallback', 'the fallback' ],
[ Mock.of<ProblemDetailsError>({ detail: 'the detail' }), 'the fallback', 'the detail' ],
[undefined, 'the fallback', 'the fallback'],
[Mock.all<ProblemDetailsError>(), 'the fallback', 'the fallback'],
[Mock.of<ProblemDetailsError>({ detail: 'the detail' }), 'the fallback', 'the detail'],
])('renders proper message', (errorData, fallbackMessage, expectedMessage) => {
const wrapper = createWrapper({ errorData, fallbackMessage });
@@ -24,9 +24,9 @@ describe('<ShlinkApiError />', () => {
});
it.each([
[ undefined, 0 ],
[ Mock.all<ProblemDetailsError>(), 0 ],
[ Mock.of<InvalidArgumentError>({ type: 'INVALID_ARGUMENT', invalidElements: [] }), 1 ],
[undefined, 0],
[Mock.all<ProblemDetailsError>(), 0],
[Mock.of<InvalidArgumentError>({ type: 'INVALID_ARGUMENT', invalidElements: [] }), 1],
])('renders list of invalid elements when provided error is an InvalidError', (errorData, expectedElementsCount) => {
const wrapper = createWrapper({ errorData });
const p = wrapper.find('p');

View File

@@ -11,13 +11,13 @@ describe('ShlinkApiClient', () => {
const createAxiosMock = (data: AxiosRequestConfig = {}) => jest.fn(createAxios(data)) as unknown as AxiosInstance;
const createApiClient = (data: AxiosRequestConfig) => new ShlinkApiClient(createAxios(data), '', '');
const shortCodesWithDomainCombinations: [ string, OptionalString ][] = [
[ 'abc123', null ],
[ 'abc123', undefined ],
[ 'abc123', 'example.com' ],
['abc123', null],
['abc123', undefined],
['abc123', 'example.com'],
];
describe('listShortUrls', () => {
const expectedList = [ 'foo', 'bar' ];
const expectedList = ['foo', 'bar'];
it('properly returns short URLs list', async () => {
const { listShortUrls } = createApiClient({
@@ -32,9 +32,9 @@ describe('ShlinkApiClient', () => {
});
it.each([
[ { field: 'visits', dir: 'DESC' } as ShortUrlsOrder, 'visits-DESC' ],
[ { field: 'longUrl', dir: 'ASC' } as ShortUrlsOrder, 'longUrl-ASC' ],
[ { field: 'longUrl', dir: undefined } as ShortUrlsOrder, undefined ],
[{ field: 'visits', dir: 'DESC' } as ShortUrlsOrder, 'visits-DESC'],
[{ field: 'longUrl', dir: 'ASC' } as ShortUrlsOrder, 'longUrl-ASC'],
[{ field: 'longUrl', dir: undefined } as ShortUrlsOrder, undefined],
])('parses orderBy in params', async (orderBy, expectedOrderBy) => {
const axiosSpy = createAxiosMock({
data: expectedList,
@@ -73,7 +73,7 @@ describe('ShlinkApiClient', () => {
describe('getShortUrlVisits', () => {
it('properly returns short URL visits', async () => {
const expectedVisits = [ 'foo', 'bar' ];
const expectedVisits = ['foo', 'bar'];
const axiosSpy = createAxiosMock({
data: {
visits: {
@@ -95,7 +95,7 @@ describe('ShlinkApiClient', () => {
describe('getTagVisits', () => {
it('properly returns tag visits', async () => {
const expectedVisits = [ 'foo', 'bar' ];
const expectedVisits = ['foo', 'bar'];
const axiosSpy = createAxiosMock({
data: {
visits: {
@@ -136,7 +136,7 @@ describe('ShlinkApiClient', () => {
describe('updateShortUrlTags', () => {
it.each(shortCodesWithDomainCombinations)('properly updates short URL tags', async (shortCode, domain) => {
const expectedTags = [ 'foo', 'bar' ];
const expectedTags = ['foo', 'bar'];
const axiosSpy = createAxiosMock({
data: { tags: expectedTags },
});
@@ -176,7 +176,7 @@ describe('ShlinkApiClient', () => {
describe('listTags', () => {
it('properly returns list of tags', async () => {
const expectedTags = [ 'foo', 'bar' ];
const expectedTags = ['foo', 'bar'];
const axiosSpy = createAxiosMock({
data: {
tags: { data: expectedTags },
@@ -193,7 +193,7 @@ describe('ShlinkApiClient', () => {
describe('deleteTags', () => {
it('properly deletes provided tags', async () => {
const tags = [ 'foo', 'bar' ];
const tags = ['foo', 'bar'];
const axiosSpy = createAxiosMock();
const { deleteTags } = new ShlinkApiClient(axiosSpy, '', '');
@@ -273,7 +273,7 @@ describe('ShlinkApiClient', () => {
describe('listDomains', () => {
it('returns domains', async () => {
const expectedData = { data: [ Mock.all<ShlinkDomain>(), Mock.all<ShlinkDomain>() ] };
const expectedData = { data: [Mock.all<ShlinkDomain>(), Mock.all<ShlinkDomain>()] };
const resp = { domains: expectedData };
const axiosSpy = createAxiosMock({ data: resp });
const { listDomains } = new ShlinkApiClient(axiosSpy, '', '');

View File

@@ -16,7 +16,7 @@ describe('ShlinkApiClientBuilder', () => {
it('creates new instances when provided params are different', async () => {
const builder = createBuilder();
const [ firstApiClient, secondApiClient, thirdApiClient ] = await Promise.all([
const [firstApiClient, secondApiClient, thirdApiClient] = await Promise.all([
builder(server({ url: 'foo', apiKey: 'bar' })),
builder(server({ url: 'bar', apiKey: 'bar' })),
builder(server({ url: 'bar', apiKey: 'foo' })),
@@ -30,7 +30,7 @@ describe('ShlinkApiClientBuilder', () => {
it('returns existing instances when provided params are the same', async () => {
const builder = createBuilder();
const selectedServer = server({ url: 'foo', apiKey: 'bar' });
const [ firstApiClient, secondApiClient, thirdApiClient ] = await Promise.all([
const [firstApiClient, secondApiClient, thirdApiClient] = await Promise.all([
builder(selectedServer),
builder(selectedServer),
builder(selectedServer),