Skip to content

Commit

Permalink
fix: resolved failing test on blockchainApplicationRow
Browse files Browse the repository at this point in the history
  • Loading branch information
eniolam1000752 committed Dec 6, 2023
1 parent ab2caf4 commit fc23b75
Showing 1 changed file with 28 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
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', () => ({
addSearchParamsToUrl: jest.fn(),
}));
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,
Expand All @@ -27,68 +26,54 @@ 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',
chainId: chainID,
});
});

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(
<MemoryRouter initialEntries={[]}>
<BlockchainApplicationRow {...props} />
</MemoryRouter>
);
fireEvent.click(wrapper.getByText(chainID));

expect(screen.getByAltText('unpinnedIcon')).toBeTruthy();
expect(mockAddMessage).toHaveBeenCalledWith(expect.anything(), 'WarnMissingAppMetaData');
});
});

0 comments on commit fc23b75

Please sign in to comment.