diff --git a/src/api/services/ShlinkApiClient.ts b/src/api/services/ShlinkApiClient.ts index 2087b6b6..315be26b 100644 --- a/src/api/services/ShlinkApiClient.ts +++ b/src/api/services/ShlinkApiClient.ts @@ -1,4 +1,3 @@ -import qs from 'qs'; import { isEmpty, isNil, reject } from 'ramda'; import { AxiosInstance, AxiosResponse, Method } from 'axios'; import { ShortUrlsListParams } from '../../short-urls/reducers/shortUrlsListParams'; @@ -19,6 +18,7 @@ import { ShlinkEditDomainRedirects, ShlinkDomainRedirects, } from '../types'; +import { stringifyQuery } from '../../utils/helpers/query'; const buildShlinkBaseUrl = (url: string, apiVersion: number) => url ? `${url}/rest/v${apiVersion}` : ''; const rejectNilProps = reject(isNil); @@ -123,7 +123,7 @@ export default class ShlinkApiClient { headers: { 'X-Api-Key': this.apiKey }, params: rejectNilProps(query), data: body, - paramsSerializer: (params) => qs.stringify(params, { arrayFormat: 'brackets' }), + paramsSerializer: stringifyQuery, }); } catch (e) { const { response } = e; diff --git a/test/domains/DomainSelector.test.tsx b/test/domains/DomainSelector.test.tsx index ec9ae9d6..0e6b211d 100644 --- a/test/domains/DomainSelector.test.tsx +++ b/test/domains/DomainSelector.test.tsx @@ -10,28 +10,40 @@ describe('', () => { let wrapper: ShallowWrapper; const domainsList = Mock.of({ domains: [ + Mock.of({ domain: 'default.com', isDefault: true }), Mock.of({ domain: 'foo.com' }), Mock.of({ domain: 'bar.com' }), ], }); + const createWrapper = (value = '') => { + wrapper = shallow( + , + ); - beforeEach(() => { - wrapper = shallow(); - }); + return wrapper; + }; afterEach(jest.clearAllMocks); afterEach(() => wrapper.unmount()); - it('shows dropdown by default', () => { + it.each([ + [ '', 'Domain', 'domains-dropdown__toggle-btn' ], + [ 'my-domain.com', 'Domain: my-domain.com', 'domains-dropdown__toggle-btn--active' ], + ])('shows dropdown by default', (value, expectedText, expectedClassName) => { + const wrapper = createWrapper(value); const input = wrapper.find(InputGroup); const dropdown = wrapper.find(DropdownBtn); expect(input).toHaveLength(0); expect(dropdown).toHaveLength(1); - expect(dropdown.find(DropdownItem)).toHaveLength(4); + expect(dropdown.find(DropdownItem)).toHaveLength(5); + expect(dropdown.prop('text')).toEqual(expectedText); + expect(dropdown.prop('className')).toEqual(expectedClassName); }); - it('allows to toggle between dropdown and input', () => { + it('allows toggling between dropdown and input', () => { + const wrapper = createWrapper(); + wrapper.find(DropdownItem).last().simulate('click'); expect(wrapper.find(InputGroup)).toHaveLength(1); expect(wrapper.find(DropdownBtn)).toHaveLength(0); @@ -40,4 +52,14 @@ describe('', () => { expect(wrapper.find(InputGroup)).toHaveLength(0); expect(wrapper.find(DropdownBtn)).toHaveLength(1); }); + + it.each([ + [ 0, 'default.comdefault' ], + [ 1, 'foo.com' ], + [ 2, 'bar.com' ], + ])('shows expected content on every item', (index, expectedContent) => { + const item = createWrapper().find(DropdownItem).at(index); + + expect(item.html()).toContain(expectedContent); + }); }); diff --git a/test/visits/reducers/visitsOverview.test.ts b/test/visits/reducers/visitsOverview.test.ts index 49c1a125..64dd2af6 100644 --- a/test/visits/reducers/visitsOverview.test.ts +++ b/test/visits/reducers/visitsOverview.test.ts @@ -43,9 +43,13 @@ describe('visitsOverviewReducer', () => { expect(visitsCount).toEqual(100); }); - it('returns updated amounts on CREATE_VISITS', () => { + it.each([ + [ 50, 53 ], + [ 0, 3 ], + [ undefined, 3 ], + ])('returns updated amounts on CREATE_VISITS', (providedOrphanVisitsCount, expectedOrphanVisitsCount) => { const { visitsCount, orphanVisitsCount } = reducer( - state({ visitsCount: 100, orphanVisitsCount: 50 }), + state({ visitsCount: 100, orphanVisitsCount: providedOrphanVisitsCount }), { type: CREATE_VISITS, createdVisits: [ @@ -65,7 +69,7 @@ describe('visitsOverviewReducer', () => { ); expect(visitsCount).toEqual(102); - expect(orphanVisitsCount).toEqual(53); + expect(orphanVisitsCount).toEqual(expectedOrphanVisitsCount); }); });