-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
7,228 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
ts/features/fims/history/components/__mocks__/FimsHistoryListItemPicker.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Text } from "react-native"; | ||
|
||
export const FimsHistoryListItemPicker = () => ( | ||
<Text>TESTING LIST ITEM FROM PICKER</Text> | ||
); |
3 changes: 3 additions & 0 deletions
3
ts/features/fims/history/components/__mocks__/FimsHistoryLoaders.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import { Text } from "react-native"; | ||
|
||
export const LoadingFimsHistoryListItem = () => <Text>LOADING_LIST_ITEM</Text>; | ||
export const LoadingFimsHistoryItemsFooter = () => ( | ||
<Text testID="testing-footer">LOADING_FOOTER</Text> | ||
); |
187 changes: 187 additions & 0 deletions
187
ts/features/fims/history/components/__tests__/FimsHistoryNonEmptyContent.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
jest.mock("../../hooks/useFimsHistoryResultToasts.tsx"); | ||
jest.mock("../FimsHistoryLoaders.tsx"); | ||
jest.mock("../FimsHistoryListItemPicker.tsx"); | ||
|
||
import * as pot from "@pagopa/ts-commons/lib/pot"; | ||
import { fireEvent } from "@testing-library/react-native"; | ||
import { createStore } from "redux"; | ||
import { AccessHistoryPage } from "../../../../../../definitions/fims_history/AccessHistoryPage"; | ||
import { | ||
remoteLoading, | ||
remoteReady | ||
} from "../../../../../common/model/RemoteValue"; | ||
import { applicationChangeState } from "../../../../../store/actions/application"; | ||
import { appReducer } from "../../../../../store/reducers"; | ||
import { GlobalState } from "../../../../../store/reducers/types"; | ||
import { renderScreenWithNavigationStoreContext } from "../../../../../utils/testWrapper"; | ||
import { FIMS_ROUTES } from "../../../common/navigation"; | ||
import { | ||
FimsHistoryNonEmptyContent, | ||
FimsHistoryNonEmptyContentProps | ||
} from "../FimsHistoryNonEmptyContent"; | ||
import * as HOOK from "../../hooks/useFimsHistoryResultToasts"; | ||
|
||
const mockAccess = { | ||
id: "TESTING", | ||
redirect: { display_name: "TESTING", uri: "TESTING" }, | ||
service_id: "TESTING_SID", | ||
timestamp: new Date(0) | ||
}; | ||
|
||
const mockAccesses: AccessHistoryPage = { | ||
data: [mockAccess] | ||
}; | ||
const mockEmptyAccesses: AccessHistoryPage = { | ||
data: [] | ||
}; | ||
|
||
// ------------------- UTILS | ||
|
||
const generateMockStoreForSelectors = ( | ||
isHistoryLoading: boolean, | ||
isHistoryExporting: boolean | ||
) => | ||
({ | ||
features: { | ||
fims: { | ||
history: { | ||
historyExportState: isHistoryExporting | ||
? remoteLoading | ||
: remoteReady("SUCCESS"), | ||
consentsList: isHistoryLoading ? pot.someLoading({}) : pot.none | ||
} | ||
} | ||
} | ||
} as GlobalState); | ||
const renderComponent = ( | ||
props: FimsHistoryNonEmptyContentProps, | ||
mockState: GlobalState | ||
) => { | ||
const globalState = appReducer(mockState, applicationChangeState("active")); | ||
|
||
return renderScreenWithNavigationStoreContext( | ||
() => <FimsHistoryNonEmptyContent {...props} />, | ||
FIMS_ROUTES.HISTORY, | ||
{}, | ||
createStore(appReducer, globalState as any) | ||
); | ||
}; | ||
|
||
// --------------- END UTILS | ||
|
||
// eslint-disable-next-line sonarjs/cognitive-complexity | ||
describe("fimsHistoryNonEmptyContent", () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
for (const historyLoading of [true, false]) { | ||
for (const historyExporting of [true, false]) { | ||
for (const hasAccesses of [true, false]) { | ||
const fetchMore = jest.fn(); | ||
const shouldShowLoadingListFooter = historyLoading; | ||
const shouldRenderPageFooter = !historyLoading || hasAccesses; // component logic is !( hLoading && !accesses ) | ||
const store = generateMockStoreForSelectors( | ||
historyLoading, | ||
historyExporting | ||
); | ||
|
||
const testString = `${+hasAccesses} accesses, historyLoading = ${historyLoading} and historyExporting = ${historyExporting}`; | ||
|
||
it(`should fetch automatically to try and fill the list, and match snapshot for ${testString} `, () => { | ||
const component = renderComponent( | ||
{ | ||
accesses: hasAccesses ? mockAccesses : mockEmptyAccesses, | ||
fetchMore | ||
}, | ||
store | ||
); | ||
expect(component).toBeTruthy(); | ||
expect(component).toMatchSnapshot(); | ||
expect(fetchMore).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
if (shouldShowLoadingListFooter) { | ||
it(`should render list footer in case of ${testString} `, () => { | ||
const component = renderComponent( | ||
{ | ||
accesses: hasAccesses ? mockAccesses : mockEmptyAccesses, | ||
fetchMore | ||
}, | ||
store | ||
); | ||
|
||
expect(component.queryByTestId("testing-footer")).toBeTruthy(); | ||
}); | ||
} else { | ||
it(`should not render list footer in case of ${testString} `, () => { | ||
const component = renderComponent( | ||
{ | ||
accesses: hasAccesses ? mockAccesses : mockEmptyAccesses, | ||
fetchMore | ||
}, | ||
store | ||
); | ||
|
||
expect(component.queryByTestId("testing-footer")).toBeNull(); | ||
}); | ||
} | ||
|
||
if (shouldRenderPageFooter) { | ||
it(`should render export footer in case of ${testString} `, () => { | ||
const component = renderComponent( | ||
{ | ||
accesses: hasAccesses ? mockAccesses : mockEmptyAccesses, | ||
fetchMore | ||
}, | ||
store | ||
); | ||
|
||
expect(component.queryByTestId("export-footer")).toBeTruthy(); | ||
}); | ||
|
||
const isPageFooterLoading = historyExporting; | ||
|
||
it(`should ${ | ||
isPageFooterLoading ? "not" : "" | ||
} dispatch the onPress if the user taps the primary action in case of ${testString}`, () => { | ||
const mockFetchMore = jest.fn(); | ||
jest.spyOn(HOOK, "useFimsHistoryExport").mockReturnValue({ | ||
handleExportOnPress: mockFetchMore | ||
}); | ||
|
||
const component = renderComponent( | ||
{ | ||
accesses: hasAccesses ? mockAccesses : mockEmptyAccesses, | ||
fetchMore | ||
}, | ||
store | ||
); | ||
|
||
const renderedComponent = component.getByTestId("export-button"); | ||
expect(renderedComponent).toBeTruthy(); | ||
|
||
fireEvent.press(renderedComponent); | ||
|
||
expect(mockFetchMore).toHaveBeenCalledTimes( | ||
isPageFooterLoading ? 0 : 1 | ||
); | ||
}); | ||
} else { | ||
it(`should not render export footer in case of ${testString} `, () => { | ||
const component = renderComponent( | ||
{ | ||
accesses: hasAccesses ? mockAccesses : mockEmptyAccesses, | ||
fetchMore | ||
}, | ||
store | ||
); | ||
|
||
expect(component.queryByTestId("export-footer")).toBeNull(); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
}); |
Oops, something went wrong.