Files
iNaturalistReactNative/tests/unit/components/SharedComponents/UploadStatus/UploadStatus.test.js
Amanda Bullington aa167c669d Refactor upload functionality into hook/zustand (#1606)
* Refactor upload code into hook and zustand slice

* Create a single source of truth for toolbar and individual progress

* Fix unit tests

* Fix more tests

* Continue trying to simplify upload progress and status code

* Continued overhaul of upload code

* Fix exclamation point in Toolbar

* Fix total toolbar progress

* Fix tests

* Update snapshots

* Code cleanup

* Update MyObs test

* Fix most tests by not deleting realm

* Keep attempting to make toolbar text clear in subsequent tests

* Mock Zustand and reset state after all tests

In theory this should make testing with Zustand simpler. The real kicker is
that resetting state will fail if we're not careful about manually replacing
nested objects in Zustand state updates.

* Bugfix: removeAllFilesFromDirectory works with File objects, not raw paths

* Update status text when uploads canceled

* Only show red exclamation rotating icon after all uploads attempted

* Fix progress bar with zustand nested object

* Fix toolbar progress

---------

Co-authored-by: Ken-ichi Ueda <kenichi.ueda@gmail.com>
2024-05-30 20:36:50 -07:00

90 lines
2.5 KiB
JavaScript

import { render, screen } from "@testing-library/react-native";
import { UploadStatus } from "components/SharedComponents";
import React from "react";
import useStore from "stores/useStore";
import faker from "tests/helpers/faker";
const initialStoreState = useStore.getState( );
beforeAll( ( ) => {
useStore.setState( initialStoreState, true );
} );
jest.mock( "react-native-circular-progress-indicator", () => "CircularProgress" );
const mockUUID = faker.string.uuid( );
jest.mock( "react-native/Libraries/Animated/NativeAnimatedHelper" );
describe( "UploadStatus", () => {
it( "does not show progress bar when progress is less than 5%", async () => {
useStore.setState( {
totalUploadProgress: [
{
uuid: mockUUID,
totalProgress: 0.01
}
]
} );
render( <UploadStatus uuid={mockUUID} color="#454545" completeColor="#77b300" /> );
expect( screen.queryByTestId( "UploadStatus.CircularProgress" ) ).toBeFalsy();
} );
it( "shows progress bar when progress is greater than 5%", async () => {
useStore.setState( {
totalUploadProgress: [
{
uuid: mockUUID,
totalProgress: 0.5
}
]
} );
render( <UploadStatus uuid={mockUUID} color="#454545" completeColor="#77b300" /> );
expect( screen.getByTestId( "UploadStatus.CircularProgress" ) ).toBeTruthy();
} );
it( "displays progress bar when progress is less than 5% correctly", async () => {
useStore.setState( {
totalUploadProgress: [
{
uuid: undefined,
totalProgress: 0.01
}
]
} );
render( <UploadStatus uuid={undefined} color="#454545" completeColor="#77b300" /> );
// Snapshot test
expect( screen ).toMatchSnapshot();
} );
it( "displays progress bar when progress is greater than 5% correctly", async () => {
useStore.setState( {
totalUploadProgress: [
{
uuid: undefined,
totalProgress: 0.5
}
]
} );
render( <UploadStatus uuid={undefined} color="#454545" completeColor="#77b300" /> );
// Snapshot test
expect( screen ).toMatchSnapshot();
} );
it( "has no accessibility errors", () => {
useStore.setState( {
totalUploadProgress: [
{
uuid: mockUUID,
totalProgress: 0.5
}
]
} );
const uploadStatus = (
<UploadStatus uuid={mockUUID} color="#454545" completeColor="#77b300" />
);
expect( uploadStatus ).toBeAccessible();
} );
} );