From fc23b7539838ab209434ea503ceed09bd86d7274 Mon Sep 17 00:00:00 2001 From: Eniola Olatunji Date: Wed, 6 Dec 2023 13:24:57 +0100 Subject: [PATCH] fix: resolved failing test on blockchainApplicationRow --- .../BlockchainApplicationRow.test.js | 71 ++++++++----------- 1 file changed, 28 insertions(+), 43 deletions(-) diff --git a/src/modules/blockchainApplication/explore/components/BlockchainApplicationRow/BlockchainApplicationRow.test.js b/src/modules/blockchainApplication/explore/components/BlockchainApplicationRow/BlockchainApplicationRow.test.js index 65a0e7f329..45e2b0df28 100644 --- a/src/modules/blockchainApplication/explore/components/BlockchainApplicationRow/BlockchainApplicationRow.test.js +++ b/src/modules/blockchainApplication/explore/components/BlockchainApplicationRow/BlockchainApplicationRow.test.js @@ -1,10 +1,9 @@ -import React from 'react'; -import { fireEvent, screen } from '@testing-library/react'; -import mockBlockchainApplications from '@tests/fixtures/blockchainApplicationsExplore'; +import { fireEvent } from '@testing-library/react'; import { usePinBlockchainApplication } from '@blockchainApplication/manage/hooks/usePinBlockchainApplication'; +import { mockBlockchainAppMeta } from '@blockchainApplication/manage/__fixtures__'; import { renderWithRouter } from 'src/utils/testHelpers'; import { addSearchParamsToUrl } from 'src/utils/searchParams'; -import { MemoryRouter } from 'react-router'; +import FlashMessageHolder from 'src/theme/flashMessage/holder'; import BlockchainApplicationRow from '.'; jest.mock('src/utils/searchParams', () => ({ @@ -12,7 +11,7 @@ jest.mock('src/utils/searchParams', () => ({ })); jest.mock('@blockchainApplication/manage/hooks/usePinBlockchainApplication'); const mockTogglePin = jest.fn(); -const mockedPins = [mockBlockchainApplications[0].chainID]; +const mockedPins = [mockBlockchainAppMeta.data[0].chainID]; usePinBlockchainApplication.mockReturnValue({ togglePin: mockTogglePin, @@ -27,38 +26,36 @@ jest.mock('src/utils/searchParams', () => ({ describe('BlockchainApplicationRow', () => { let wrapper; + const blockChainData = { + ...mockBlockchainAppMeta.data[0], + status: 'activated', + escrowedLSK: 10000000, + }; + const props = { - data: mockBlockchainApplications[0], + data: blockChainData, t: jest.fn((val) => val), }; beforeEach(() => { jest.clearAllMocks(); - wrapper = renderWithRouter(BlockchainApplicationRow, props); }); it('should display correctly', () => { - const { chainName, status, chainID } = mockBlockchainApplications[0]; + const { chainName, status, chainID } = blockChainData; + wrapper = renderWithRouter(BlockchainApplicationRow, props); - expect(screen.getByText(chainName)).toBeTruthy(); - expect(screen.getByText(chainID)).toBeTruthy(); - expect(screen.getByText(status)).toBeTruthy(); - expect(screen.getByText('0.5 LSK')).toBeTruthy(); + expect(wrapper.getByText(chainName)).toBeTruthy(); + expect(wrapper.getByText(chainID)).toBeTruthy(); + expect(wrapper.getByText(status)).toBeTruthy(); + expect(wrapper.getByText('0.1 LSK')).toBeTruthy(); }); it("should navigate to the application's details", () => { - const { chainID } = mockBlockchainApplications[0]; - fireEvent.click(screen.getByText(chainID)); - - expect(addSearchParamsToUrl).toHaveBeenCalledWith(expect.any(Object), { - modal: 'blockChainApplicationDetails', - chainId: chainID, - }); - }); + const { chainID } = blockChainData; + wrapper = renderWithRouter(BlockchainApplicationRow, props); - it("should navigate to the application's details", () => { - const { chainID } = mockBlockchainApplications[0]; - fireEvent.click(screen.getByText(chainID)); + fireEvent.click(wrapper.getByText(chainID)); expect(addSearchParamsToUrl).toHaveBeenCalledWith(expect.any(Object), { modal: 'blockChainApplicationDetails', @@ -66,29 +63,17 @@ describe('BlockchainApplicationRow', () => { }); }); - it('should invoke toggle callback', () => { - const { chainID } = mockBlockchainApplications[0]; - fireEvent.click(screen.getByTestId('pin-button')); - expect(mockTogglePin).toHaveBeenCalledWith(chainID); - }); - - it('should render the active pin icon', () => { - expect(screen.getByAltText('pinnedIcon')).toBeTruthy(); - }); + it('should show a flashback message recommendation to regisgter a side chain', () => { + const { chainID } = blockChainData; + const mockAddMessage = jest.spyOn(FlashMessageHolder, 'addMessage').mockReturnValue({}); - it('should render the inactive pin icon', () => { - usePinBlockchainApplication.mockReturnValue({ - togglePin: mockTogglePin, - pins: [], - checkPinByChainId: jest.fn().mockReturnValue(false), + wrapper = renderWithRouter(BlockchainApplicationRow, { + ...props, + data: { ...props.data, serviceURLs: undefined }, }); - wrapper.rerender( - - - - ); + fireEvent.click(wrapper.getByText(chainID)); - expect(screen.getByAltText('unpinnedIcon')).toBeTruthy(); + expect(mockAddMessage).toHaveBeenCalledWith(expect.anything(), 'WarnMissingAppMetaData'); }); });