Skip to content

Commit

Permalink
feat(P2P-ENERGY): added cypress test case for open spark cart page in…
Browse files Browse the repository at this point in the history
… p2p
  • Loading branch information
imrthr committed Dec 6, 2024
1 parent 5ab673f commit c074d2e
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 3 deletions.
66 changes: 66 additions & 0 deletions cypress/e2e/p2p-energy/p2p-energy-cart.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { testIds } from '../../../shared/dataTestIds'

describe('Open spark Cart Page Tests in p2p-energy', () => {
beforeEach(() => {
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')
})
afterEach(() => {
cy.clearAllLocalStorage()
})
context('should render When there are Items in Cart', () => {
it('should render and display cart page with result', () => {
cy.getByData(testIds.cartpage_itemImage).should('have.attr', 'src')
cy.getByData(testIds.cartpage_itemName).should('be.visible')
cy.getByData(testIds.cartpage_productPrice).should('be.visible')
cy.getByData(testIds.cartpage_trashButton).should('be.visible')
cy.getByData(testIds.cartpage_incrementButton).should('be.visible')
cy.getByData(testIds.cartpage_input).should('have.value', '1')
cy.url().should('include', testIds.url_cart)
})
it('should render and display cart page Order Summary ', () => {
cy.getByData(testIds.cartpage_orderSummaryText).should('contain.text', 'Order Summary')
cy.getByData(testIds.cartpage_totalQuantityText).should('contain.text', 'Total Quantity')
cy.getByData(testIds.cartpage_totalAmountText).should('contain.text', 'Total Amount')
})

it('should render the cart page when counter is one and trash button is clicked', () => {
cy.getByData(testIds.cartpage_trashButton).click()
cy.url().should('include', testIds.url_cart)
cy.getByData(testIds.cartpage_emptyImage).should('have.attr', 'src')
cy.getByData(testIds.cartpage_emptyheading).should('contain.text', 'The Cart is Empty')
cy.getByData(testIds.cartpage_emptySubHeading).should(
'contain.text',
'Looks like you haven’t made your choice yet'
)
cy.getByData(testIds.cartpage_emptyButton).should('contain.text', 'Shop')
})
it('increments the counter and updates the total amount when the increment button is clicked', () => {
cy.getByData(testIds.cartpage_incrementButton).click()
cy.getByData(testIds.cartpage_input).should('have.value', '2')
})
it('decrement the counter and updates the total amount when the decrement button is clicked', () => {
cy.getByData(testIds.cartpage_incrementButton).click()
cy.getByData(testIds.cartpage_input).should('have.value', '2')
cy.getByData(testIds.cartpage_decrementButton).click()
cy.getByData(testIds.cartpage_input).should('have.value', '1')
})
it('Should conatin order Button and click on it render it on checkout page', () => {
cy.getByData(testIds.cartpage_cartOrderButton).should('contain.text', 'Proceed')
cy.getByData(testIds.cartpage_cartOrderButton).click()
})
})
})
2 changes: 1 addition & 1 deletion cypress/e2e/p2p-energy/p2p-energy-productDetails.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ describe('p2p energy product details Page Tests', () => {
before(() => {
cy.visit(testIds.url_base)
cy.getByData(testIds.clickable_card_open_spark).click()
cy.getByData(testIds.P2P_hompage_button).click()
cy.intercept('POST', '**/search', {
fixture: 'P2P/searchResponse.json'
}).as('searchResponse')
cy.wait(1000)
cy.getByData(testIds.P2P_hompage_button).click()
cy.url().should('include', `${testIds.url_search}?searchTerm`)
cy.getByData(testIds.searchpage_products).first().click()
})
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/p2p-energy/p2p-searchPage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ describe('Search Page Tests', () => {
beforeEach(() => {
cy.visit(testIds.url_base)
cy.getByData(testIds.clickable_card_open_spark).click()
cy.getByData(testIds.P2P_hompage_button).click()
cy.intercept('POST', '**/search', {
fixture: 'P2P/emptySearchResults.json'
}).as('emptySearchResults')
cy.getByData(testIds.P2P_hompage_button).click()
cy.url().should('include', `${testIds.url_search}?searchTerm`)
})

Expand Down
141 changes: 141 additions & 0 deletions cypress/fixtures/P2P/selectResult.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"data": [
{
"context": {
"domain": "uei:p2p_trading",
"action": "on_select",
"version": "1.1.0",
"bpp_id": "bpp-ps-network-strapi-dev.becknprotocol.io",
"bpp_uri": "http://bpp-ps-network-strapi-dev.becknprotocol.io",
"country": "IND",
"city": "std:080",
"location": {
"country": {
"name": "India",
"code": "IND"
},
"city": {
"name": "Bangalore",
"code": "std:080"
}
},
"bap_id": "bap-ps-network-dev.becknprotocol.io",
"bap_uri": "https://bap-ps-network-dev.becknprotocol.io",
"transaction_id": "9801be1d-52b5-492a-b8dd-2afdba1ae7f5",
"message_id": "b750655f-0006-43ef-8e63-703d7c60fff2",
"ttl": "PT10M",
"timestamp": "2024-12-05T07:30:19.569Z"
},
"message": {
"order": {
"quote": {
"price": {
"value": "13"
},
"breakup": [
{
"title": "CGST",
"price": {
"currency": "INR",
"value": "5"
}
},
{
"title": "SGST",
"price": {
"currency": "INR",
"value": "5"
}
},
{
"title": "Convenience charges",
"price": {
"currency": "INR",
"value": "1"
}
},
{
"title": "Wheeling charges @ 0.5/unit",
"price": {
"currency": "INR",
"value": "1"
}
},
{
"title": "P2P Energy Cost",
"price": {
"currency": "INR"
}
}
]
},
"provider": {
"id": "798",
"name": "Leela Energy Corp",
"short_desc": "Leela Energy Company",
"long_desc": "Big Leela Energy Company",
"images": {
"url": "https://file.aiquickdraw.com/imgcompressed/img/compressed_56a2f2ed06b49ceb7f8580c4bed33b52.webp",
"size_type": "sm"
},
"fulfillments": [
{
"id": "27",
"type": "END",
"rateable": true
},
{
"id": "26",
"type": "START",
"rateable": true
}
]
},
"items": [
{
"id": "322",
"name": "Energy",
"short_desc": "Excess power from my rooftop system to sell",
"images": [
{
"url": "https://file.aiquickdraw.com/imgcompressed/img/compressed_56a2f2ed06b49ceb7f8580c4bed33b52.webp",
"size_type": "sm"
}
],
"price": {
"value": "13"
},
"rating": "null",
"rateable": true,
"quantity": {
"available": {
"count": 120,
"measure": {
"value": "120",
"unit": "kWh"
}
}
},
"categories": [
{
"id": "100",
"name": "SOLAR ENERGY"
}
],
"fulfillments": [
{
"id": "27",
"type": "END"
},
{
"id": "26",
"type": "START"
}
]
}
]
}
}
}
]
}
2 changes: 1 addition & 1 deletion shared/dataTestIds.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const testIds = {
// application wise base url
url_base: process.env.CYPRESS_BASE_URL || 'http://localhost:3010',
url_base: process.env.CYPRESS_BASE_URL || 'http://localhost:3000',
url_base_retail: process.env.CYPRESS_BASE_URL || 'http://localhost:3002',
url_base_tourism: process.env.CYPRESS_BASE_URL || 'http://localhost:3001',
// general
Expand Down

0 comments on commit c074d2e

Please sign in to comment.