From 83150331e5bf4f54d56c6dbb071ac25aa49c82df Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 10 Jul 2022 19:44:49 +0200 Subject: [PATCH 1/6] Renamed test helpers folder --- test/{__mocks__ => __helpers__}/setUpTest.ts | 0 test/common/AppUpdateBanner.test.tsx | 2 +- test/common/ErrorHandler.test.tsx | 2 +- test/common/MainHeader.test.tsx | 2 +- test/domains/DomainSelector.test.tsx | 2 +- test/domains/ManageDomains.test.tsx | 2 +- test/domains/helpers/DomainDropdown.test.tsx | 2 +- test/domains/helpers/DomainStatusIcon.test.tsx | 2 +- test/domains/helpers/EditDomainRedirectsModal.test.tsx | 2 +- test/servers/CreateServer.test.tsx | 2 +- test/servers/DeleteServerButton.test.tsx | 2 +- test/servers/DeleteServerModal.test.tsx | 2 +- test/servers/EditServer.test.tsx | 2 +- test/servers/ManageServers.test.tsx | 2 +- test/servers/ManageServersRowDropdown.test.tsx | 2 +- test/servers/ServersDropdown.test.tsx | 2 +- test/servers/helpers/DuplicatedServersModal.test.tsx | 2 +- test/servers/helpers/ImportServersBtn.test.tsx | 2 +- test/settings/RealTimeUpdatesSettings.test.tsx | 2 +- test/settings/ShortUrlCreationSettings.test.tsx | 2 +- test/settings/ShortUrlsListSettings.test.tsx | 2 +- test/settings/TagsSettings.test.tsx | 2 +- test/settings/UserInterfaceSettings.test.tsx | 2 +- test/settings/VisitsSettings.test.tsx | 2 +- test/short-urls/ShortUrlForm.test.tsx | 2 +- test/short-urls/ShortUrlsFilteringBar.test.tsx | 2 +- test/short-urls/ShortUrlsList.test.tsx | 2 +- test/short-urls/ShortUrlsTable.test.tsx | 2 +- test/short-urls/UseExistingIfFoundInfoIcon.test.tsx | 2 +- test/short-urls/helpers/CreateShortUrlResult.test.tsx | 2 +- test/short-urls/helpers/ExportShortUrlsBtn.test.tsx | 2 +- .../helpers/qr-codes/QrErrorCorrectionDropdown.test.tsx | 2 +- test/short-urls/helpers/qr-codes/QrFormatDropdown.test.tsx | 2 +- test/tags/TagCard.test.tsx | 2 +- test/tags/TagsCards.test.tsx | 2 +- test/tags/TagsList.test.tsx | 2 +- test/tags/TagsModeDropdown.test.tsx | 2 +- test/tags/helpers/DeleteTagConfirmModal.test.tsx | 2 +- test/tags/helpers/Tag.test.tsx | 2 +- test/utils/Checkbox.test.tsx | 2 +- test/utils/CopyToClipboardIcon.test.tsx | 2 +- test/utils/DateInput.test.tsx | 2 +- test/utils/InfoTooltip.test.tsx | 2 +- test/utils/OrderingDropdown.test.tsx | 2 +- test/utils/dates/DateIntervalDropdownItems.test.tsx | 2 +- test/utils/dates/DateIntervalSelector.test.tsx | 2 +- test/visits/DomainVisits.test.tsx | 2 +- test/visits/NonOrphanVisits.test.tsx | 2 +- test/visits/OrphanVisits.test.tsx | 2 +- test/visits/ShortUrlVisits.test.tsx | 2 +- test/visits/ShortUrlVisitsHeader.test.tsx | 2 +- test/visits/TagVisits.test.tsx | 2 +- test/visits/charts/DoughnutChart.test.tsx | 2 +- test/visits/charts/HorizontalBarChart.test.tsx | 2 +- test/visits/charts/LineChartCard.test.tsx | 2 +- test/visits/helpers/OpenMapModalBtn.test.tsx | 2 +- test/visits/helpers/VisitsFilterDropdown.test.tsx | 2 +- 57 files changed, 56 insertions(+), 56 deletions(-) rename test/{__mocks__ => __helpers__}/setUpTest.ts (100%) diff --git a/test/__mocks__/setUpTest.ts b/test/__helpers__/setUpTest.ts similarity index 100% rename from test/__mocks__/setUpTest.ts rename to test/__helpers__/setUpTest.ts diff --git a/test/common/AppUpdateBanner.test.tsx b/test/common/AppUpdateBanner.test.tsx index 0dfa0e14..4dfcd207 100644 --- a/test/common/AppUpdateBanner.test.tsx +++ b/test/common/AppUpdateBanner.test.tsx @@ -1,6 +1,6 @@ import { screen } from '@testing-library/react'; import { AppUpdateBanner } from '../../src/common/AppUpdateBanner'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const toggle = jest.fn(); diff --git a/test/common/ErrorHandler.test.tsx b/test/common/ErrorHandler.test.tsx index c924e137..67d271c4 100644 --- a/test/common/ErrorHandler.test.tsx +++ b/test/common/ErrorHandler.test.tsx @@ -1,7 +1,7 @@ import { render, screen } from '@testing-library/react'; import { Mock } from 'ts-mockery'; import { ErrorHandler as createErrorHandler } from '../../src/common/ErrorHandler'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; const ComponentWithError = () => { throw new Error('Error!!'); diff --git a/test/common/MainHeader.test.tsx b/test/common/MainHeader.test.tsx index c29d3c63..e3187c7e 100644 --- a/test/common/MainHeader.test.tsx +++ b/test/common/MainHeader.test.tsx @@ -2,7 +2,7 @@ import { screen, waitFor } from '@testing-library/react'; import { Router } from 'react-router-dom'; import { createMemoryHistory } from 'history'; import { MainHeader as createMainHeader } from '../../src/common/MainHeader'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const MainHeader = createMainHeader(() => <>ServersDropdown); diff --git a/test/domains/DomainSelector.test.tsx b/test/domains/DomainSelector.test.tsx index 7ae03403..e2effdf4 100644 --- a/test/domains/DomainSelector.test.tsx +++ b/test/domains/DomainSelector.test.tsx @@ -3,7 +3,7 @@ import { Mock } from 'ts-mockery'; import { DomainSelector } from '../../src/domains/DomainSelector'; import { DomainsList } from '../../src/domains/reducers/domainsList'; import { ShlinkDomain } from '../../src/api/types'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const domainsList = Mock.of({ diff --git a/test/domains/ManageDomains.test.tsx b/test/domains/ManageDomains.test.tsx index 55415c29..509ee2c7 100644 --- a/test/domains/ManageDomains.test.tsx +++ b/test/domains/ManageDomains.test.tsx @@ -4,7 +4,7 @@ import { DomainsList } from '../../src/domains/reducers/domainsList'; import { ManageDomains } from '../../src/domains/ManageDomains'; import { ProblemDetailsError, ShlinkDomain } from '../../src/api/types'; import { SelectedServer } from '../../src/servers/data'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const listDomains = jest.fn(); diff --git a/test/domains/helpers/DomainDropdown.test.tsx b/test/domains/helpers/DomainDropdown.test.tsx index 09f2f05c..90b5658b 100644 --- a/test/domains/helpers/DomainDropdown.test.tsx +++ b/test/domains/helpers/DomainDropdown.test.tsx @@ -5,7 +5,7 @@ import { DomainDropdown } from '../../../src/domains/helpers/DomainDropdown'; import { Domain } from '../../../src/domains/data'; import { ReachableServer, SelectedServer } from '../../../src/servers/data'; import { SemVer } from '../../../src/utils/helpers/version'; -import { renderWithEvents } from '../../__mocks__/setUpTest'; +import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { const editDomainRedirects = jest.fn().mockResolvedValue(undefined); diff --git a/test/domains/helpers/DomainStatusIcon.test.tsx b/test/domains/helpers/DomainStatusIcon.test.tsx index e7bc6946..a95ab027 100644 --- a/test/domains/helpers/DomainStatusIcon.test.tsx +++ b/test/domains/helpers/DomainStatusIcon.test.tsx @@ -2,7 +2,7 @@ import { screen } from '@testing-library/react'; import { Mock } from 'ts-mockery'; import { DomainStatus } from '../../../src/domains/data'; import { DomainStatusIcon } from '../../../src/domains/helpers/DomainStatusIcon'; -import { renderWithEvents } from '../../__mocks__/setUpTest'; +import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { const matchMedia = jest.fn().mockReturnValue(Mock.of({ matches: false })); diff --git a/test/domains/helpers/EditDomainRedirectsModal.test.tsx b/test/domains/helpers/EditDomainRedirectsModal.test.tsx index 1b8753f4..6f402350 100644 --- a/test/domains/helpers/EditDomainRedirectsModal.test.tsx +++ b/test/domains/helpers/EditDomainRedirectsModal.test.tsx @@ -2,7 +2,7 @@ import { fireEvent, screen, waitFor } from '@testing-library/react'; import { Mock } from 'ts-mockery'; import { ShlinkDomain } from '../../../src/api/types'; import { EditDomainRedirectsModal } from '../../../src/domains/helpers/EditDomainRedirectsModal'; -import { renderWithEvents } from '../../__mocks__/setUpTest'; +import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { const editDomainRedirects = jest.fn().mockResolvedValue(undefined); diff --git a/test/servers/CreateServer.test.tsx b/test/servers/CreateServer.test.tsx index a12aa73e..dd559dc3 100644 --- a/test/servers/CreateServer.test.tsx +++ b/test/servers/CreateServer.test.tsx @@ -3,7 +3,7 @@ import { Mock } from 'ts-mockery'; import { useNavigate } from 'react-router-dom'; import { CreateServer as createCreateServer } from '../../src/servers/CreateServer'; import { ServerWithId } from '../../src/servers/data'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), useNavigate: jest.fn() })); diff --git a/test/servers/DeleteServerButton.test.tsx b/test/servers/DeleteServerButton.test.tsx index 3d636182..c26431e5 100644 --- a/test/servers/DeleteServerButton.test.tsx +++ b/test/servers/DeleteServerButton.test.tsx @@ -3,7 +3,7 @@ import { screen, waitFor } from '@testing-library/react'; import { Mock } from 'ts-mockery'; import { DeleteServerButton as createDeleteServerButton } from '../../src/servers/DeleteServerButton'; import { ServerWithId } from '../../src/servers/data'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const DeleteServerButton = createDeleteServerButton( diff --git a/test/servers/DeleteServerModal.test.tsx b/test/servers/DeleteServerModal.test.tsx index 4defa691..cf509b41 100644 --- a/test/servers/DeleteServerModal.test.tsx +++ b/test/servers/DeleteServerModal.test.tsx @@ -3,7 +3,7 @@ import { Mock } from 'ts-mockery'; import { useNavigate } from 'react-router-dom'; import { DeleteServerModal } from '../../src/servers/DeleteServerModal'; import { ServerWithId } from '../../src/servers/data'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), useNavigate: jest.fn() })); diff --git a/test/servers/EditServer.test.tsx b/test/servers/EditServer.test.tsx index 0ecf87ca..771a6210 100644 --- a/test/servers/EditServer.test.tsx +++ b/test/servers/EditServer.test.tsx @@ -3,7 +3,7 @@ import { Mock } from 'ts-mockery'; import { useNavigate } from 'react-router-dom'; import { EditServer as editServerConstruct } from '../../src/servers/EditServer'; import { ReachableServer, SelectedServer } from '../../src/servers/data'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), useNavigate: jest.fn() })); diff --git a/test/servers/ManageServers.test.tsx b/test/servers/ManageServers.test.tsx index 8fc19b78..520e5b4f 100644 --- a/test/servers/ManageServers.test.tsx +++ b/test/servers/ManageServers.test.tsx @@ -4,7 +4,7 @@ import { MemoryRouter } from 'react-router-dom'; import ServersExporter from '../../src/servers/services/ServersExporter'; import { ManageServers as createManageServers } from '../../src/servers/ManageServers'; import { ServersMap, ServerWithId } from '../../src/servers/data'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const exportServers = jest.fn(); diff --git a/test/servers/ManageServersRowDropdown.test.tsx b/test/servers/ManageServersRowDropdown.test.tsx index 85b544c3..043950f0 100644 --- a/test/servers/ManageServersRowDropdown.test.tsx +++ b/test/servers/ManageServersRowDropdown.test.tsx @@ -3,7 +3,7 @@ import { Mock } from 'ts-mockery'; import { MemoryRouter } from 'react-router-dom'; import { ServerWithId } from '../../src/servers/data'; import { ManageServersRowDropdown as createManageServersRowDropdown } from '../../src/servers/ManageServersRowDropdown'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const ManageServersRowDropdown = createManageServersRowDropdown( diff --git a/test/servers/ServersDropdown.test.tsx b/test/servers/ServersDropdown.test.tsx index 0f18fbf4..102cec91 100644 --- a/test/servers/ServersDropdown.test.tsx +++ b/test/servers/ServersDropdown.test.tsx @@ -4,7 +4,7 @@ import { Mock } from 'ts-mockery'; import { MemoryRouter } from 'react-router-dom'; import { ServersDropdown } from '../../src/servers/ServersDropdown'; import { ServersMap, ServerWithId } from '../../src/servers/data'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const fallbackServers: ServersMap = { diff --git a/test/servers/helpers/DuplicatedServersModal.test.tsx b/test/servers/helpers/DuplicatedServersModal.test.tsx index fe41a5b8..0441b4e5 100644 --- a/test/servers/helpers/DuplicatedServersModal.test.tsx +++ b/test/servers/helpers/DuplicatedServersModal.test.tsx @@ -2,7 +2,7 @@ import { screen } from '@testing-library/react'; import { Mock } from 'ts-mockery'; import { DuplicatedServersModal } from '../../../src/servers/helpers/DuplicatedServersModal'; import { ServerData } from '../../../src/servers/data'; -import { renderWithEvents } from '../../__mocks__/setUpTest'; +import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { const onDiscard = jest.fn(); diff --git a/test/servers/helpers/ImportServersBtn.test.tsx b/test/servers/helpers/ImportServersBtn.test.tsx index b7c49303..605270fa 100644 --- a/test/servers/helpers/ImportServersBtn.test.tsx +++ b/test/servers/helpers/ImportServersBtn.test.tsx @@ -6,7 +6,7 @@ import { } from '../../../src/servers/helpers/ImportServersBtn'; import { ServersImporter } from '../../../src/servers/services/ServersImporter'; import { ServersMap, ServerWithId } from '../../../src/servers/data'; -import { renderWithEvents } from '../../__mocks__/setUpTest'; +import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { const onImportMock = jest.fn(); diff --git a/test/settings/RealTimeUpdatesSettings.test.tsx b/test/settings/RealTimeUpdatesSettings.test.tsx index aed93bde..943f8157 100644 --- a/test/settings/RealTimeUpdatesSettings.test.tsx +++ b/test/settings/RealTimeUpdatesSettings.test.tsx @@ -5,7 +5,7 @@ import { Settings, } from '../../src/settings/reducers/settings'; import { RealTimeUpdatesSettings } from '../../src/settings/RealTimeUpdatesSettings'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const toggleRealTimeUpdates = jest.fn(); diff --git a/test/settings/ShortUrlCreationSettings.test.tsx b/test/settings/ShortUrlCreationSettings.test.tsx index 77038cbb..57ea949a 100644 --- a/test/settings/ShortUrlCreationSettings.test.tsx +++ b/test/settings/ShortUrlCreationSettings.test.tsx @@ -2,7 +2,7 @@ import { screen } from '@testing-library/react'; import { Mock } from 'ts-mockery'; import { ShortUrlCreationSettings as ShortUrlsSettings, Settings } from '../../src/settings/reducers/settings'; import { ShortUrlCreationSettings } from '../../src/settings/ShortUrlCreationSettings'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const setShortUrlCreationSettings = jest.fn(); diff --git a/test/settings/ShortUrlsListSettings.test.tsx b/test/settings/ShortUrlsListSettings.test.tsx index f396c723..53350a0e 100644 --- a/test/settings/ShortUrlsListSettings.test.tsx +++ b/test/settings/ShortUrlsListSettings.test.tsx @@ -3,7 +3,7 @@ import { Mock } from 'ts-mockery'; import { Settings, ShortUrlsListSettings as ShortUrlsSettings } from '../../src/settings/reducers/settings'; import { ShortUrlsListSettings } from '../../src/settings/ShortUrlsListSettings'; import { ShortUrlsOrder } from '../../src/short-urls/data'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const setSettings = jest.fn(); diff --git a/test/settings/TagsSettings.test.tsx b/test/settings/TagsSettings.test.tsx index c110b033..854ebf9f 100644 --- a/test/settings/TagsSettings.test.tsx +++ b/test/settings/TagsSettings.test.tsx @@ -4,7 +4,7 @@ import { Settings, TagsMode, TagsSettings as TagsSettingsOptions } from '../../s import { TagsSettings } from '../../src/settings/TagsSettings'; import { TagsOrder } from '../../src/tags/data/TagsListChildrenProps'; import { capitalize } from '../../src/utils/utils'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const setTagsSettings = jest.fn(); diff --git a/test/settings/UserInterfaceSettings.test.tsx b/test/settings/UserInterfaceSettings.test.tsx index ebfee1ee..12270b37 100644 --- a/test/settings/UserInterfaceSettings.test.tsx +++ b/test/settings/UserInterfaceSettings.test.tsx @@ -3,7 +3,7 @@ import { Mock } from 'ts-mockery'; import { Settings, UiSettings } from '../../src/settings/reducers/settings'; import { UserInterfaceSettings } from '../../src/settings/UserInterfaceSettings'; import { Theme } from '../../src/utils/theme'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const setUiSettings = jest.fn(); diff --git a/test/settings/VisitsSettings.test.tsx b/test/settings/VisitsSettings.test.tsx index c2926d2b..8d198272 100644 --- a/test/settings/VisitsSettings.test.tsx +++ b/test/settings/VisitsSettings.test.tsx @@ -2,7 +2,7 @@ import { screen } from '@testing-library/react'; import { Mock } from 'ts-mockery'; import { Settings } from '../../src/settings/reducers/settings'; import { VisitsSettings } from '../../src/settings/VisitsSettings'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const setVisitsSettings = jest.fn(); diff --git a/test/short-urls/ShortUrlForm.test.tsx b/test/short-urls/ShortUrlForm.test.tsx index 4c741e93..60b983c4 100644 --- a/test/short-urls/ShortUrlForm.test.tsx +++ b/test/short-urls/ShortUrlForm.test.tsx @@ -6,7 +6,7 @@ import { ShortUrlForm as createShortUrlForm, Mode } from '../../src/short-urls/S import { ReachableServer, SelectedServer } from '../../src/servers/data'; import { parseDate } from '../../src/utils/helpers/date'; import { OptionalString } from '../../src/utils/utils'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const createShortUrl = jest.fn(async () => Promise.resolve()); diff --git a/test/short-urls/ShortUrlsFilteringBar.test.tsx b/test/short-urls/ShortUrlsFilteringBar.test.tsx index c5f7f247..10adb9fc 100644 --- a/test/short-urls/ShortUrlsFilteringBar.test.tsx +++ b/test/short-urls/ShortUrlsFilteringBar.test.tsx @@ -6,7 +6,7 @@ import { ShortUrlsFilteringBar as filteringBarCreator } from '../../src/short-ur import { ReachableServer, SelectedServer } from '../../src/servers/data'; import { DateRange } from '../../src/utils/dates/types'; import { formatDate } from '../../src/utils/helpers/date'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), diff --git a/test/short-urls/ShortUrlsList.test.tsx b/test/short-urls/ShortUrlsList.test.tsx index 8c9f0eea..06b062ed 100644 --- a/test/short-urls/ShortUrlsList.test.tsx +++ b/test/short-urls/ShortUrlsList.test.tsx @@ -9,7 +9,7 @@ import { ShortUrlsList as ShortUrlsListModel } from '../../src/short-urls/reduce import { ReachableServer } from '../../src/servers/data'; import { Settings } from '../../src/settings/reducers/settings'; import { ShortUrlsTableProps } from '../../src/short-urls/ShortUrlsTable'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), diff --git a/test/short-urls/ShortUrlsTable.test.tsx b/test/short-urls/ShortUrlsTable.test.tsx index f16e3218..c3fded0a 100644 --- a/test/short-urls/ShortUrlsTable.test.tsx +++ b/test/short-urls/ShortUrlsTable.test.tsx @@ -4,7 +4,7 @@ import { ShortUrlsTable as shortUrlsTableCreator } from '../../src/short-urls/Sh import { ShortUrlsList } from '../../src/short-urls/reducers/shortUrlsList'; import { ReachableServer, SelectedServer } from '../../src/servers/data'; import { ShortUrlsOrderableFields, SHORT_URLS_ORDERABLE_FIELDS } from '../../src/short-urls/data'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const shortUrlsList = Mock.all(); diff --git a/test/short-urls/UseExistingIfFoundInfoIcon.test.tsx b/test/short-urls/UseExistingIfFoundInfoIcon.test.tsx index b823296b..43d2319a 100644 --- a/test/short-urls/UseExistingIfFoundInfoIcon.test.tsx +++ b/test/short-urls/UseExistingIfFoundInfoIcon.test.tsx @@ -1,6 +1,6 @@ import { screen } from '@testing-library/react'; import { UseExistingIfFoundInfoIcon } from '../../src/short-urls/UseExistingIfFoundInfoIcon'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { it('shows modal when icon is clicked', async () => { diff --git a/test/short-urls/helpers/CreateShortUrlResult.test.tsx b/test/short-urls/helpers/CreateShortUrlResult.test.tsx index e32e944b..03082a93 100644 --- a/test/short-urls/helpers/CreateShortUrlResult.test.tsx +++ b/test/short-urls/helpers/CreateShortUrlResult.test.tsx @@ -3,7 +3,7 @@ import { Mock } from 'ts-mockery'; import { CreateShortUrlResult as createResult } from '../../../src/short-urls/helpers/CreateShortUrlResult'; import { ShortUrl } from '../../../src/short-urls/data'; import { TimeoutToggle } from '../../../src/utils/helpers/hooks'; -import { renderWithEvents } from '../../__mocks__/setUpTest'; +import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { const copyToClipboard = jest.fn(); diff --git a/test/short-urls/helpers/ExportShortUrlsBtn.test.tsx b/test/short-urls/helpers/ExportShortUrlsBtn.test.tsx index 18f0bdac..c3abad98 100644 --- a/test/short-urls/helpers/ExportShortUrlsBtn.test.tsx +++ b/test/short-urls/helpers/ExportShortUrlsBtn.test.tsx @@ -4,7 +4,7 @@ import { MemoryRouter } from 'react-router-dom'; import { ReportExporter } from '../../../src/common/services/ReportExporter'; import { ExportShortUrlsBtn as createExportShortUrlsBtn } from '../../../src/short-urls/helpers/ExportShortUrlsBtn'; import { NotFoundServer, ReachableServer, SelectedServer } from '../../../src/servers/data'; -import { renderWithEvents } from '../../__mocks__/setUpTest'; +import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { const listShortUrls = jest.fn(); diff --git a/test/short-urls/helpers/qr-codes/QrErrorCorrectionDropdown.test.tsx b/test/short-urls/helpers/qr-codes/QrErrorCorrectionDropdown.test.tsx index 94cb23c7..ae20d61f 100644 --- a/test/short-urls/helpers/qr-codes/QrErrorCorrectionDropdown.test.tsx +++ b/test/short-urls/helpers/qr-codes/QrErrorCorrectionDropdown.test.tsx @@ -1,7 +1,7 @@ import { screen } from '@testing-library/react'; import { QrErrorCorrection } from '../../../../src/utils/helpers/qrCodes'; import { QrErrorCorrectionDropdown } from '../../../../src/short-urls/helpers/qr-codes/QrErrorCorrectionDropdown'; -import { renderWithEvents } from '../../../__mocks__/setUpTest'; +import { renderWithEvents } from '../../../__helpers__/setUpTest'; describe('', () => { const initialErrorCorrection: QrErrorCorrection = 'Q'; diff --git a/test/short-urls/helpers/qr-codes/QrFormatDropdown.test.tsx b/test/short-urls/helpers/qr-codes/QrFormatDropdown.test.tsx index 04767a34..499a5e89 100644 --- a/test/short-urls/helpers/qr-codes/QrFormatDropdown.test.tsx +++ b/test/short-urls/helpers/qr-codes/QrFormatDropdown.test.tsx @@ -1,7 +1,7 @@ import { screen } from '@testing-library/react'; import { QrCodeFormat } from '../../../../src/utils/helpers/qrCodes'; import { QrFormatDropdown } from '../../../../src/short-urls/helpers/qr-codes/QrFormatDropdown'; -import { renderWithEvents } from '../../../__mocks__/setUpTest'; +import { renderWithEvents } from '../../../__helpers__/setUpTest'; describe('', () => { const initialFormat: QrCodeFormat = 'svg'; diff --git a/test/tags/TagCard.test.tsx b/test/tags/TagCard.test.tsx index 60e8a488..d0e9297c 100644 --- a/test/tags/TagCard.test.tsx +++ b/test/tags/TagCard.test.tsx @@ -4,7 +4,7 @@ import { Mock } from 'ts-mockery'; import { TagCard as createTagCard } from '../../src/tags/TagCard'; import { ColorGenerator } from '../../src/utils/services/ColorGenerator'; import { ReachableServer } from '../../src/servers/data'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const TagCard = createTagCard( diff --git a/test/tags/TagsCards.test.tsx b/test/tags/TagsCards.test.tsx index 06274262..36d6f286 100644 --- a/test/tags/TagsCards.test.tsx +++ b/test/tags/TagsCards.test.tsx @@ -4,7 +4,7 @@ import { TagsCards as createTagsCards } from '../../src/tags/TagsCards'; import { SelectedServer } from '../../src/servers/data'; import { rangeOf } from '../../src/utils/utils'; import { NormalizedTag } from '../../src/tags/data'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const amountOfTags = 10; diff --git a/test/tags/TagsList.test.tsx b/test/tags/TagsList.test.tsx index b386fb5b..03caedcd 100644 --- a/test/tags/TagsList.test.tsx +++ b/test/tags/TagsList.test.tsx @@ -5,7 +5,7 @@ import { TagsList as createTagsList, TagsListProps } from '../../src/tags/TagsLi import { TagsList } from '../../src/tags/reducers/tagsList'; import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub'; import { Settings } from '../../src/settings/reducers/settings'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const filterTags = jest.fn(); diff --git a/test/tags/TagsModeDropdown.test.tsx b/test/tags/TagsModeDropdown.test.tsx index 7dfda64f..9550a04b 100644 --- a/test/tags/TagsModeDropdown.test.tsx +++ b/test/tags/TagsModeDropdown.test.tsx @@ -1,7 +1,7 @@ import { screen } from '@testing-library/react'; import { TagsModeDropdown } from '../../src/tags/TagsModeDropdown'; import { TagsMode } from '../../src/settings/reducers/settings'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const onChange = jest.fn(); diff --git a/test/tags/helpers/DeleteTagConfirmModal.test.tsx b/test/tags/helpers/DeleteTagConfirmModal.test.tsx index b141d6a5..8ca667ea 100644 --- a/test/tags/helpers/DeleteTagConfirmModal.test.tsx +++ b/test/tags/helpers/DeleteTagConfirmModal.test.tsx @@ -1,7 +1,7 @@ import { screen } from '@testing-library/react'; import { DeleteTagConfirmModal } from '../../../src/tags/helpers/DeleteTagConfirmModal'; import { TagDeletion } from '../../../src/tags/reducers/tagDelete'; -import { renderWithEvents } from '../../__mocks__/setUpTest'; +import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { const tag = 'nodejs'; diff --git a/test/tags/helpers/Tag.test.tsx b/test/tags/helpers/Tag.test.tsx index a7f24c6f..e8ecbaf6 100644 --- a/test/tags/helpers/Tag.test.tsx +++ b/test/tags/helpers/Tag.test.tsx @@ -4,7 +4,7 @@ import { ReactNode } from 'react'; import { ColorGenerator } from '../../../src/utils/services/ColorGenerator'; import { MAIN_COLOR } from '../../../src/utils/theme'; import { Tag } from '../../../src/tags/helpers/Tag'; -import { renderWithEvents } from '../../__mocks__/setUpTest'; +import { renderWithEvents } from '../../__helpers__/setUpTest'; const hexToRgb = (hex: string) => { const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); diff --git a/test/utils/Checkbox.test.tsx b/test/utils/Checkbox.test.tsx index a60f3a3e..d290b319 100644 --- a/test/utils/Checkbox.test.tsx +++ b/test/utils/Checkbox.test.tsx @@ -1,6 +1,6 @@ import { render, screen } from '@testing-library/react'; import { Checkbox } from '../../src/utils/Checkbox'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { it.each([['foo'], ['bar'], ['baz']])('includes extra class names when provided', (className) => { diff --git a/test/utils/CopyToClipboardIcon.test.tsx b/test/utils/CopyToClipboardIcon.test.tsx index df7b3f99..3423a3d9 100644 --- a/test/utils/CopyToClipboardIcon.test.tsx +++ b/test/utils/CopyToClipboardIcon.test.tsx @@ -1,5 +1,5 @@ import { CopyToClipboardIcon } from '../../src/utils/CopyToClipboardIcon'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const onCopy = jest.fn(); diff --git a/test/utils/DateInput.test.tsx b/test/utils/DateInput.test.tsx index eba1eb05..e036433c 100644 --- a/test/utils/DateInput.test.tsx +++ b/test/utils/DateInput.test.tsx @@ -1,7 +1,7 @@ import { screen, waitFor } from '@testing-library/react'; import { Mock } from 'ts-mockery'; import { DateInput, DateInputProps } from '../../src/utils/DateInput'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const setUp = (props: Partial = {}) => renderWithEvents( diff --git a/test/utils/InfoTooltip.test.tsx b/test/utils/InfoTooltip.test.tsx index 8a651b9c..1bda4e60 100644 --- a/test/utils/InfoTooltip.test.tsx +++ b/test/utils/InfoTooltip.test.tsx @@ -1,7 +1,7 @@ import { screen, waitFor } from '@testing-library/react'; import { Placement } from '@popperjs/core'; import { InfoTooltip, InfoTooltipProps } from '../../src/utils/InfoTooltip'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const setUp = (props: Partial = {}) => renderWithEvents( diff --git a/test/utils/OrderingDropdown.test.tsx b/test/utils/OrderingDropdown.test.tsx index 47c83302..f8e78944 100644 --- a/test/utils/OrderingDropdown.test.tsx +++ b/test/utils/OrderingDropdown.test.tsx @@ -2,7 +2,7 @@ import { screen } from '@testing-library/react'; import { values } from 'ramda'; import { OrderingDropdown, OrderingDropdownProps } from '../../src/utils/OrderingDropdown'; import { OrderDir } from '../../src/utils/helpers/ordering'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const items = { diff --git a/test/utils/dates/DateIntervalDropdownItems.test.tsx b/test/utils/dates/DateIntervalDropdownItems.test.tsx index 0cbf817e..0e9ec52f 100644 --- a/test/utils/dates/DateIntervalDropdownItems.test.tsx +++ b/test/utils/dates/DateIntervalDropdownItems.test.tsx @@ -2,7 +2,7 @@ import { screen, waitFor } from '@testing-library/react'; import { DateIntervalDropdownItems } from '../../../src/utils/dates/DateIntervalDropdownItems'; import { DATE_INTERVALS, DateInterval, rangeOrIntervalToString } from '../../../src/utils/dates/types'; import { DropdownBtn } from '../../../src/utils/DropdownBtn'; -import { renderWithEvents } from '../../__mocks__/setUpTest'; +import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { const onChange = jest.fn(); diff --git a/test/utils/dates/DateIntervalSelector.test.tsx b/test/utils/dates/DateIntervalSelector.test.tsx index abca608e..ebff24a1 100644 --- a/test/utils/dates/DateIntervalSelector.test.tsx +++ b/test/utils/dates/DateIntervalSelector.test.tsx @@ -1,7 +1,7 @@ import { screen, waitFor } from '@testing-library/react'; import { DateInterval, rangeOrIntervalToString } from '../../../src/utils/dates/types'; import { DateIntervalSelector } from '../../../src/utils/dates/DateIntervalSelector'; -import { renderWithEvents } from '../../__mocks__/setUpTest'; +import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { const activeInterval: DateInterval = 'last7Days'; diff --git a/test/visits/DomainVisits.test.tsx b/test/visits/DomainVisits.test.tsx index 7697a1eb..19be1892 100644 --- a/test/visits/DomainVisits.test.tsx +++ b/test/visits/DomainVisits.test.tsx @@ -9,7 +9,7 @@ import { DomainVisits } from '../../src/visits/reducers/domainVisits'; import { Settings } from '../../src/settings/reducers/settings'; import { SelectedServer } from '../../src/servers/data'; import { Visit } from '../../src/visits/types'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), diff --git a/test/visits/NonOrphanVisits.test.tsx b/test/visits/NonOrphanVisits.test.tsx index f27ec3f5..1c3572de 100644 --- a/test/visits/NonOrphanVisits.test.tsx +++ b/test/visits/NonOrphanVisits.test.tsx @@ -8,7 +8,7 @@ import { Visit, VisitsInfo } from '../../src/visits/types'; import { Settings } from '../../src/settings/reducers/settings'; import { ReportExporter } from '../../src/common/services/ReportExporter'; import { SelectedServer } from '../../src/servers/data'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const exportVisits = jest.fn(); diff --git a/test/visits/OrphanVisits.test.tsx b/test/visits/OrphanVisits.test.tsx index 874be1ef..6f92edf4 100644 --- a/test/visits/OrphanVisits.test.tsx +++ b/test/visits/OrphanVisits.test.tsx @@ -8,7 +8,7 @@ import { Visit, VisitsInfo } from '../../src/visits/types'; import { Settings } from '../../src/settings/reducers/settings'; import { ReportExporter } from '../../src/common/services/ReportExporter'; import { SelectedServer } from '../../src/servers/data'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const getOrphanVisits = jest.fn(); diff --git a/test/visits/ShortUrlVisits.test.tsx b/test/visits/ShortUrlVisits.test.tsx index a2dc15b4..4e6f4376 100644 --- a/test/visits/ShortUrlVisits.test.tsx +++ b/test/visits/ShortUrlVisits.test.tsx @@ -10,7 +10,7 @@ import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub'; import { ReportExporter } from '../../src/common/services/ReportExporter'; import { Visit } from '../../src/visits/types'; import { Settings } from '../../src/settings/reducers/settings'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const getShortUrlVisitsMock = jest.fn(); diff --git a/test/visits/ShortUrlVisitsHeader.test.tsx b/test/visits/ShortUrlVisitsHeader.test.tsx index 78ff2ba0..12c8fa80 100644 --- a/test/visits/ShortUrlVisitsHeader.test.tsx +++ b/test/visits/ShortUrlVisitsHeader.test.tsx @@ -4,7 +4,7 @@ import { formatDistance, parseISO } from 'date-fns'; import { ShortUrlVisitsHeader } from '../../src/visits/ShortUrlVisitsHeader'; import { ShortUrlDetail } from '../../src/short-urls/reducers/shortUrlDetail'; import { ShortUrlVisits } from '../../src/visits/reducers/shortUrlVisits'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const dateCreated = '2018-01-01T10:00:00+00:00'; diff --git a/test/visits/TagVisits.test.tsx b/test/visits/TagVisits.test.tsx index 7225a809..feb4bcae 100644 --- a/test/visits/TagVisits.test.tsx +++ b/test/visits/TagVisits.test.tsx @@ -9,7 +9,7 @@ import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub'; import { ReportExporter } from '../../src/common/services/ReportExporter'; import { Visit } from '../../src/visits/types'; import { Settings } from '../../src/settings/reducers/settings'; -import { renderWithEvents } from '../__mocks__/setUpTest'; +import { renderWithEvents } from '../__helpers__/setUpTest'; jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), diff --git a/test/visits/charts/DoughnutChart.test.tsx b/test/visits/charts/DoughnutChart.test.tsx index e942bd7f..2dee8163 100644 --- a/test/visits/charts/DoughnutChart.test.tsx +++ b/test/visits/charts/DoughnutChart.test.tsx @@ -1,6 +1,6 @@ import { screen } from '@testing-library/react'; import { DoughnutChart } from '../../../src/visits/charts/DoughnutChart'; -import { setUpCanvas } from '../../__mocks__/setUpTest'; +import { setUpCanvas } from '../../__helpers__/setUpTest'; describe('', () => { const stats = { diff --git a/test/visits/charts/HorizontalBarChart.test.tsx b/test/visits/charts/HorizontalBarChart.test.tsx index cc5c1b6b..6664f1bf 100644 --- a/test/visits/charts/HorizontalBarChart.test.tsx +++ b/test/visits/charts/HorizontalBarChart.test.tsx @@ -1,5 +1,5 @@ import { HorizontalBarChart, HorizontalBarChartProps } from '../../../src/visits/charts/HorizontalBarChart'; -import { setUpCanvas } from '../../__mocks__/setUpTest'; +import { setUpCanvas } from '../../__helpers__/setUpTest'; describe('', () => { const setUp = (props: HorizontalBarChartProps) => setUpCanvas(); diff --git a/test/visits/charts/LineChartCard.test.tsx b/test/visits/charts/LineChartCard.test.tsx index db5e9040..433615b3 100644 --- a/test/visits/charts/LineChartCard.test.tsx +++ b/test/visits/charts/LineChartCard.test.tsx @@ -4,7 +4,7 @@ import { formatISO, subDays, subMonths, subYears } from 'date-fns'; import { Mock } from 'ts-mockery'; import { LineChartCard } from '../../../src/visits/charts/LineChartCard'; import { NormalizedVisit } from '../../../src/visits/types'; -import { setUpCanvas } from '../../__mocks__/setUpTest'; +import { setUpCanvas } from '../../__helpers__/setUpTest'; describe('', () => { const setUp = (visits: NormalizedVisit[] = [], highlightedVisits: NormalizedVisit[] = []) => ({ diff --git a/test/visits/helpers/OpenMapModalBtn.test.tsx b/test/visits/helpers/OpenMapModalBtn.test.tsx index 5c851ae9..2e83dc71 100644 --- a/test/visits/helpers/OpenMapModalBtn.test.tsx +++ b/test/visits/helpers/OpenMapModalBtn.test.tsx @@ -2,7 +2,7 @@ import { screen, waitFor } from '@testing-library/react'; import { Mock } from 'ts-mockery'; import { OpenMapModalBtn } from '../../../src/visits/helpers/OpenMapModalBtn'; import { CityStats } from '../../../src/visits/types'; -import { renderWithEvents } from '../../__mocks__/setUpTest'; +import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { const title = 'Foo'; diff --git a/test/visits/helpers/VisitsFilterDropdown.test.tsx b/test/visits/helpers/VisitsFilterDropdown.test.tsx index 71ce49c8..eb3f38a2 100644 --- a/test/visits/helpers/VisitsFilterDropdown.test.tsx +++ b/test/visits/helpers/VisitsFilterDropdown.test.tsx @@ -1,7 +1,7 @@ import { screen } from '@testing-library/react'; import { OrphanVisitType, VisitsFilter } from '../../../src/visits/types'; import { VisitsFilterDropdown } from '../../../src/visits/helpers/VisitsFilterDropdown'; -import { renderWithEvents } from '../../__mocks__/setUpTest'; +import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { const onChange = jest.fn(); From 879017ecca5462c5813fa88ab62ab5a7c038983a Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 10 Jul 2022 19:51:21 +0200 Subject: [PATCH 2/6] Migrated ShortUrlFormCheckboxGroup test to react testing library --- .../helpers/ShortUrlFormCheckboxGroup.test.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/short-urls/helpers/ShortUrlFormCheckboxGroup.test.tsx b/test/short-urls/helpers/ShortUrlFormCheckboxGroup.test.tsx index aa564849..ec3276d0 100644 --- a/test/short-urls/helpers/ShortUrlFormCheckboxGroup.test.tsx +++ b/test/short-urls/helpers/ShortUrlFormCheckboxGroup.test.tsx @@ -1,17 +1,17 @@ -import { shallow } from 'enzyme'; +import { render, screen } from '@testing-library/react'; import { ShortUrlFormCheckboxGroup } from '../../../src/short-urls/helpers/ShortUrlFormCheckboxGroup'; -import { Checkbox } from '../../../src/utils/Checkbox'; -import { InfoTooltip } from '../../../src/utils/InfoTooltip'; describe('', () => { it.each([ [undefined, '', 0], ['This is the tooltip', 'me-2', 1], ])('renders tooltip only when provided', (infoTooltip, expectedClassName, expectedAmountOfTooltips) => { - const wrapper = shallow(); - const checkbox = wrapper.find(Checkbox); + render(); - expect(checkbox.prop('className')).toEqual(expectedClassName); - expect(wrapper.find(InfoTooltip)).toHaveLength(expectedAmountOfTooltips); + expect(screen.getByRole('checkbox').parentNode).toHaveAttribute( + 'class', + expect.stringContaining(expectedClassName), + ); + expect(screen.queryAllByRole('img', { hidden: true })).toHaveLength(expectedAmountOfTooltips); }); }); From f97fce873b11d389fafe16d86c22c24fd598c8d0 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 10 Jul 2022 19:58:27 +0200 Subject: [PATCH 3/6] Migrated ShortUrlDetailLink test to react testing library --- .../helpers/ShortUrlDetailLink.test.tsx | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/test/short-urls/helpers/ShortUrlDetailLink.test.tsx b/test/short-urls/helpers/ShortUrlDetailLink.test.tsx index 83671e5a..3c38216e 100644 --- a/test/short-urls/helpers/ShortUrlDetailLink.test.tsx +++ b/test/short-urls/helpers/ShortUrlDetailLink.test.tsx @@ -1,15 +1,11 @@ -import { shallow, ShallowWrapper } from 'enzyme'; -import { Link } from 'react-router-dom'; +import { render, screen } from '@testing-library/react'; import { Mock } from 'ts-mockery'; +import { MemoryRouter } from 'react-router-dom'; import { ShortUrlDetailLink, LinkSuffix } from '../../../src/short-urls/helpers/ShortUrlDetailLink'; import { NotFoundServer, ReachableServer } from '../../../src/servers/data'; import { ShortUrl } from '../../../src/short-urls/data'; describe('', () => { - let wrapper: ShallowWrapper; - - afterEach(() => wrapper?.unmount()); - it.each([ [undefined, undefined], [null, null], @@ -19,15 +15,14 @@ describe('', () => { [null, Mock.all()], [undefined, Mock.all()], ])('only renders a plain span when either server or short URL are not set', (selectedServer, shortUrl) => { - wrapper = shallow( + render( Something , ); - const link = wrapper.find(Link); - expect(link).toHaveLength(0); - expect(wrapper.html()).toEqual('Something'); + expect(screen.queryByRole('link')).not.toBeInTheDocument(); + expect(screen.getByText('Something')).toBeInTheDocument(); }); it.each([ @@ -56,15 +51,13 @@ describe('', () => { '/server/3/short-code/def456/edit?domain=example.com', ], ])('renders link with expected query when', (selectedServer, shortUrl, suffix, expectedLink) => { - wrapper = shallow( - - Something - , + render( + + + Something + + , ); - const link = wrapper.find(Link); - const to = link.prop('to'); - - expect(link).toHaveLength(1); - expect(to).toEqual(expectedLink); + expect(screen.getByRole('link')).toHaveProperty('href', expect.stringContaining(expectedLink)); }); }); From bdf181adec242889750d6c7aa30cd8cb7ed7fc5f Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 10 Jul 2022 20:11:01 +0200 Subject: [PATCH 4/6] Migrated PaginationDropdown test to react testing library --- test/utils/PaginationDropdown.test.tsx | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/test/utils/PaginationDropdown.test.tsx b/test/utils/PaginationDropdown.test.tsx index c3718398..02ff5d61 100644 --- a/test/utils/PaginationDropdown.test.tsx +++ b/test/utils/PaginationDropdown.test.tsx @@ -1,22 +1,23 @@ -import { shallow, ShallowWrapper } from 'enzyme'; -import { DropdownItem } from 'reactstrap'; +import { screen } from '@testing-library/react'; import { PaginationDropdown } from '../../src/utils/PaginationDropdown'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const setValue = jest.fn(); - let wrapper: ShallowWrapper; + const setUp = async () => { + const result = renderWithEvents(); + const { user } = result; - beforeEach(() => { - wrapper = shallow(); - }); + await user.click(screen.getByRole('button')); + + return result; + }; afterEach(jest.clearAllMocks); - afterEach(() => wrapper?.unmount()); - it('renders expected amount of items', () => { - const items = wrapper.find(DropdownItem); - - expect(items).toHaveLength(6); + it('renders expected amount of items', async () => { + await setUp(); + expect(screen.getAllByRole('menuitem')).toHaveLength(5); }); it.each([ @@ -24,12 +25,11 @@ describe('', () => { [1, 50], [2, 100], [3, 200], - [5, Infinity], - ])('sets expected value when an item is clicked', (index, expectedValue) => { - const item = wrapper.find(DropdownItem).at(index); + ])('sets expected value when an item is clicked', async (index, expectedValue) => { + const { user } = await setUp(); expect(setValue).not.toHaveBeenCalled(); - item.simulate('click'); + await user.click(screen.getAllByRole('menuitem')[index]); expect(setValue).toHaveBeenCalledWith(expectedValue); }); }); From 4a88f30d13dcc861762b0497f3d6d2fe6f424c6c Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 10 Jul 2022 20:29:56 +0200 Subject: [PATCH 5/6] Migrated Message test to react testing library --- test/utils/Message.test.tsx | 49 +++++++++++++------------------------ 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/test/utils/Message.test.tsx b/test/utils/Message.test.tsx index 4c658c20..d800a66d 100644 --- a/test/utils/Message.test.tsx +++ b/test/utils/Message.test.tsx @@ -1,28 +1,17 @@ -import { shallow, ShallowWrapper } from 'enzyme'; +import { render, screen } from '@testing-library/react'; import { PropsWithChildren } from 'react'; -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { Card } from 'reactstrap'; import { Message, MessageProps } from '../../src/utils/Message'; describe('', () => { - let wrapper: ShallowWrapper; - const createWrapper = (props: PropsWithChildren = {}) => { - wrapper = shallow(); - - return wrapper; - }; - - afterEach(() => wrapper?.unmount()); + const setUp = (props: PropsWithChildren = {}) => render(); it.each([ - [true, 1, 0], - [false, 0, 1], - [undefined, 0, 1], - ])('renders expected classes based on width', (fullWidth, expectedFull, expectedNonFull) => { - const wrapper = createWrapper({ fullWidth }); - - expect(wrapper.find('.col-md-12')).toHaveLength(expectedFull); - expect(wrapper.find('.col-md-10')).toHaveLength(expectedNonFull); + [true, 'col-md-12'], + [false, 'col-md-10 offset-md-1'], + [undefined, 'col-md-10 offset-md-1'], + ])('renders expected classes based on width', (fullWidth, expectedClass) => { + const { container } = setUp({ fullWidth }); + expect(container.firstChild?.firstChild).toHaveClass(expectedClass); }); it.each([ @@ -31,15 +20,14 @@ describe('', () => { [true, undefined], [false, undefined], ])('renders expected content', (loading, children) => { - const wrapper = createWrapper({ loading, children }); + setUp({ loading, children }); - expect(wrapper.find(FontAwesomeIcon)).toHaveLength(loading ? 1 : 0); + expect(screen.queryAllByRole('img', { hidden: true })).toHaveLength(loading ? 1 : 0); if (loading) { - expect(wrapper.find('span').text()).toContain(children || 'Loading...'); + expect(screen.getByText(children || 'Loading...')).toHaveClass('ms-2'); } else { - expect(wrapper.find('span')).toHaveLength(0); - expect(wrapper.find('h3').text()).toContain(children || ''); + expect(screen.getByRole('heading')).toHaveTextContent(children || ''); } }); @@ -48,17 +36,14 @@ describe('', () => { ['default', '', 'text-muted'], [undefined, '', 'text-muted'], ])('renders proper classes based on message type', (type, expectedCardClass, expectedH3Class) => { - const wrapper = createWrapper({ type: type as 'default' | 'error' | undefined }); - const card = wrapper.find(Card); - const h3 = wrapper.find('h3'); + const { container } = setUp({ type: type as 'default' | 'error' | undefined }); - expect(card.prop('className')).toEqual(expectedCardClass); - expect(h3.prop('className')).toEqual(`text-center mb-0 ${expectedH3Class}`); + expect(container.querySelector('.card-body')).toHaveAttribute('class', expect.stringContaining(expectedCardClass)); + expect(screen.getByRole('heading')).toHaveClass(`text-center mb-0 ${expectedH3Class}`); }); it.each([{ className: 'foo' }, { className: 'bar' }, {}])('renders provided classes', ({ className }) => { - const wrapper = createWrapper({ className }); - - expect(wrapper.prop('className')).toEqual(`g-0${className ? ` ${className}` : ''}`); + const { container } = setUp({ className }); + expect(container.firstChild).toHaveClass(`g-0${className ? ` ${className}` : ''}`); }); }); From 381eb5a5022921e06a56363bf0cf8306be92fbe3 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 10 Jul 2022 20:42:58 +0200 Subject: [PATCH 6/6] Migrated DropdownBtn test to react testing library --- test/utils/DropdownBtn.test.tsx | 54 +++++++++++++++------------------ 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/test/utils/DropdownBtn.test.tsx b/test/utils/DropdownBtn.test.tsx index 0a6d301a..cfca2128 100644 --- a/test/utils/DropdownBtn.test.tsx +++ b/test/utils/DropdownBtn.test.tsx @@ -1,30 +1,23 @@ -import { shallow, ShallowWrapper } from 'enzyme'; -import { DropdownMenu, DropdownToggle } from 'reactstrap'; +import { screen } from '@testing-library/react'; import { PropsWithChildren } from 'react'; import { DropdownBtn, DropdownBtnProps } from '../../src/utils/DropdownBtn'; +import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - let wrapper: ShallowWrapper; - const createWrapper = (props: PropsWithChildren) => { - wrapper = shallow(); + const setUp = (props: PropsWithChildren) => renderWithEvents( + , + ); - return wrapper; - }; - - afterEach(() => wrapper?.unmount()); - - it.each([['foo'], ['bar'], ['baz']])('displays provided text', (text) => { - const wrapper = createWrapper({ text }); - const toggle = wrapper.find(DropdownToggle); - - expect(toggle.prop('children')).toContain(text); + it.each([['foo'], ['bar'], ['baz']])('displays provided text in button', (text) => { + setUp({ text }); + expect(screen.getByRole('button')).toHaveTextContent(text); }); - it.each([['foo'], ['bar'], ['baz']])('displays provided children', (children) => { - const wrapper = createWrapper({ text: '', children }); - const menu = wrapper.find(DropdownMenu); + it.each([['foo'], ['bar'], ['baz']])('displays provided children in menu', async (children) => { + const { user } = setUp({ text: '', children }); - expect(menu.html()).toContain(children); + await user.click(screen.getByRole('button')); + expect(screen.getByRole('menu')).toHaveTextContent(children); }); it.each([ @@ -33,20 +26,21 @@ describe('', () => { ['foo', 'dropdown-btn__toggle btn-block foo'], ['bar', 'dropdown-btn__toggle btn-block bar'], ])('includes provided classes', (className, expectedClasses) => { - const wrapper = createWrapper({ text: '', className }); - const toggle = wrapper.find(DropdownToggle); - - expect(toggle.prop('className')?.trim()).toEqual(expectedClasses); + setUp({ text: '', className }); + expect(screen.getByRole('button')).toHaveClass(expectedClasses); }); it.each([ - [100, { minWidth: '100px' }], - [250, { minWidth: '250px' }], - [undefined, {}], - ])('renders proper styles when minWidth is provided', (minWidth, expectedStyle) => { - const wrapper = createWrapper({ text: '', minWidth }); - const style = wrapper.find(DropdownMenu).prop('style'); + [100, 'min-width: 100px; '], + [250, 'min-width: 250px; '], + [undefined, ''], + ])('renders proper styles when minWidth is provided', async (minWidth, expectedStyle) => { + const { user } = setUp({ text: '', minWidth }); - expect(style).toEqual(expectedStyle); + await user.click(screen.getByRole('button')); + expect(screen.getByRole('menu')).toHaveAttribute( + 'style', + `${expectedStyle}position: absolute; left: 0px; top: 0px;`, + ); }); });