Skip to content

Commit

Permalink
Merge pull request #3066 from beckn/cypress-open-spark-admin-flow
Browse files Browse the repository at this point in the history
feat(OPEN-SPARK): added cypress test cases for admin flow
  • Loading branch information
aniketceminds authored Jan 27, 2025
2 parents a2e6a4c + 4d55916 commit f7c9a33
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 3 deletions.
19 changes: 17 additions & 2 deletions apps/open-spark/pages/adminDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Cookies from 'js-cookie'
import BecknButton from '@beckn-ui/molecules/src/components/button/Button'
import { MdOutlineRefresh } from 'react-icons/md'
import { setTradeExecutionProcessed, UserRootState } from '@store/user-slice'
import { testIds } from '@shared/dataTestIds'

interface PendingTrades {
id: number
Expand Down Expand Up @@ -130,6 +131,7 @@ const LockDemand = () => {
>
<Box>
<Typography
dataTest={testIds.total_aggregated_demand}
text="Total Aggregated demand"
fontWeight="600"
fontSize="16px"
Expand All @@ -142,20 +144,25 @@ const LockDemand = () => {
className="hideScroll"
marginTop={'1rem'}
>
<Table variant="simple">
<Table
variant="simple"
data-test={testIds.total_aggregated_table}
>
<Thead
data-test={testIds.total_aggregated_table_head}
position="sticky"
top={0}
bg="white"
zIndex={1}
>
<Tr>
<Tr data-test={testIds.total_aggregated_table_row}>
<Th padding="0">
<Box
display="flex"
alignItems="center"
placeContent={'center'}
width={'64px'}
data-test={testIds.total_aggregated_table_unit}
>
Unit
</Box>
Expand All @@ -166,6 +173,7 @@ const LockDemand = () => {
alignItems="center"
placeContent={'center'}
width={'130px'}
data-test={testIds.total_aggregated_table_consumer}
>
Consumer
</Box>
Expand All @@ -176,6 +184,7 @@ const LockDemand = () => {
alignItems="center"
placeContent={'center'}
width={'70px'}
data-test={testIds.total_aggregated_table_date}
>
Date
</Box>
Expand Down Expand Up @@ -205,6 +214,7 @@ const LockDemand = () => {
padding="0"
>
<Typography
dataTest={testIds.total_aggregated_item_quantity}
text={item.quantity}
style={{
display: '-webkit-box',
Expand All @@ -223,6 +233,7 @@ const LockDemand = () => {
padding="0"
>
<Typography
dataTest={testIds.total_aggregated_item_name}
text={item.name}
style={{
display: '-webkit-box',
Expand All @@ -241,6 +252,7 @@ const LockDemand = () => {
padding="0"
>
<Typography
dataTest={testIds.total_aggregated_item_date}
text={formatDate(item.createdAt, 'yyyy-MM-dd')}
style={{
display: '-webkit-box',
Expand All @@ -256,6 +268,7 @@ const LockDemand = () => {
</Td>
<Td borderBottom={'1px dotted #004e92!important'}>
<Image
data-test={testIds.total_aggregated_nav_img}
src={NavIcon}
alt="nav_icon"
width={'6px'}
Expand All @@ -267,6 +280,7 @@ const LockDemand = () => {
<Tr>
<Td colSpan={5}>
<Typography
dataTest="noRows"
text="No rows"
fontWeight="600"
style={{ textAlign: 'center' }}
Expand All @@ -279,6 +293,7 @@ const LockDemand = () => {
</Box>
</Box>
<BecknButton
dataTest={testIds.total_aggregated_lock_demand}
children={'Lock Demand'}
isLoading={tradeExecutionProcessed}
handleClick={handleOnLockDemand}
Expand Down
76 changes: 76 additions & 0 deletions cypress/e2e/open-spak/adminFlow.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { testIds } from '../../../shared/dataTestIds'
describe('Admin Flow', () => {
context('Should Render Empty admin page when there is no response in get pending trades', () => {
before(() => {
cy.clearAllLocalStorage()
cy.clearAllCookies()
cy.visit(testIds.url_base)
cy.getByData('consumer_button').click()
cy.getByData(testIds.auth_inputEmail).type(testIds.user_validEmail_admin_flow)
cy.getByData(testIds.auth_inputEmail).should('have.value', testIds.user_validEmail_admin_flow)
cy.getByData(testIds.auth_inputPassword).type(testIds.user_validPassword_admin_flow)
cy.getByData(testIds.auth_inputPassword).should('have.value', testIds.user_validPassword_admin_flow)
cy.getByData(testIds.auth_loginButton).click()
})
it('should render empty admin page ', () => {
cy.url().should('include', testIds.url_home)
cy.intercept('GET', '/beckn-trade-bap/get-pending-trades', {
fixture: 'OpenSpark/myTrade/get-pending-empty-trades.json'
}).as('emptyPendingTrade')
cy.wait('@emptyPendingTrade')
})
it('should render lock demand button diabled ', () => {
cy.getByData(testIds.total_aggregated_lock_demand).should('be.disabled')
cy.getByData(testIds.total_aggregated_demand).should('be.visible')
cy.getByData(testIds.total_aggregated_table).should('be.visible')
cy.getByData(testIds.total_aggregated_table_head).should('be.visible')
cy.getByData('noRows').should('be.visible')
cy.getByData('noRows').should('contain.text', 'No rows')
})
})
context('Should Render admin page when there is response in get pending trades', () => {
before(() => {
cy.clearAllLocalStorage()
cy.clearAllCookies()
cy.visit(testIds.url_base)
cy.getByData('consumer_button').click()
cy.getByData(testIds.auth_inputEmail).type(testIds.user_validEmail_admin_flow)
cy.getByData(testIds.auth_inputEmail).should('have.value', testIds.user_validEmail_admin_flow)
cy.getByData(testIds.auth_inputPassword).type(testIds.user_validPassword_admin_flow)
cy.getByData(testIds.auth_inputPassword).should('have.value', testIds.user_validPassword_admin_flow)
cy.getByData(testIds.auth_loginButton).click()
})
it('should render admin page ', () => {
cy.url().should('include', testIds.url_home)
cy.intercept('GET', '/beckn-trade-bap/get-pending-trades', {
fixture: 'OpenSpark/myTrade/get-pending-trades.json'
}).as('getPendingTrade')
cy.wait('@getPendingTrade')
})
it('should display all the fields and button', () => {
cy.getByData(testIds.total_aggregated_demand).should('be.visible')
cy.getByData(testIds.total_aggregated_table).should('be.visible')
cy.getByData(testIds.total_aggregated_table_head).should('be.visible')
cy.getByData(testIds.total_aggregated_table_row).should('be.visible')
cy.getByData(testIds.total_aggregated_table_unit).should('be.visible')
cy.getByData(testIds.total_aggregated_table_consumer).should('be.visible')
cy.getByData(testIds.total_aggregated_table_date).should('be.visible')
cy.getByData(testIds.total_aggregated_item_quantity).should('be.visible')
cy.getByData(testIds.total_aggregated_item_name).should('be.visible')
cy.getByData(testIds.total_aggregated_item_date).should('be.visible')
cy.getByData(testIds.total_aggregated_nav_img).should('be.visible')
cy.getByData(testIds.total_aggregated_lock_demand).should('be.visible')
})
it('should render lock demand button enable and user click it for lock demand ', () => {
cy.intercept('POST', '/beckn-trade-bap/start-trade', {
fixture: 'OpenSpark/myTrade/start-trade.json'
}).as('start-trade')
cy.getByData(testIds.total_aggregated_lock_demand).click()
cy.wait('@start-trade')
cy.intercept('GET', '/beckn-trade-bap/get-pending-trades', {
fixture: 'OpenSpark/myTrade/get-pending-empty-trades.json'
}).as('emptyPendingTrade')
cy.visit(testIds.url_base)
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
58 changes: 58 additions & 0 deletions cypress/fixtures/OpenSpark/myTrade/get-pending-trades.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{
"id": 206,
"unit": "kwh",
"item_name": "energy",
"trusted_source": false,
"cred_required": false,
"recurring": false,
"domain": "uei:p2p_trading",
"status": "RECEIVED",
"type": "BUY",
"quantity": 100,
"price": 0,
"createdAt": "2025-01-23T10:29:20.570Z",
"updatedAt": "2025-01-23T10:29:20.570Z",
"publishedAt": "2025-01-23T10:29:20.566Z",
"profile": {
"id": 128,
"name": "Leelatai Kalbhor",
"address": "pune",
"createdAt": "2024-12-04T08:29:52.567Z",
"updatedAt": "2025-01-15T04:00:25.459Z",
"publishedAt": "2025-01-13T06:24:00.090Z",
"phone": "9718329616",
"zip_code": null,
"utility_name": "MSEB",
"customer_id": "12345"
}
},
{
"id": 207,
"unit": "kwh",
"item_name": "energy",
"trusted_source": false,
"cred_required": false,
"recurring": false,
"domain": "uei:p2p_trading",
"status": "RECEIVED",
"type": "BUY",
"quantity": 50,
"price": 0,
"createdAt": "2025-01-23T10:29:27.344Z",
"updatedAt": "2025-01-23T10:29:27.344Z",
"publishedAt": "2025-01-23T10:29:27.339Z",
"profile": {
"id": 128,
"name": "Leelatai Kalbhor",
"address": "pune",
"createdAt": "2024-12-04T08:29:52.567Z",
"updatedAt": "2025-01-15T04:00:25.459Z",
"publishedAt": "2025-01-13T06:24:00.090Z",
"phone": "9718329616",
"zip_code": null,
"utility_name": "MSEB",
"customer_id": "12345"
}
}
]
15 changes: 15 additions & 0 deletions cypress/fixtures/OpenSpark/myTrade/start-trade.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"message": "Trade processing completed!",
"data": [
{
"tradeId": 206,
"status": "SUCCESS",
"message": "Trade executed successfully for Trade ID: 206"
},
{
"tradeId": 207,
"status": "SUCCESS",
"message": "Trade executed successfully for Trade ID: 207"
}
]
}
Empty file.
16 changes: 15 additions & 1 deletion shared/dataTestIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,8 @@ const testIds = {
user_validPassword_consumer_flow: 'Test@123',
user_validEmail_producer_flow: '[email protected]',
user_validPassword_producer_flow: 'Test@123',
user_validEmail_admin_flow: '[email protected]',
user_validPassword_admin_flow: 'Test@123',
total_energy_text: 'total_energy_text',
total_energy_input: 'total_energy_input',
total_energy_unit: 'total_energy_unit',
Expand Down Expand Up @@ -723,6 +725,18 @@ const testIds = {
document_uplaod_date: 'document-uplaod-date',
delete_Icon: 'delete-Icon',
trade_details_date: 'trade-details-date',
trade_details_Id: 'trade-details-Id'
trade_details_Id: 'trade-details-Id',
total_aggregated_demand: 'total_aggregated_demand',
total_aggregated_table: 'total_aggregated_table',
total_aggregated_table_head: 'total_aggregated_table_head',
total_aggregated_table_row: 'total_aggregated_table_row',
total_aggregated_table_unit: 'total_aggregated_table_unit',
total_aggregated_table_consumer: 'total_aggregated_table_consumer',
total_aggregated_table_date: 'total_aggregated_table_date',
total_aggregated_item_quantity: 'total_aggregated_item_quantity',
total_aggregated_item_name: 'total_aggregated_item_name',
total_aggregated_item_date: 'total_aggregated_item_date',
total_aggregated_nav_img: 'total_aggregated_nav_img',
total_aggregated_lock_demand: 'total_aggregated_lock_demand'
}
export { testIds }

0 comments on commit f7c9a33

Please sign in to comment.