-
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.
chore(Bonus Pagamenti Digitali): [#176842973] Add tests for the CoBad…
…ge components (#2826) * [#176842973] fix InternationalCircuitIconsBar naming * [#176842973] add InternationalCircuitIconsBar test * [#176842973] fix optional prop * [#176842973] add BancomatInformation component tests * [#176842973] renaming folder * [#176842973] add test * [#176842973] add CoBadgeChooseType tests * [#176842973] add missing test in BaseCoBadgeCard component * [#176842973] remove component wrapper Co-authored-by: Fabrizio <[email protected]>
- Loading branch information
1 parent
8b59304
commit 0860f77
Showing
11 changed files
with
198 additions
and
15 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
13 changes: 13 additions & 0 deletions
13
ts/components/wallet/__test__/InternationalCircuitIconsBar.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,13 @@ | ||
import { render } from "@testing-library/react-native"; | ||
import * as React from "react"; | ||
import InternationalCircuitIconsBar from "../InternationalCircuitIconsBar"; | ||
|
||
describe("InternationalCircuitIconBar component", () => { | ||
["maestro", "mastercard", "visa", "visaElectron", "vPay"].map(circuit => | ||
it(`should show the ${circuit} icon`, () => { | ||
const component = render(<InternationalCircuitIconsBar />); | ||
|
||
expect(component.queryByTestId(circuit)).not.toBeNull(); | ||
}) | ||
); | ||
}); |
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
61 changes: 61 additions & 0 deletions
61
ts/features/wallet/bancomat/screen/__tests__/BancomatInformation.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,61 @@ | ||
import { fireEvent, render } from "@testing-library/react-native"; | ||
import * as React from "react"; | ||
import { Provider } from "react-redux"; | ||
import configureMockStore from "redux-mock-store"; | ||
import BancomatInformation from "../BancomatInformation"; | ||
|
||
const mockPresentFn = jest.fn(); | ||
jest.mock("../../utils/bancomatInformationBottomSheet", () => ({ | ||
__esModule: true, | ||
default: () => ({ present: mockPresentFn }) | ||
})); | ||
|
||
describe("BancomatInformation component", () => { | ||
it("should show the InternationalCircuitIconsBar", () => { | ||
const onAddPaymentMethod = jest.fn(); | ||
const component = getComponent(onAddPaymentMethod); | ||
const internationalCircuitIconsBar = component.queryByTestId( | ||
"internationalCircuitIconsBar" | ||
); | ||
|
||
expect(internationalCircuitIconsBar).not.toBeNull(); | ||
}); | ||
|
||
it("should call the present function when click on notice icon", () => { | ||
const onAddPaymentMethod = jest.fn(); | ||
const component = getComponent(onAddPaymentMethod); | ||
const ioNoticeIcon = component.queryByTestId("noticeIconFont"); | ||
|
||
expect(ioNoticeIcon).not.toBeNull(); | ||
|
||
if (ioNoticeIcon !== null) { | ||
fireEvent.press(ioNoticeIcon); | ||
expect(mockPresentFn).toHaveBeenCalledTimes(1); | ||
} | ||
}); | ||
it("should call the onAddPaymentMethod function when click on addPaymentMethod button", () => { | ||
const onAddPaymentMethod = jest.fn(); | ||
const component = getComponent(onAddPaymentMethod); | ||
const addPaymentMethodButton = component.queryByTestId( | ||
"addPaymentMethodButton" | ||
); | ||
|
||
expect(addPaymentMethodButton).not.toBeNull(); | ||
|
||
if (addPaymentMethodButton !== null) { | ||
fireEvent.press(addPaymentMethodButton); | ||
expect(onAddPaymentMethod).toHaveBeenCalledTimes(1); | ||
} | ||
}); | ||
}); | ||
|
||
const getComponent = (onAddPaymentMethod: () => void) => { | ||
const mockStore = configureMockStore(); | ||
|
||
const store: ReturnType<typeof mockStore> = mockStore(); | ||
return render( | ||
<Provider store={store}> | ||
<BancomatInformation onAddPaymentMethod={onAddPaymentMethod} /> | ||
</Provider> | ||
); | ||
}; |
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
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
File renamed without changes.
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
83 changes: 83 additions & 0 deletions
83
ts/features/wallet/onboarding/cobadge/screens/__tests__/CoBadgeChooseType.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,83 @@ | ||
import { fireEvent } from "@testing-library/react-native"; | ||
import { none } from "fp-ts/lib/Option"; | ||
import { NavigationActions, NavigationParams } from "react-navigation"; | ||
import configureMockStore from "redux-mock-store"; | ||
import ROUTES from "../../../../../../navigation/routes"; | ||
import { applicationChangeState } from "../../../../../../store/actions/application"; | ||
import { appReducer } from "../../../../../../store/reducers"; | ||
import { GlobalState } from "../../../../../../store/reducers/types"; | ||
import { renderScreenFakeNavRedux } from "../../../../../../utils/testWrapper"; | ||
import WALLET_ONBOARDING_COBADGE_ROUTES from "../../navigation/routes"; | ||
import CoBadgeChooseType from "../CoBadgeChooseType"; | ||
|
||
jest.mock("react-native-share", () => ({ | ||
open: jest.fn() | ||
})); | ||
describe("CoBadgeChooseType component", () => { | ||
beforeEach(() => jest.useFakeTimers()); | ||
it("should dispatch navigateToWalletAddCreditCard action if press the enabled item", () => { | ||
const { component, store } = getComponent(undefined, 1); | ||
const enabledItem = component.queryByTestId("enabledItem"); | ||
|
||
expect(component).not.toBeNull(); | ||
expect(enabledItem).not.toBeNull(); | ||
|
||
const expectedPayload = [ | ||
{ | ||
type: NavigationActions.BACK, | ||
key: undefined | ||
}, | ||
{ | ||
type: NavigationActions.NAVIGATE, | ||
routeName: ROUTES.WALLET_ADD_CARD, | ||
params: { inPayment: none } | ||
} | ||
]; | ||
|
||
if (enabledItem) { | ||
fireEvent.press(enabledItem); | ||
expect(store.getActions()).toEqual(expectedPayload); | ||
} | ||
}); | ||
it("should dispatch walletAddCoBadgeStart action if press disabled or unknown item", () => { | ||
const anAbi = "1234"; | ||
const { component, store } = getComponent(anAbi, 1); | ||
const disabledItem = component.queryByTestId("disabledItem"); | ||
const unknownItem = component.queryByTestId("unknownItem"); | ||
|
||
expect(disabledItem).not.toBeNull(); | ||
expect(unknownItem).not.toBeNull(); | ||
|
||
const expectedPayload = { | ||
type: WALLET_ONBOARDING_COBADGE_ROUTES.START, | ||
payload: anAbi | ||
}; | ||
if (disabledItem) { | ||
fireEvent.press(disabledItem); | ||
expect(store.getActions()).toEqual([expectedPayload]); | ||
} | ||
if (unknownItem) { | ||
fireEvent.press(unknownItem); | ||
expect(store.getActions()).toEqual([expectedPayload, expectedPayload]); | ||
} | ||
}); | ||
}); | ||
|
||
const getComponent = (abi?: string, legacyAddCreditCardBack?: number) => { | ||
const globalState = appReducer(undefined, applicationChangeState("active")); | ||
|
||
const mockStore = configureMockStore<GlobalState>(); | ||
const store: ReturnType<typeof mockStore> = mockStore({ | ||
...globalState | ||
} as GlobalState); | ||
|
||
return { | ||
component: renderScreenFakeNavRedux<GlobalState, NavigationParams>( | ||
CoBadgeChooseType, | ||
ROUTES.WALLET_BPAY_DETAIL, | ||
{ abi, legacyAddCreditCardBack }, | ||
store | ||
), | ||
store | ||
}; | ||
}; |
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