Untitled
user_1697073
plain_text
7 months ago
17 kB
6
Indexable
Never
import { defineFeature, loadFeature } from "jest-cucumber"; import { shallow, ShallowWrapper } from "enzyme"; import * as helpers from "../../../../framework/src/Helpers"; import React from "react"; import Catalogue from "../../src/Catalogue"; import MessageEnum, { getName, } from "../../../../framework/src/Messages/MessageEnum"; import { Message } from "../../../../framework/src/Message"; import { runEngine } from "../../../../framework/src/RunEngine"; import * as storageData from "../../../../framework/src/Utilities"; const screenProps = { navigation: { navigate: jest.fn(), goBack: jest.fn(), state: { routeName: "Catalogue", params: { newHome: "Home", }, }, }, id: "Catalogue", }; const screenProps2 = { navigation: { navigate: jest.fn(), goBack: jest.fn(), state: { routeName: "Catalogue", params: { newHome: "Home", }, }, }, id: "Catalogue", }; const feature = loadFeature("./__tests__/features/catalogue-scenario.feature"); const mockGetStorageData = jest.spyOn(storageData, "getStorageData"); defineFeature(feature, (test) => { beforeEach(() => { jest.resetModules(); jest.doMock("react-native", () => ({ Platform: { OS: "web" } })); jest.spyOn(helpers, "getOS").mockImplementation(() => "web"); }); test("User navigates to catalogue", ({ given, when, then }) => { let exampleBlockA: ShallowWrapper; let exampleBlockA2: ShallowWrapper; let instance: Catalogue; given("I am a User loading catalogue", () => { exampleBlockA = shallow(<Catalogue {...screenProps} />); exampleBlockA2 = shallow(<Catalogue {...screenProps2} />); }); when("I navigate to the catalogue", () => { instance = exampleBlockA.instance() as Catalogue; const getHomeApi = new Message( getName(MessageEnum.RestAPIResponceMessage) ); getHomeApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), getHomeApi ); getHomeApi.addData( getName(MessageEnum.RestAPIResponceSuccessMessage), JSON.parse( JSON.stringify({ catalogue: { data: { id: "1", }, }, }) ) ); getHomeApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), getHomeApi.messageId ); const getHomeApiError = new Message( getName(MessageEnum.RestAPIResponceMessage) ); getHomeApiError.addData( getName(MessageEnum.RestAPIResponceDataMessage), getHomeApiError ); getHomeApiError.addData( getName(MessageEnum.RestAPIResponceErrorMessage), [{}] ); getHomeApiError.addData( getName(MessageEnum.RestAPIResponceDataMessage), getHomeApiError.messageId ); const getHomeApiUpdate = new Message( getName(MessageEnum.RestAPIResponceMessage) ); getHomeApiUpdate.addData( getName(MessageEnum.RestAPIResponceDataMessage), getHomeApiUpdate ); getHomeApiUpdate.addData( getName(MessageEnum.RestAPIResponceSuccessMessage), JSON.parse( JSON.stringify({ catalogue: { data: { id: "1", }, }, }) ) ); getHomeApiUpdate.addData( getName(MessageEnum.RestAPIResponceDataMessage), getHomeApiUpdate.messageId ); instance.updateHomeDetail = getHomeApiUpdate.messageId; instance.getHomePriceAPICallId = getHomeApi.messageId; instance.addCarDetailAPICallId = getHomeApi.messageId; instance.addHomePricingAPICallId = getHomeApi.messageId; runEngine.sendMessage("Unit Test", getHomeApi); runEngine.sendMessage("Unit Test", getHomeApiUpdate); instance.addHomePricingAPICallId = getHomeApiError.messageId; runEngine.sendMessage("Unit Test", getHomeApiError); }); then("catalogue will load without errors", () => { expect(exampleBlockA).toBeTruthy(); }); then("I can render FlatList without error", () => { const addHomeDetailsApiCall = new Message( getName(MessageEnum.RestAPIResponceMessage) ); addHomeDetailsApiCall.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApiCall ); addHomeDetailsApiCall.addData( getName(MessageEnum.RestAPIResponceSuccessMessage), { data: [ { id: "1", attributes: { category: "Home", }, }, ], } ); addHomeDetailsApiCall.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApiCall.messageId ); instance.getCategoryApiCall = addHomeDetailsApiCall.messageId; instance.getHomeCarListingApiCall = addHomeDetailsApiCall.messageId; runEngine.sendMessage("Unit Test", addHomeDetailsApiCall); let flatList = exampleBlockA.findWhere( (node) => node.prop("testID") === "arrayList" ); let flatListRender = shallow( flatList.props().renderItem({ item: { id: "1", attributes: { id: "1", name: "Luxury Mansion 1", price: "$500 / NIGHT", distance: "2 mi", images: [], wishlist_liked: true, features: { home_title: "home_title", }, address: { id: "1", }, }, }, }) ); let onPressspaceTypeBtn = flatListRender.findWhere( (node) => node.prop("testID") === "addWishList-1" ); onPressspaceTypeBtn.simulate("press"); flatListRender = shallow( flatList.props().renderItem({ item: { id: "1", attributes: { id: "", name: "Luxury Mansion 1", price: "$500 / NIGHT", distance: "2 mi", images: [], wishlist_liked: false, features: { home_title: "home_title", }, address: { id: "1", }, }, }, }) ); let onPressspaceType = flatListRender.findWhere( (node) => node.prop("testID") === "addWishList-1" ); onPressspaceType.simulate("press"); let carousel = flatListRender.findWhere( (node) => node.prop("testID") === "carousel" ); carousel.props().renderItem({ item: { url: "url", }, }); let Emptycarousel = flatListRender.findWhere( (node) => node.prop("testID") === "carousel" ); Emptycarousel.props().renderItem({ item: {}, }); const addHomeDetailsApi = new Message( getName(MessageEnum.RestAPIResponceMessage) ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceSuccessMessage), [] ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi.messageId ); instance.addWishListAPi = addHomeDetailsApi.messageId; runEngine.sendMessage("Unit Test", addHomeDetailsApi); }); then("User can delete the item from wishlist", () => { const addHomeDetailsApi = new Message( getName(MessageEnum.RestAPIResponceMessage) ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceSuccessMessage), [] ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi.messageId ); instance.deleteItemApiCallId = addHomeDetailsApi.messageId; runEngine.sendMessage("Unit Test", addHomeDetailsApi); }); then("I can check all the functions rendering without error", () => { instance.goBack(); }); then("User can set car ID successfully", () => { const addHomeDetailsApi = new Message( getName(MessageEnum.RestAPIResponceMessage) ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceSuccessMessage), [ { id: "1", name: "Car", }, ] ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi.messageId ); instance.getCategoryApiCall = addHomeDetailsApi.messageId; runEngine.sendMessage("Unit Test", addHomeDetailsApi); }); then("User can handle the home car listing", () => { const addHomeDetailsApi = new Message( getName(MessageEnum.RestAPIResponceMessage) ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceSuccessMessage), { error: 'error' } ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi.messageId ); instance.getHomeCarListingApiCall = addHomeDetailsApi.messageId; runEngine.sendMessage("Unit Test", addHomeDetailsApi); }); then("User can set home ID successfully", () => { const addHomeDetailsApi = new Message( getName(MessageEnum.RestAPIResponceMessage) ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceSuccessMessage), [ { id: "2", name: "Home", }, ] ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi.messageId ); instance.getCategoryApiCall = addHomeDetailsApi.messageId; instance.getHomeCarListingApiCall = addHomeDetailsApi.messageId; runEngine.sendMessage("Unit Test", addHomeDetailsApi); }); then("I should get token properly", async () => { mockGetStorageData.mockResolvedValue(`"renter"`); const addHomeDetails = new Message( getName(MessageEnum.RestAPIResponceMessage) ); addHomeDetails.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetails ); addHomeDetails.addData( getName(MessageEnum.RestAPIResponceSuccessMessage), { message: "message" } ); addHomeDetails.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetails.messageId ); instance.getHomeCarListingApiCall = addHomeDetails.messageId; runEngine.sendMessage("Unit Test", addHomeDetails); const tokenMsg: Message = new Message( getName(MessageEnum.SessionResponseMessage) ); tokenMsg.addData( getName(MessageEnum.SessionResponseToken), "token-string" ); runEngine.sendMessage("Unit Test", tokenMsg); const addHomeDetailsApi = new Message( getName(MessageEnum.RestAPIResponceMessage) ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceSuccessMessage), JSON.parse( JSON.stringify({ data: [ { item: { attributes: { name: "Home", }, }, }, ], }) ) ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi.messageId ); instance.getHomeCarListingApiCall = addHomeDetailsApi.messageId; runEngine.sendMessage("Unit Test", addHomeDetailsApi); await new Promise((resolve) => setImmediate(resolve)); }); then("User can open the search modal successfully", () => { let searchModal = exampleBlockA.findWhere( (node) => node.prop("testID") === "searchModal" ); searchModal.props().oncloseModal(); searchModal.props().decreaseGusetsNumber(); searchModal.props().goToSearchScreen(); searchModal.props().increaseGuestsNumber(); searchModal.props().openCalendar(); searchModal.props().callApi(); }); then("User can get the searched place list successfully", () => { const addHomeDetailsApi = new Message( getName(MessageEnum.RestAPIResponceMessage) ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceSuccessMessage), JSON.parse( JSON.stringify({ data: [ { item: { attributes: { name: "Home", }, }, }, ], }) ) ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi.messageId ); instance.searchCatalogueApiCallId = addHomeDetailsApi.messageId; runEngine.sendMessage("Unit Test", addHomeDetailsApi); }); then("User as renter can get the Home and car listing without errors", () => { const addHomeDetailsApi = new Message( getName(MessageEnum.RestAPIResponceMessage) ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceSuccessMessage), JSON.parse( JSON.stringify({ catalogue: { data: [ { item: { attributes: { name: "Home", }, }, }, ], } }) ) ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi.messageId ); instance.getHomeCarListingRenterApiCall = addHomeDetailsApi.messageId; runEngine.sendMessage("Unit Test", addHomeDetailsApi); }); then("User as renter can handle the error of home and car listing", () => { const addHomeDetailsApi = new Message( getName(MessageEnum.RestAPIResponceMessage) ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceSuccessMessage), JSON.parse( JSON.stringify({ error: 'error' }) ) ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi.messageId ); instance.getHomeCarListingRenterApiCall = addHomeDetailsApi.messageId; runEngine.sendMessage("Unit Test", addHomeDetailsApi); }); then("User as renter gets the Home and car listing empty", () => { const addHomeDetailsApi = new Message( getName(MessageEnum.RestAPIResponceMessage) ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceSuccessMessage), JSON.parse( JSON.stringify({ message: "message" }) ) ); addHomeDetailsApi.addData( getName(MessageEnum.RestAPIResponceDataMessage), addHomeDetailsApi.messageId ); instance.getHomeCarListingRenterApiCall = addHomeDetailsApi.messageId; runEngine.sendMessage("Unit Test", addHomeDetailsApi); }); then("I can leave the screen without errors", () => { instance.componentWillUnmount(); expect(exampleBlockA).toBeTruthy(); }); }); });
Leave a Comment