Skip to content

Commit

Permalink
Merge pull request #2988 from beckn/feat/cypress-myDers-openSpark
Browse files Browse the repository at this point in the history
Feat/cypress my ders open spark
  • Loading branch information
aniketceminds authored Jan 20, 2025
2 parents a88a098 + 5496413 commit a3e22ec
Show file tree
Hide file tree
Showing 18 changed files with 1,279 additions and 1 deletion.
4 changes: 4 additions & 0 deletions apps/open-spark/components/deviceList/AddNewDerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import uploadIcon from '@public/images/upload_icon.svg'
import pdfIcon from '@public/images/PDF.svg'
import DragAndDropUpload from '@components/dragAndDropUpload'
import RenderDocuments, { DocumentProps } from '@components/documentsRenderer'
import { testIds } from '@shared/dataTestIds'

interface Proofs {
id: number
Expand Down Expand Up @@ -75,6 +76,7 @@ const AddNewDerModal = (props: AddNewDerModalProps) => {
display="grid"
height="100%"
alignContent="center"
data-test={testIds.loadingIndicator}
>
<LoaderWithMessage
loadingText="Please Wait"
Expand All @@ -92,6 +94,7 @@ const AddNewDerModal = (props: AddNewDerModalProps) => {
value={category}
label="Category"
handleChange={e => setCategory(e.target.value)}
dataTest={'add-new-ders-input'}
/>
<Typography
text="Proofs"
Expand Down Expand Up @@ -141,6 +144,7 @@ const AddNewDerModal = (props: AddNewDerModalProps) => {
disabled={!category.trim() || uploadedFiles.length === 0}
sx={{ marginTop: '20px' }}
isLoading={isLoading}
dataTest={'add-new-ders'}
/>
</Flex>
)}
Expand Down
9 changes: 8 additions & 1 deletion apps/open-spark/components/deviceList/DeviceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,22 @@ export default function DeviceList({ initialDevices, onDeviceChange, fetchPaired
text="Pair Device"
fontWeight="600"
fontSize="15px"
dataTest={'pair-device'}
/>
<IconButton
aria-label="Add device"
icon={<BiPlusCircle size={20} />}
variant="ghost"
onClick={handleModalOpen}
data-test={'add-devices-icon'}
/>
</Flex>

<Typography
text="Paired"
fontWeight="600"
fontSize="12px"
dataTest={'paired'}
/>

<VStack
Expand All @@ -155,12 +158,16 @@ export default function DeviceList({ initialDevices, onDeviceChange, fetchPaired
_hover={{ bg: 'gray.50' }}
boxShadow="rgba(0, 0, 0, 0.35) 0px 5px 15px"
>
<Typography text={device?.name} />
<Typography
text={device?.name}
dataTest={'device_name'}
/>
<CiCircleMinus
onClick={() => handleDeleteModalOpen(device?.id)}
style={{ cursor: 'pointer' }}
size={24}
opacity="0.5"
data-test={'remove-paired-device'}
/>
</Flex>
))}
Expand Down
1 change: 1 addition & 0 deletions apps/open-spark/components/dragAndDropUpload/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const DragAndDropUpload = (props: DragAndDropUploadProps) => {
display="none"
ref={fileInputRef}
onChange={handleFileInput}
data-test={'document-upload'}
/>
<>{fileSelectionElement?.(fileInputRef)}</>
</Box>
Expand Down
3 changes: 3 additions & 0 deletions apps/open-spark/components/modal/DeleteAlertModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const DeleteAlertModal = (props: DeleteAlertModalProps) => {
text="Are you sure you want to delete"
fontSize="18px"
fontWeight="400"
dataTest={'delete-modal-message'}
/>
<Typography
text="this item?"
Expand All @@ -42,12 +43,14 @@ const DeleteAlertModal = (props: DeleteAlertModalProps) => {
variant="solid"
handleClick={handleConfirmDeleteDevice}
isLoading={isLoading}
dataTest={'delete-modal-yes-button'}
/>
<BecknButton
children="Cancel"
variant="outline"
color="#E93324"
handleClick={onClose}
dataTest={'delete-modal-cancel-button'}
/>
</Flex>
</BottomModalScan>
Expand Down
195 changes: 195 additions & 0 deletions cypress/e2e/open-spak/myDers.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
import { testIds } from '../../../shared/dataTestIds'
import 'cypress-file-upload'

describe('My Ders Page ', () => {
context('Consumer My Ders Page Flow', () => {
before(() => {
cy.clearAllLocalStorage()
cy.clearAllCookies()
cy.visit(testIds.url_base)
cy.getByData('consumer_button').click()
cy.getByData(testIds.auth_inputEmail).type(testIds.user_validEmail_consumer_flow)
cy.getByData(testIds.auth_inputPassword).type(testIds.user_validPassword_consumer_flow)
cy.getByData(testIds.auth_loginButton).click()
cy.url().should('include', testIds.url_home)
cy.getByData(testIds.topSheet_profile_icon).click()
cy.visit(`${testIds.url_base}${testIds.url_profile}`)
cy.intercept('GET', '/beckn-trade-bap/user-profile', {
fixture: 'OpenSpark/profile/profile.json'
}).as('profileCall')
cy.getByData('myDers').click()
})

context('Should render Empty Ders Page when no Response in Ders', () => {
it('should display Empty Page My Ders page', () => {
cy.visit(`${testIds.url_base}${'/myDers'}`)
cy.intercept('GET', '/beckn-trade-bap/der', {
fixture: 'OpenSpark/myDers/emptyMyDers.json'
}).as('emptyMyDers')
cy.wait('@emptyMyDers')
cy.getByData('pair-device').should('be.visible')
cy.getByData('pair-device').should('contain.text', 'Pair Device')
cy.getByData('paired').should('be.visible')
cy.getByData('add-devices-icon').should('be.visible')
})
})
context('Should render My Ders Page when Response in Ders', () => {
it('should display My Ders page', () => {
cy.visit(`${testIds.url_base}${'/myDers'}`)
cy.intercept('GET', '/beckn-trade-bap/der', {
fixture: 'OpenSpark/myDers/myDers.json'
}).as('myDers')
cy.wait('@myDers')
cy.getByData('device_name').should('be.visible')
cy.getByData('remove-paired-device').should('be.visible')
})
it('should display paired devices', () => {
cy.getByData('device_name').eq(0).should('contain.text', 'Storage battery2')
cy.getByData('device_name').eq(1).should('contain.text', 'sd')
})
it('should Click on Plus icon and Modal Should be Open', () => {
cy.getByData('add-devices-icon').click()
cy.getByData('add-new-ders-input').should('be.visible')
})
it('should fill and upload documents for new paired device', () => {
cy.getByData('add-new-ders-input').clear().type('washing machine')
const fileName = 'OpenSpark/myDers/sample_aadhar.pdf'
cy.getByData('document-upload').attachFile(fileName)
cy.getByData('add-new-ders').click()
cy.getByData(testIds.loadingIndicator).should('be.visible')
cy.intercept('GET', '/beckn-trade-bap/der', {
fixture: 'OpenSpark/myDers/addNewDers.json'
}).as('addNewDers')
cy.wait(5000)
})
it('should display New paired devices', () => {
cy.getByData('device_name').eq(2).should('contain.text', 'washing machine')
})
it('should remove paired device On clicking of remove button and open modal', () => {
cy.clearAllLocalStorage()
cy.clearAllCookies()
cy.visit(testIds.url_base)
cy.getByData('consumer_button').click()
cy.getByData(testIds.auth_inputEmail).type(testIds.user_validEmail_consumer_flow)
cy.getByData(testIds.auth_inputPassword).type(testIds.user_validPassword_consumer_flow)
cy.getByData(testIds.auth_loginButton).click()
cy.url().should('include', testIds.url_home)
cy.getByData(testIds.topSheet_profile_icon).click()
cy.visit(`${testIds.url_base}${testIds.url_profile}`)
cy.intercept('GET', '/beckn-trade-bap/user-profile', {
fixture: 'OpenSpark/profile/profile.json'
}).as('profileCall')
cy.getByData('myDers').click()
cy.getByData('remove-paired-device').eq(2).click()
cy.getByData('delete-modal-message').should('be.visible')
cy.getByData('delete-modal-yes-button').should('be.visible')
cy.getByData('delete-modal-cancel-button').should('be.visible')
cy.getByData('delete-modal-yes-button').click()
cy.intercept('DELETE', '/beckn-trade-bap/der/30', {
fixture: 'OpenSpark/myDers/deleteDers.json'
}).as('deleteDers')
cy.intercept('GET', '/beckn-trade-bap/der', {
fixture: 'OpenSpark/myDers/afterDeleteders.json'
}).as('afterDeleteders.json')
})
it('should not display remove paired devices', () => {
cy.getByData('device_name').eq(1).should('be.visible')
})
})
})
context('Prosumer My Ders Page Flow', () => {
before(() => {
cy.clearAllLocalStorage()
cy.clearAllCookies()
cy.visit(testIds.url_base)
cy.getByData('producer_button').click()
cy.getByData(testIds.auth_inputEmail).type(testIds.user_validEmail_producer_flow)
cy.getByData(testIds.auth_inputPassword).type(testIds.user_validPassword_producer_flow)
cy.getByData(testIds.auth_loginButton).click()
cy.url().should('include', testIds.url_home)
cy.getByData(testIds.topSheet_profile_icon).click()
cy.visit(`${testIds.url_base}${testIds.url_profile}`)
cy.intercept('GET', '/beckn-trade-bpp/user-profile', {
fixture: 'OpenSpark/profile/producerProfile.json'
}).as('producerProfile')
cy.getByData('myDers').click()
})

context('Should render Empty Ders Page when no Response in Ders', () => {
it('should display Empty Page My Ders page', () => {
cy.visit(`${testIds.url_base}${'/myDers'}`)
cy.intercept('GET', '/beckn-trade-bpp/der', {
fixture: 'OpenSpark/myDers/emptyMyDersProducer.json'
}).as('emptyMyDersProducer')
cy.wait('@emptyMyDersProducer')
cy.getByData('pair-device').should('be.visible')
cy.getByData('pair-device').should('contain.text', 'Pair Device')
cy.getByData('paired').should('be.visible')
cy.getByData('add-devices-icon').should('be.visible')
})
})
context('Should render My Ders Page when Response in Ders', () => {
it('should display My Ders page', () => {
cy.visit(`${testIds.url_base}${'/myDers'}`)
cy.intercept('GET', '/beckn-trade-bpp/der', {
fixture: 'OpenSpark/myDers/myDersProducer.json'
}).as('myDersProducer')
cy.wait('@myDersProducer')
cy.getByData('device_name').should('be.visible')
cy.getByData('remove-paired-device').should('be.visible')
})
it('should display paired devices', () => {
cy.getByData('device_name').eq(0).should('contain.text', 'Solar panel 1')
cy.getByData('device_name').eq(1).should('contain.text', 'Solar panel 2')
})
it('should Click on Plus icon and Modal Should be Open', () => {
cy.getByData('add-devices-icon').click()
cy.getByData('add-new-ders-input').should('be.visible')
})
it('should fill and upload documents for new paired device', () => {
cy.getByData('add-new-ders-input').clear().type('Water Filter')
const fileName = 'OpenSpark/myDers/sample_aadhar.pdf'
cy.getByData('document-upload').attachFile(fileName)
cy.getByData('add-new-ders').click()
cy.getByData(testIds.loadingIndicator).should('be.visible')
cy.intercept('GET', '/beckn-trade-bpp/der', {
fixture: 'OpenSpark/myDers/addNewDersProducer.json'
}).as('addNewDersProducer')
cy.wait(5000)
})
it('should display New paired devices', () => {
cy.getByData('device_name').eq(2).should('contain.text', 'Water Filter')
})
it('should remove paired device On clicking of remove button and open modal', () => {
cy.clearAllLocalStorage()
cy.clearAllCookies()
cy.visit(testIds.url_base)
cy.getByData('producer_button').click()
cy.getByData(testIds.auth_inputEmail).type(testIds.user_validEmail_producer_flow)
cy.getByData(testIds.auth_inputPassword).type(testIds.user_validPassword_producer_flow)
cy.getByData(testIds.auth_loginButton).click()
cy.url().should('include', testIds.url_home)
cy.getByData(testIds.topSheet_profile_icon).click()
cy.visit(`${testIds.url_base}${testIds.url_profile}`)
cy.intercept('GET', '/beckn-trade-bpp/user-profile', {
fixture: 'OpenSpark/profile/producerProfile.json'
}).as('producerProfile')
cy.getByData('myDers').click()
cy.getByData('remove-paired-device').eq(2).click()
cy.getByData('delete-modal-message').should('be.visible')
cy.getByData('delete-modal-yes-button').should('be.visible')
cy.getByData('delete-modal-cancel-button').should('be.visible')
cy.getByData('delete-modal-yes-button').click()
cy.intercept('DELETE', '/beckn-trade-bpp/der/50', {
fixture: 'OpenSpark/myDers/deleteProducerDers.json'
}).as('deleteProducerDers')
cy.intercept('GET', '/beckn-trade-bpp/der', {
fixture: 'OpenSpark/myDers/afterDeleteProducerDers.json'
}).as('afterDeleteProducerDers.json')
})
it('should not display remove paired devices', () => {
cy.getByData('device_name').eq(1).should('be.visible')
})
})
})
})
81 changes: 81 additions & 0 deletions cypress/fixtures/OpenSpark/myDers/aadhar_cred .json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://cord.network/2023/cred/v1"
],
"type": ["VerifiableCredential"],
"issuer": "did:cord:3zKcL2oAsvZZwFA5uPxtysk5jsai2TGx4AvrpJcBYmAwzGyN",
"issuanceDate": "2024-12-10T09:21:27.012Z",
"credentialSubject": {
"documentName": "Aadhar Card",
"type": "PROSUMER",
"proof": "9CE71A8A2B02AFAFE6F559223D743B49360324A71F610DCBF767BC3790F3862B",
"id": "did:cord:3zKcL2oAsvZZwFA5uPxtysk5jsai2TGx4AvrpJcBYmAwzGyN",
"@context": {
"vocab": "schema:cord:s361qsAZ9oNHtFD9vngtYewEkdJNNdYuiQHc9a4nibgZZkgQ5#"
}
},
"validFrom": "2024-12-10T09:21:27.012Z",
"validUntil": "2025-12-10T09:21:27.012Z",
"metadata": {},
"credentialSchema": {
"$id": "schema:cord:s361qsAZ9oNHtFD9vngtYewEkdJNNdYuiQHc9a4nibgZZkgQ5",
"title": "User Cred Schema:5bbb6047-25f5-41c4-b9d9-ab9d0eb6408c",
"properties": {
"documentName": {
"type": "string"
},
"proof": {
"type": "string"
},
"type": {
"type": "string"
},
"category": {
"type": "string"
}
},
"required": [],
"type": "object",
"additionalProperties": false,
"$schema": "http://cord.network/draft-01/schema#"
},
"credentialHash": "0xc9fd80776d943c5bf63423920b002497e48e1d96cf1e5543115f1e0d0a07dd7d",
"id": "stmt:cord:s3eMFj1bXVMYY8muhCFjvSFGaBkg4Mvtvqcyx47W7NR7xY9uW",
"proof": [
{
"type": "Ed25519Signature2020",
"created": "Tue Dec 10 2024 09:21:27 GMT+0000 (Coordinated Universal Time)",
"proofPurpose": "sr25519",
"verificationMethod": "did:cord:3zKcL2oAsvZZwFA5uPxtysk5jsai2TGx4AvrpJcBYmAwzGyN#0xaebd479b52b61ec4954a5478e6285bff0a5508b53f30ee5c552061efd4c89842",
"proofValue": "z4cdZsEqDHQsKbmPYxeNeLrSjWgqhGs4aD2o4BJYX2PsmU8Lmp8KEAFeC6sy5ymYT7bRGpizQmqwVpsXb8KRfohwU"
},
{
"type": "CordProof2024",
"elementUri": "stmt:cord:s3eMFj1bXVMYY8muhCFjvSFGaBkg4Mvtvqcyx47W7NR7xY9uW:c9fd80776d943c5bf63423920b002497e48e1d96cf1e5543115f1e0d0a07dd7d",
"spaceUri": "space:cord:c35h1XGuUXDHwtJTre7dwsb7KqZM5DWYA4kpPRuSx6BZJnXTg",
"schemaUri": "schema:cord:s361qsAZ9oNHtFD9vngtYewEkdJNNdYuiQHc9a4nibgZZkgQ5",
"creatorUri": "did:cord:3zKcL2oAsvZZwFA5uPxtysk5jsai2TGx4AvrpJcBYmAwzGyN",
"digest": "0xc9fd80776d943c5bf63423920b002497e48e1d96cf1e5543115f1e0d0a07dd7d",
"identifier": "stmt:cord:s3eMFj1bXVMYY8muhCFjvSFGaBkg4Mvtvqcyx47W7NR7xY9uW",
"genesisHash": "0x99f72c0a4e8ec69365bb2b480302b719465d838cfefa9db0c5a91eed5378285c"
},
{
"type": "CordSDRProof2024",
"defaultDigest": "0x4956536fe08fa3d73b6e828eff0668f0d60bb88cbd727d08d2115f330f7ba969",
"hashes": [
"0x8cde0d63a5d311675021a7ebd9bc505d6737dc78eace5a0c213ecb024ecc0494",
"0xbe8acccbce566548081584e953cdc9319cc3cf3a94d7491c4f290f70b85c27d5",
"0xc670b0f807b50461ee07f12343a093bc75fda5144e17a75bec0171f87a3730b8",
"0xd90cf630b54d06ccc3d009c3f3ddfaf6e52cfec32742a60d4b617b4b1a9a977e"
],
"nonceMap": {
"0xc659b638f8a487c2044b7f803e94bb023095d8e7cb12681d0a12cd0561e22e77": "0c1a11d2-281c-4850-8de7-516391edf853",
"0x8909fd9b5b2c34efb196d40fc18ba53adc3c3f02afea10e5516392c35a99852d": "8446d1e2-30f2-4b7e-9ecf-d9c435205da4",
"0xe01505ef079688c73427c0eca8a4c8e73f6b76b75c45b0d263af635c8d03d97b": "b861a708-e4e7-4559-bcc7-55f3ebdc848a",
"0xc12bc153949ca6f4012428c671f804553cb805026bab898978c671e9983f933f": "68f275ea-0869-4b4b-85b6-6d3fb364b012"
},
"genesisHash": "0x99f72c0a4e8ec69365bb2b480302b719465d838cfefa9db0c5a91eed5378285c"
}
]
}
Loading

0 comments on commit a3e22ec

Please sign in to comment.