Skip to content

Commit

Permalink
Merge pull request #2732 from beckn/cypress-2448
Browse files Browse the repository at this point in the history
feat(P2P-ENERGY): added cypress test case for open spark checkout  pa…
  • Loading branch information
aniketceminds authored Dec 12, 2024
2 parents 6611348 + 0c53bb7 commit 34a00a6
Show file tree
Hide file tree
Showing 9 changed files with 478 additions and 62 deletions.
Binary file removed apps/p2p-energy/garudaa-1.0.0.tgz
Binary file not shown.
10 changes: 5 additions & 5 deletions apps/p2p-energy/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import 'react-toastify/dist/ReactToastify.css'
import '../styles/globals.css'
import { Provider } from 'react-redux'
import store, { persistor } from '@store/index'
import { Garuda } from 'garudaa'
// import { Garuda } from 'garudaa'
import { PersistGate } from 'redux-persist/integration/react'
import { FallbackUI } from '@beckn-ui/common'
import { useLanguage } from '@hooks/useLanguage'
import Router, { useRouter } from 'next/router'
import ErrorBoundary from '@beckn-ui/common/src/components/errorBoundary'

Garuda.init({
projectId: '65c0d663cbe90cafae9185f6',
host: 'https://garuda-api.becknprotocol.io'
})
// Garuda.init({
// projectId: '65c0d663cbe90cafae9185f6',
// host: 'https://garuda-api.becknprotocol.io'
// })
function MyApp({ Component, pageProps }: AppProps) {
const { t } = useLanguage()
const router = useRouter()
Expand Down
100 changes: 100 additions & 0 deletions cypress/e2e/p2p-energy/p2p-energy-checkoutPage.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { testIds } from '../../../shared/dataTestIds'
import { shippingDetails } from '../../fixtures/P2P/userDetails'

describe('Checkout Page', () => {
afterEach(() => {
cy.clearAllLocalStorage()
})
before(() => {
cy.visit(testIds.url_base)
cy.getByData(testIds.clickable_card_open_spark).click()
cy.wait(2000)
cy.intercept('POST', '**/search', {
fixture: 'P2P/searchResponse.json'
}).as('searchResponse')
cy.getByData(testIds.P2P_hompage_button).click()
cy.wait(2000)
cy.url().should('include', `${testIds.url_search}?searchTerm`)

cy.getByData(testIds.searchpage_products).first().click()
cy.url().should('include', testIds.url_product)
cy.intercept('POST', '/select', { fixture: 'P2P/selectResult.json' }).as('selectCall')
cy.getByData(testIds.productpage_addTocartButton).click()
cy.wait('@selectCall')
cy.getByData(testIds.cartpage_cartOrderButton).click()
})

it('should display the item details', () => {
cy.getByData(testIds.item_details).should('have.length', 1)
cy.getByData(testIds.item_title).should('contain.text', 'energy')
cy.getByData(testIds.item_quantity).should('contain.text', 1)
cy.getByData(testIds.item_price).should('contain.text', '₹7.00')
})
it('should check the shipping, billing, payment section rendered or not & proceed btn', () => {
cy.getByData(testIds.checkoutpage_shippingDetails).should('be.visible')
cy.getByData(testIds.checkoutpage_paymentDetails).should('not.exist')
cy.getByData(testIds.checkoutpage_proceedToCheckout).should('be.disabled')
})

it('should validate shipping form fields', () => {
cy.getByData(testIds.checkoutpage_shippingDetails).getByData(testIds.checkoutpage_openForm).click()

cy.getByData(testIds.checkoutpage_shippingDetails)
.getByData(testIds.checkoutpage_form)
.within(() => {
cy.getByData(testIds.checkoutpage_name).clear().blur()
cy.contains('Name is required').should('be.visible')

cy.getByData(testIds.meterNumber).clear().type('MT451667').blur()

cy.getByData(testIds.checkoutpage_address).clear().blur()
cy.contains('Complete Address is required').should('be.visible')

cy.getByData(testIds.checkoutpage_pinCode).clear().type('123').blur()
cy.contains('Invalid Zip Code').should('be.visible')

cy.getByData('submit').should('be.disabled')
})
cy.getByData(testIds.checkoutpage_shippingDetails).getByData(testIds.checkoutpage_form).type('{esc}')
})

it('should fill and save the shipping form data', () => {
cy.getByData(testIds.checkoutpage_shippingDetails).getByData(testIds.checkoutpage_openForm).click()
cy.getByData(testIds.checkoutpage_form).should('be.visible')

cy.getByData(testIds.checkoutpage_shippingDetails)
.getByData(testIds.checkoutpage_form)
.within(() => {
cy.getByData(testIds.checkoutpage_name).clear().type(shippingDetails.name)
cy.getByData(testIds.meterNumber).clear().type('MT451667')
cy.getByData(testIds.checkoutpage_address).clear().type(shippingDetails.address)
cy.getByData(testIds.checkoutpage_pinCode).clear().type(shippingDetails.pinCode)
cy.getByData('submit').click()
})

cy.intercept('POST', '**/init', { fixture: 'P2P/initResponse.json' }).as('initCall')
cy.wait('@initCall')
})

it('should display the payment section', () => {
cy.getByData(testIds.checkoutpage_paymentDetails).should('be.visible')
})

it('should display the payment breakup details', () => {
cy.getByData(testIds.checkoutpage_paymentDetails).within(() => {
cy.getByData('CGST').should('contain.text', 'CGST')
cy.getByData(testIds.item_price).eq(0).should('contain.text', '₹0.65')

cy.getByData('SGST').should('contain.text', 'SGST')
cy.getByData(testIds.item_price).eq(1).should('contain.text', '₹0.65')

cy.getByData(testIds.payment_totalPayment).should('contain.text', 'Total')
cy.getByData(testIds.item_price).eq(5).should('contain.text', '₹15.80')
})
})

it('should proceed to checkout when valid data is provided', () => {
cy.getByData(testIds.checkoutpage_proceedToCheckout).click()
cy.url().should('include', '/paymentMode')
})
})
53 changes: 53 additions & 0 deletions cypress/e2e/p2p-energy/paymentMode.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { testIds } from '../../../shared/dataTestIds'
describe('Payment Page', () => {
afterEach(() => {
cy.clearAllLocalStorage()
})
before(() => {
cy.visit(testIds.url_base)
cy.getByData(testIds.clickable_card_open_spark).click()
cy.wait(2000)
cy.intercept('POST', '**/search', {
fixture: 'P2P/searchResponse.json'
}).as('searchResponse')
cy.getByData(testIds.P2P_hompage_button).click()
cy.wait(2000)
cy.url().should('include', `${testIds.url_search}?searchTerm`)

cy.getByData(testIds.searchpage_products).first().click()
cy.url().should('include', testIds.url_product)
cy.intercept('POST', '/select', { fixture: 'P2P/selectResult.json' }).as('selectCall')
cy.getByData(testIds.productpage_addTocartButton).click()
cy.wait('@selectCall')
cy.getByData(testIds.cartpage_cartOrderButton).click()
cy.getByData(testIds.checkoutpage_shippingDetails).getByData(testIds.checkoutpage_openForm).click()
cy.getByData('submit').click()
cy.intercept('POST', '**/init', { fixture: 'P2P/initResponse.json' }).as('initCall')
cy.wait('@initCall')
cy.getByData(testIds.checkoutpage_proceedToCheckout).click()
cy.url().should('include', testIds.url_payment)
})

it('should display payment Page with Result', () => {
cy.contains(testIds.paymentpage_creditcardAndDebitCard).should('contain.text', 'Credit & Debit Cards')
cy.getByData(testIds.paymentpage_visa).should('contain.text', '**** **** **** 1234')
cy.getByData(testIds.paymentpage_masterCard).should('contain.text', '**** **** **** 1234')
cy.getByData(testIds.paymentpage_phonePay).should('contain.text', 'PhonePe UPI')
cy.getByData(testIds.paymentpage_NetBanking).should('contain.text', 'Adjust with Monthly Billing')
cy.getByData(testIds.paymentpage_image).should('have.attr', 'src')
})
it('should display payment method images and radio button', () => {
cy.getByData(testIds.paymentpage_radioButton).parent().find('img').should('have.length.greaterThan', 0)
})

it('should disable the confirm button when no radio button is selected', () => {
cy.getByData(testIds.paymentpage_radioButton).should('not.be.checked')
cy.getByData(testIds.paymentpage_confirmButton).contains('Confirm Order').should('be.disabled')
})

it('should navigate to the order confirmation page upon clicking confirm button', () => {
cy.getByData(testIds.paymentpage_radioButton).eq(3).check().should('be.checked')
cy.getByData(testIds.paymentpage_confirmButton).click()
cy.url().should('include', testIds.url_orderConfirmation)
})
})
Loading

0 comments on commit 34a00a6

Please sign in to comment.