Skip to content

Commit

Permalink
Merge pull request #3022 from beckn/feat/cypress-myCredential-openSpark
Browse files Browse the repository at this point in the history
feat(open-spark): test cases for my credential page
  • Loading branch information
aniketceminds authored Jan 24, 2025
2 parents 5cc5c30 + 04d39b4 commit 10c0e59
Show file tree
Hide file tree
Showing 13 changed files with 682 additions and 5 deletions.
9 changes: 8 additions & 1 deletion apps/open-spark/components/documentsRenderer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Typography } from '@beckn-ui/molecules'
import deleteIcon from '@public/images/delete_icon.svg'
import tickIcon from '@public/images/tick.svg'
import { formatFileSize } from '@utils/general'
import { testIds } from '@shared/dataTestIds'

export interface DocumentProps {
icon: string
Expand Down Expand Up @@ -74,6 +75,7 @@ const RenderDocuments = (props: RenderDocumentsProps) => {
<Image
src={document.icon}
alt="doc_type"
data-test={testIds.document_upload_icon}
/>
<Flex
flexDirection={'column'}
Expand All @@ -83,6 +85,7 @@ const RenderDocuments = (props: RenderDocumentsProps) => {
>
<Typography
text={document.title}
dataTest={testIds.document_title}
fontWeight="600"
sx={{
maxWidth: '10rem',
Expand All @@ -93,7 +96,10 @@ const RenderDocuments = (props: RenderDocumentsProps) => {
}}
/>
{type === 'cred' ? (
<Typography text={formatDate(document.date, "dd MMM yyyy 'at' hh:mm a")} />
<Typography
text={formatDate(document.date, "dd MMM yyyy 'at' hh:mm a")}
dataTest={testIds.document_uplaod_date}
/>
) : (
<>
<Typography
Expand Down Expand Up @@ -131,6 +137,7 @@ const RenderDocuments = (props: RenderDocumentsProps) => {
alignSelf={'center'}
width={'16px'}
height={'16px'}
data-test={testIds.delete_Icon}
cursor="pointer"
onClick={() => handleOnDelete(index, document, type)}
/>
Expand Down
16 changes: 14 additions & 2 deletions apps/open-spark/pages/myCredentials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import DragAndDropUpload from '@components/dragAndDropUpload'
import { FiPlusCircle } from 'react-icons/fi'
import RenderDocuments from '@components/documentsRenderer'
import DeleteAlertModal from '@components/modal/DeleteAlertModal'
import { testIds } from '@shared/dataTestIds'

interface DocumentProps {
id?: string
Expand Down Expand Up @@ -161,6 +162,7 @@ const MyCredentials = () => {
<>
<Typography
text="Credentials"
dataTest={testIds.Credentials_text}
fontWeight="600"
fontSize="16px"
style={{
Expand All @@ -176,13 +178,17 @@ const MyCredentials = () => {
)}
<Typography
text="Upload a file"
dataTest={testIds.upload_file}
fontWeight="600"
fontSize="16px"
style={{
marginTop: '1rem'
}}
/>
<Typography text="File upload description" />
<Typography
text="File upload description"
dataTest={testIds.File_upload_description}
/>
{selectedFile.length === 0 && (
<DragAndDropUpload
multiple={false}
Expand All @@ -197,9 +203,13 @@ const MyCredentials = () => {
boxSize={6}
color="gray.500"
/>
<Typography text={'Drop your file here'} />
<Typography
text={'Drop your file here'}
dataTest={testIds.drop_your_file_here}
/>
<HStack gap={1}>
<Typography
dataTest={testIds.Browse_file}
color="#4498E8"
fontSize="8px"
onClick={() => {
Expand Down Expand Up @@ -240,8 +250,10 @@ const MyCredentials = () => {
color="#E93324"
sx={{ marginRight: '8px', border: '1px solid red' }}
handleClick={clearAllFiles}
dataTest={testIds.myCred_Cancel_button}
/>
<BecknButton
dataTest={testIds.myCred_Upload_button}
text={t.upload}
disabled={selectedFile?.length === 0 || !allFilesProcessed}
sx={{ marginLeft: '8px' }}
Expand Down
134 changes: 134 additions & 0 deletions cypress/e2e/open-spak/myCredential.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { testIds } from '../../../shared/dataTestIds'
import 'cypress-file-upload'

describe('My Credential Page ', () => {
context('Consumer My Credential 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.getByData('myCredintial').click()
})

context('Should render My Credential Page when no Response in Cred', () => {
it('should display Empty Page My Credential page with disabled buttons', () => {
cy.visit(`${testIds.url_base}${'/myCredentials'}`)
cy.intercept('GET', '/beckn-trade-bap/cred', {
fixture: 'OpenSpark/myCred/credEmpty.json'
}).as('emptyCred')
cy.wait('@emptyCred')
cy.getByData(testIds.upload_file).should('be.visible')
cy.getByData(testIds.upload_file).should('contain.text', 'Upload a file')
cy.getByData(testIds.drop_your_file_here).should('be.visible')
cy.getByData(testIds.drop_your_file_here).should('contain.text', 'Drop your file here')
cy.getByData(testIds.myCred_Cancel_button).should('be.disabled')
cy.getByData(testIds.myCred_Upload_button).should('be.disabled')
})
})
context('Should render My Credential Page when Response in Cred', () => {
it('should display My Credential page', () => {
cy.visit(`${testIds.url_base}${'/myCredentials'}`)
const fileName = 'OpenSpark/myCred/aadhar_cred.json'
cy.getByData('document-upload').attachFile(fileName)
cy.wait(1000)
cy.getByData(testIds.myCred_Upload_button).click()
cy.intercept('POST', '/beckn-trade-bap/upload-cred', {
fixture: 'OpenSpark/myCred/uplaodConsumer.json'
}).as('uplaodConsumer.json')
cy.intercept('GET', '/beckn-trade-bap/cred', {
fixture: 'OpenSpark/myCred/uploadCredConsumer.json'
}).as('uplaodCredConsumer')
cy.getByData(testIds.Credentials_text).should('be.visible')
cy.getByData(testIds.document_upload_icon).should('be.visible')
cy.getByData(testIds.document_title).should('be.visible')
cy.getByData(testIds.document_uplaod_date).should('be.visible')
cy.getByData(testIds.delete_Icon).should('be.visible')
cy.getByData(testIds.myCred_Upload_button).should('be.disabled')
})
it('should remove credential after click on delete button', () => {
cy.getByData(testIds.delete_Icon).eq(0).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/cred/221', {
fixture: 'OpenSpark/myCred/deleteConsumerCred.json'
}).as('deleteConsumerCred')
cy.intercept('GET', '/beckn-trade-bap/cred', {
fixture: 'OpenSpark/myCred/credEmpty.json'
}).as('afterDeleteders.json')
})
})
})
context('Prosumer My Credential 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.getByData('myCredintial').click()
})

context('Should render My Credential Page when no Response in Cred', () => {
it('should display Empty Page My Credential page with disabled buttons', () => {
cy.visit(`${testIds.url_base}${'/myCredentials'}`)
cy.intercept('GET', '/beckn-trade-bap/cred', {
fixture: 'OpenSpark/myCred/credEmpty.json'
}).as('emptyCred')
cy.getByData(testIds.upload_file).should('be.visible')
cy.getByData(testIds.upload_file).should('contain.text', 'Upload a file')
cy.getByData(testIds.drop_your_file_here).should('be.visible')
cy.getByData(testIds.drop_your_file_here).should('contain.text', 'Drop your file here')
cy.getByData(testIds.myCred_Cancel_button).should('be.disabled')
cy.getByData(testIds.myCred_Upload_button).should('be.disabled')
})
})
context('Should render My Credential Page when Response in Cred', () => {
it('should display My Credential page', () => {
cy.visit(`${testIds.url_base}${'/myCredentials'}`)
const fileName = 'OpenSpark/myCred/aadhar_cred.json'
cy.getByData('document-upload').attachFile(fileName)
cy.wait(1000)
cy.getByData(testIds.myCred_Upload_button).click()
cy.intercept('POST', '/beckn-trade-bpp/upload-cred', {
fixture: 'OpenSpark/myCred/uloadProducer.json'
}).as('uloadProducer.json')
cy.intercept('GET', '/beckn-trade-bpp/cred', {
fixture: 'OpenSpark/myCred/uploadCredProsumer.json'
}).as('uploadCredProsumer')
cy.getByData(testIds.Credentials_text).should('be.visible')
cy.getByData(testIds.document_upload_icon).should('be.visible')
cy.getByData(testIds.document_title).should('be.visible')
cy.getByData(testIds.document_uplaod_date).should('be.visible')
cy.getByData(testIds.delete_Icon).should('be.visible')
cy.getByData(testIds.myCred_Upload_button).should('be.disabled')
})
it('should remove credential after click on delete button', () => {
cy.getByData(testIds.delete_Icon).eq(0).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/cred/236', {
fixture: 'OpenSpark/myCred/deleteProsumerCred.json'
}).as('deleteProsumerCred')
cy.intercept('GET', '/beckn-trade-bpp/cred', {
fixture: 'OpenSpark/myCred/credEmpty.json'
}).as('afterDeleteders.json')
})
})
})
})
2 changes: 1 addition & 1 deletion cypress/e2e/open-spak/myDers.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('My Ders Page ', () => {
fixture: 'OpenSpark/myDers/afterDeleteders.json'
}).as('afterDeleteders.json')
})
it('should not display remove paired devices', () => {
it.only('should not display remove paired devices', () => {
cy.getByData('device_name').eq(1).should('be.visible')
})
})
Expand Down
78 changes: 78 additions & 0 deletions cypress/fixtures/OpenSpark/myCred/aadhar_cred.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"@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"
}
]
}
1 change: 1 addition & 0 deletions cypress/fixtures/OpenSpark/myCred/credEmpty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Loading

0 comments on commit 10c0e59

Please sign in to comment.