Skip to content

Commit

Permalink
feat(mobility-bap): add cypress tests for mobility homepage, cancel s…
Browse files Browse the repository at this point in the history
…earch
  • Loading branch information
aniketceminds committed Oct 8, 2024
1 parent 0542210 commit f5a728d
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const BottomModalRenderer = (props: BottomModalRendererProps) => {
return (
<BecknButton
text="Cancel Search"
dataTest={testIds.mobility_cancel_search}
variant="outline"
handleClick={handleClickOnCancelSearch}
/>
Expand Down
88 changes: 88 additions & 0 deletions cypress/e2e/mobility-bap/homePage.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { testIds } from '../../../shared/dataTestIds'

describe('Home Page Tests', () => {
before(() => {
cy.visit(`${testIds.url_base}${testIds.url_home}`)
cy.setGeolocation('getAddress', { latitude: 18.6087413, longitude: 73.75189209999999 }, 'mobility-bap/address.json')
cy.wait('@getAddress')
})

it('should render homepage with google map', () => {
cy.getByData(testIds.mobility_map_container).should('be.visible')
cy.getByData(testIds.mobility_map).should('be.visible')
})

it('should render the pickup-dropoff modal', () => {
cy.getByData(testIds.mobility_pickup_dropoff).should('be.visible')
cy.getByData(testIds.mobility_pickup_dropoff).should('contain.text', 'Where Would You Like To Go?')
cy.getByData(testIds.mobility_pickup_label).should('contain.text', 'Pickup')
cy.getByData(testIds.mobility_dropoff_label).should('contain.text', 'Dropoff')
})

it('should contain pickup address on load', () => {
cy.getByData(testIds.mobility_pickup_label).should('contain.text', 'Pickup')
cy.getByData(testIds.mobility_pickup_address).should('contain.text', 'Decathlon Sports Wakad')
})

it('should contain empty dropoff address on load', () => {
cy.getByData(testIds.mobility_dropoff_label).should('contain.text', 'Dropoff')
cy.getByData(testIds.mobility_dropoff_address).should('contain.text', '')
})

it('The search button should render as disabled on initial load', () => {
cy.getByData(testIds.mobility_search_btn).should('be.disabled')
})

it('should render the geolocation search component onclick of dropoff field', () => {
cy.getByData(testIds.mobility_dropoff_address).click()
cy.getByData(testIds.loaction_list).should('be.visible')
})

it('should render the location list on input change', () => {
cy.getByData(testIds.loaction_list).should('be.visible')
cy.getByData(testIds.loaction_list).type('Maharashtra Cricket Association Stadium')
cy.getByData(testIds.location_list_item).should('be.visible')
})

it('should update the dropoff address on select', () => {
cy.getByData(testIds.location_list_item).should('be.visible').eq(0).click()
cy.getByData(testIds.mobility_dropoff_address).should('contain.text', 'Maharashtra Cricket Association Stadium')
})

it('search button should be enabled when both drop-off and pickup addresses are set', () => {
cy.getByData(testIds.mobility_search_btn).should('not.be.disabled')
})

it('should check for violation for drop-off and pickup when search button click', () => {
cy.performCheckViolation(
{
policyCheckResult: [
{
location: '18.6744633,73.7065161',
violation: false,
violatedPolicies: [
{
id: '6b298',
name: 'Quarantine Policy'
}
]
}
]
},
'checkViolation'
)
cy.getByData(testIds.mobility_search_btn).click()
cy.getByData(testIds.mobility_cancel_search).should('be.visible')
cy.getByData(testIds.mobility_cancel_search).should('contain.text', 'Cancel Search')
})

it('should cancel the search when the user clicks the cancel button', () => {
cy.getByData(testIds.mobility_cancel_search).click()
cy.getByData(testIds.mobility_search_btn).should('not.be.disabled')
cy.getByData(testIds.mobility_cancel_search).should('not.exist')
})

it('should render the toast when the user cancels the search', () => {
cy.getByData(testIds.feedback).should('contain.text', 'Cab search request canceled.')
})
})
16 changes: 16 additions & 0 deletions cypress/fixtures/mobility-bap/address.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"ok": true,
"status": 200,
"results": [
{
"address_components": [
{
"long_name": "India",
"short_name": "IN",
"types": ["country", "political"]
}
],
"formatted_address": "Decathlon Sports Wakad, Tathawade Road, Tathawade, Pimpri-Chinchwad, Maharashtra, India"
}
]
}
31 changes: 20 additions & 11 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ declare global {
interface Chainable<Subject = any> {
getByData(dataTestAttribute: string): Chainable<JQuery<HTMLElement>>
login(baseUrl: string, email: string, password: string): Chainable<void>
setGeolocation(aliasName: string): Chainable<void>
setGeolocation(aliasName: string, location: { latitude: number; longitude: number }, data?: any): Chainable<void>
performSearch(searchTerm: string, response: RouteHandler): Chainable<void>
mockReduxState(type: string, data: Record<string, any>): Chainable<void>
selectProduct(index: number): Chainable<void>
Expand All @@ -78,6 +78,7 @@ declare global {
fillConsentDetails(): Chainable<void>
fillAssemblyDetails(): Chainable<void>
performXinput_Submit(response: RouteHandler, aliasName: string): Chainable<void>
performCheckViolation(response: RouteHandler, aliasName: string): Chainable<void>
//Created by omkar
loginDynamic(email: string, password: string): Chainable<void>
performSearchDynamic(searchTerm: string): Chainable<void>
Expand All @@ -89,6 +90,7 @@ const GCL_URL = 'https://bap-gcl-**.becknprotocol.io'
const STRAPI_URL = 'https://bap-backend-**.becknprotocol.io/api'
const XINPUT_SUBMIT = 'https://bpp-unified-strapi-dev.becknprotocol.io/beckn-bpp-adapter/x-input'
const S3Integration_URL = 'https://bap-s3integration-api-dev.becknprotocol.io'
const CHECK_VIOLATION_URL = 'https://bpp-unified-strapi-dev.becknprotocol.io/policy-violation/bap'

Cypress.Commands.add('getByData', selector => {
return cy.get(`[data-test=${selector}]`)
Expand Down Expand Up @@ -123,17 +125,20 @@ Cypress.Commands.add('login', (baseUrl, email, password) => {
)
})

Cypress.Commands.add('setGeolocation', aliasName => {
cy.window().then(win => {
cy.intercept('GET', '**/maps.googleapis.com/maps/api/geocode/json*', {
fixture: 'homePage/address.json'
}).as(aliasName as string)
cy.stub(win.navigator.geolocation, 'getCurrentPosition').callsFake(success => {
success({ coords: { latitude: 28.4594965, longitude: 77.0266383 } })
Cypress.Commands.add(
'setGeolocation',
(aliasName, location = { latitude: 28.4594965, longitude: 77.0266383 }, data = 'homePage/address.json') => {
cy.window().then(win => {
cy.intercept('GET', '**/maps.googleapis.com/maps/api/geocode/json*', {
fixture: data
}).as(aliasName as string)
cy.stub(win.navigator.geolocation, 'getCurrentPosition').callsFake(success => {
success({ coords: location })
})
})
})
cy.wait(500)
})
cy.wait(500)
}
)

Cypress.Commands.add('performSearch', (searchTerm, response) => {
const searchInputId = 'search-input'
Expand Down Expand Up @@ -229,6 +234,10 @@ Cypress.Commands.add('performXinput_Submit', (response, aliasName) => {
cy.intercept('POST', `${GCL_URL}/x-input/submit`, response).as(aliasName)
})

Cypress.Commands.add('performCheckViolation', (response, aliasName) => {
cy.intercept('POST', `${CHECK_VIOLATION_URL}/policy/checkViolation`, response).as(aliasName)
})

Cypress.Commands.add('fillComplaintDetails', complaintDetails => {
cy.getByData(testIds.checkoutpage_complaints_Details).getByData(testIds.checkoutpage_openForm).eq(0).click()
cy.getByData(testIds.checkoutpage_complaints_Details)
Expand Down
3 changes: 2 additions & 1 deletion shared/dataTestIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ const testIds = {
job_details_name: 'job-details-name',
job_details_provider_name: 'job-details-provider-name',
job_details_description: 'job-details-description',
job_details_apply: 'job-details-apply'
job_details_apply: 'job-details-apply',
mobility_cancel_search: 'cancel-search'
}

export { testIds }

0 comments on commit f5a728d

Please sign in to comment.