Skip to content

Commit

Permalink
fix new unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OlimpiaZurek committed Jan 7, 2025
1 parent 1297804 commit c52234d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
8 changes: 2 additions & 6 deletions tests/unit/BaseSelectionListTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,8 @@ describe('BaseSelectionList', () => {
isSelected: section.keyForList === '2',
}));
const {rerender} = render(<BaseListItemRenderer sections={mockSections} />);
expect(screen.getByTestId(`${CONST.BASE_LIST_ITEM_TEST_ID}1`)).toHaveAccessibilityState({
selected: true,
});
expect(screen.getByTestId(`${CONST.BASE_LIST_ITEM_TEST_ID}1`)).toBeSelected();
rerender(<BaseListItemRenderer sections={updatedMockSections} />);
expect(screen.getByTestId(`${CONST.BASE_LIST_ITEM_TEST_ID}2`)).toHaveAccessibilityState({
selected: true,
});
expect(screen.getByTestId(`${CONST.BASE_LIST_ITEM_TEST_ID}2`)).toBeSelected();
});
});
18 changes: 14 additions & 4 deletions tests/unit/NetworkTest.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {render, screen} from '@testing-library/react-native';
import {fireEvent, render, screen} from '@testing-library/react-native';
import {sub as dateSubtract} from 'date-fns/sub';
import type {Mock} from 'jest-mock';
import type {OnyxEntry} from 'react-native-onyx';
Expand Down Expand Up @@ -398,6 +398,8 @@ describe('NetworkTests', () => {

test('poor connection simulation', async () => {
const logSpy = jest.spyOn(Log, 'info');
const setShouldForceOfflineSpy = jest.spyOn(NetworkActions, 'setShouldForceOffline');
const setShouldFailAllRequestsSpy = jest.spyOn(NetworkActions, 'setShouldFailAllRequests');

// Given an opened test tool menu
render(<TestToolMenu />);
Expand All @@ -408,10 +410,18 @@ describe('NetworkTests', () => {
NetworkActions.setShouldSimulatePoorConnection(true, undefined);
await waitForBatchedUpdates();

// Then the connection status change log should be displayed as well as Force offline/Simulate failing network requests toggles should be disabled
// Then the connection status change log should be displayed as well Simulate poor internet connection toggle should be checked
expect(logSpy).toHaveBeenCalledWith(expect.stringMatching(/\[NetworkConnection\] Set connection status "(online|offline)" for (\d+(?:\.\d+)?) sec/));
expect(screen.getByAccessibilityHint('Force offline')).toBeDisabled();
expect(screen.getByAccessibilityHint('Simulate failing network requests')).toBeDisabled();
expect(screen.getByAccessibilityHint('Simulate poor internet connection')).toBeChecked();

// And the setShouldForceOffline and setShouldFailAllRequests should not be called as the Force offline and Simulate failing network requests toggles are disabled
fireEvent.press(screen.getByAccessibilityHint('Force offline'));
await waitForBatchedUpdates();
expect(setShouldForceOfflineSpy).not.toHaveBeenCalled();

fireEvent.press(screen.getByAccessibilityHint('Simulate failing network requests'));
await waitForBatchedUpdates();
expect(setShouldFailAllRequestsSpy).not.toHaveBeenCalled();
});

test('connection changes tracking', async () => {
Expand Down

0 comments on commit c52234d

Please sign in to comment.