Skip to content

Commit

Permalink
Upd: Setup cypress with publish data agreement e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: George J Padayatti <george.padayatti@igrant.io>
  • Loading branch information
georgepadayatti committed Jan 14, 2024
1 parent 681d5be commit 2061394
Show file tree
Hide file tree
Showing 9 changed files with 1,589 additions and 86 deletions.
10 changes: 10 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from "cypress";

export default defineConfig({
projectId: "6iyv1h",
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
78 changes: 78 additions & 0 deletions cypress/e2e/data-agreement/dataAgreement.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/// <reference types="cypress" />

// Load fixtures
const testDataAsImport = require('../../fixtures/test-data')
const urls = require('../../fixtures/urls')


describe('Publish a data agreement', () => {
before(function () {
// Supply fixtures into each test using `this.testData`
cy.fixture('test-data.json').then((testData) => {
this.testData = testData
});

const loginToAdminDashboard = () => {
// Visit dashboard login page
cy.visit(urls.baseUrl)

// Type the username and password
cy.get("#username").type(testDataAsImport.username);
cy.get("#password").type(testDataAsImport.password);

// Click the login button
cy.get('[data-testid="ArrowCircleRightOutlinedIcon"]').click();

// If login is success and redirected to dashboard.
cy.url().should('include', urls.pages.gettingStarted);
cy.get('h6.MuiTypography-h6').contains('Consent Building Block - Admin Dashboard').should('exist');
}

cy.session('login', loginToAdminDashboard)
})

it('should publish a data agreement', function () {
const { dataAgreement } = this.testData

// Visit data agreement page
cy.visit(urls.baseUrl + urls.pages.dataAgreements)

// Click on create data agreement + button
cy.get('[aria-label="Create Data Agreement"]').click();

// Fill create data agreement form
// Purpose name
cy.get('[name="Name"]').type(dataAgreement.name);
// Data exchange mode - DUS
cy.get('[aria-labelledby="mui-component-select-AttributeType"]').click();
cy.get('[data-value="data_using_service"]').click();
// Purpose description
cy.get('[name="Description"]').type(dataAgreement.description);
// Lawful basis of processing
cy.get('[aria-labelledby="mui-component-select-LawfulBasisOfProcessing"]').click();
cy.get('[data-value="contract"]').click();

// Data attributes
// Attribute 1
cy.get('[name="dataAttributes.0.attributeName"]').type(dataAgreement.dataAttributes[0].attributeName);
cy.get('[name="dataAttributes.0.attributeDescription"]').type(dataAgreement.dataAttributes[0].attributeDescription);
cy.get('[data-testid="AddCircleOutlineOutlinedIcon"]').eq(-1).click();

// Attribute 2
cy.get('[name="dataAttributes.1.attributeName"]').type(dataAgreement.dataAttributes[1].attributeName);
cy.get('[name="dataAttributes.1.attributeDescription"]').type(dataAgreement.dataAttributes[1].attributeDescription);

// Publish data agreement
cy.contains('button', 'PUBLISH').click();

})

after(function () {
// Click the login button
cy.wait(3000);
cy.get('[data-testid="DeleteOutlineOutlinedIcon"]').click();
cy.get("#username").type("DELETE");
cy.contains('button', 'DELETE').click();
})

})
18 changes: 18 additions & 0 deletions cypress/fixtures/test-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"username": "admin@localretail.com",
"password": "qwerty123",
"dataAgreement": {
"name": "Marketing and campaign",
"description": "Marketing and campaign",
"dataAttributes": [
{
"attributeName": "Name",
"attributeDescription": "Name of the individual"
},
{
"attributeName": "Age",
"attributeDescription": "Age of the individual"
}
]
}
}
8 changes: 8 additions & 0 deletions cypress/fixtures/urls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"baseUrl": "https://dashboard.bb-consent.dev",
"pages": {
"login":"/#/login",
"gettingStarted": "/#/start",
"dataAgreements": "/#/dataagreement"
}
}
37 changes: 37 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
20 changes: 20 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading

0 comments on commit 2061394

Please sign in to comment.