Skip to content

Commit

Permalink
feat(Cypress): Add selectors into selectors.js files
Browse files Browse the repository at this point in the history
  • Loading branch information
maipt1 committed Nov 12, 2024
1 parent 208a070 commit 79eb089
Show file tree
Hide file tree
Showing 10 changed files with 372 additions and 206 deletions.
17 changes: 9 additions & 8 deletions cypress/e2e/components/delete.cy.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import { gotoViewComponentPage, createComponent, createRelease } from './utils.js';
import { viewSelectors } from './selectors'

function deleteComponent(componentName) {
// go to component page
cy.visit(`${Cypress.env('sw360_base_url')}/components`)
cy.contains('Add Component')
cy.get('a:contains(' + componentName + ')').closest('tr').find('td').last().find('svg').last().click()
cy.get('.modal-content').should('be.visible')
cy.get('.login-btn').click()
cy.get(viewSelectors.dialogDeleteComponent.dialog).should('be.visible')
cy.get(viewSelectors.dialogDeleteComponent.btnDeleteComponent).click()
verifyDeleteSuccessfully()
}

function verifyDeleteSuccessfully() {
cy.get('.alert-success').should('be.visible')
cy.get('.delete-btn').click()
cy.get(viewSelectors.dialogDeleteComponent.alertSuccess).should('be.visible')
cy.get(viewSelectors.dialogDeleteComponent.btnClose).click()
}

function deleteAllReleaseOfComponent(numberOfReleases) {
for (let i = 0; i < numberOfReleases; i++) {
cy.get('#tab-Releases').click()
cy.get('[data-column-id="action"] > div > span').should('have.length', numberOfReleases - i)
cy.get('[data-column-id="action"] > div > span').first().find('svg').last().click()
cy.get('.login-btn').click()
cy.get(viewSelectors.tabReleaseOverview).click()
cy.get(viewSelectors.actionsInReleaseListTbl).should('have.length', numberOfReleases - i)
cy.get(viewSelectors.actionsInReleaseListTbl).first().find('svg').last().click()
cy.get(viewSelectors.btnDeleteRelease).click()
verifyDeleteSuccessfully()
}
}
Expand Down
10 changes: 6 additions & 4 deletions cypress/e2e/components/export-spreadsheet.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// SPDX-License-Identifier: EPL-2.0
// License-Filename: LICENSE

import { viewSelectors } from './selectors'

const verifyFileExported = () => {
const currentDate = new Date().toISOString().split("T")[0]
cy.readFile(`cypress/downloads/components-${currentDate}.xlsx`)
Expand All @@ -21,15 +23,15 @@ describe('Export Spreadsheet', () => {
})

it('TC13: Export components without releases', () => {
cy.get('#project-export').click()
cy.get('.dropdown-menu > :nth-child(1)').click()
cy.get(viewSelectors.btnExportSpreadsheet).click()
cy.get(viewSelectors.btnExportComponentsOnly).click()
verifyFileExported()
cy.removeDownloadedFiles()
})

it('TC14: Export components with releases', () => {
cy.get('#project-export').click()
cy.get('.dropdown-menu > :nth-child(2)').click()
cy.get(viewSelectors.btnExportSpreadsheet).click()
cy.get(viewSelectors.btnExportComponentsWithReleases).click()
verifyFileExported()
cy.removeDownloadedFiles()
})
Expand Down
18 changes: 10 additions & 8 deletions cypress/e2e/components/import.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
// SPDX-License-Identifier: EPL-2.0
// License-Filename: LICENSE

import { viewSelectors } from './selectors'

const verifyModalData = (testData) => {
cy.get('.modal-body > div > p').contains('The new Component and new Release will be created, do you want to import?')
cy.get('.modal-body > div > div:nth-child(2)').contains(`New Components: ${testData.component}`)
cy.get('.modal-body > div > div:nth-child(3)').contains(`New Releases: ${testData.release.name}`)
cy.get(viewSelectors.dialogUploadSBOM.message1).contains('The new Component and new Release will be created, do you want to import?')
cy.get(viewSelectors.dialogUploadSBOM.message2).contains(`New Components: ${testData.component}`)
cy.get(viewSelectors.dialogUploadSBOM.message3).contains(`New Releases: ${testData.release.name}`)
}

const verifyImportSuccess = (testData) => {
Expand All @@ -24,20 +26,20 @@ const verifyComponent = (component) => {
}

const verifyRelease = (release) => {
cy.get('#tab-Releases').click()
cy.get(viewSelectors.tabReleaseOverview).click()
cy.get(':nth-child(3) > .row > :nth-child(2) .gridjs-table > tbody > tr > td:nth-child(1)').contains(release.name)
cy.get(':nth-child(3) > .row > :nth-child(2) .gridjs-table > tbody > tr > td:nth-child(2)').contains(release.version)
}

const selectFile = (filePath) => {
cy.get('input[type="file"]').selectFile(filePath, {force: true})
cy.get(viewSelectors.uploadFiles).selectFile(filePath, {force: true})
}

const importSPDX = (testId) => {
cy.fixture('components/import-spdx').then((data) => {
const testData = data[testId]
selectFile(testData.filePath)
const importButton = cy.get('.modal-content .btn-primary').contains('Import')
const importButton = cy.get(viewSelectors.btnImportAndClose).contains('Import')
verifyModalData(testData)
importButton.click()
verifyImportSuccess(testData)
Expand All @@ -52,12 +54,12 @@ describe('TC12: Import a new component by .spdx/.xml/ .rdf file', () => {
})

it.skip('Import SPDX in .rdf format', () => {
cy.get('a>.btn-secondary').click()
cy.get(viewSelectors.btnImportSBOM).click()
importSPDX('IMPORT_SPDX_001')
})

it('Import SPDX in .spdx format', () => {
cy.get('a>.btn-secondary').click()
cy.get(viewSelectors.btnImportSBOM).click()
importSPDX('IMPORT_SPDX_002')
})

Expand Down
17 changes: 9 additions & 8 deletions cypress/e2e/components/register.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

import { registerComponent } from './utils.js';
import { updateRelease, registerAndVerifyRelease, updateAndVerifyReleaseAfterUpdate, gotoUpdateReleasePageFromViewReleasePage } from '../releases/utils.js';
import { addEditSelectors } from './selectors'

function verifyComponentAfterCreated(testId) {
cy.log('[Info] Validate Testcase')
cy.get('.btn-group > :nth-child(1) > .btn')
cy.get(addEditSelectors.btnUpdateComponent)
.contains('Update Component')
cy.fixture('components/register').then((component) => {
const dataTest = component[testId]
Expand All @@ -30,19 +31,19 @@ function verifyComponentAfterCreated(testId) {
case 'description':
case 'owner_accounting_unit':
case 'owner_billing_group':
cy.get('#' + keyFieldName)
cy.get(addEditSelectors.fillData(keyFieldName))
.should('have.value', fieldValue)
break
case 'component_type':
case 'country':
cy.get('#' + keyFieldName)
cy.get(addEditSelectors.fillData(keyFieldName))
.should('have.value', fieldValue.value)
break
case 'default_vendor':
//
break
case 'homeurl':
cy.get('#tag')
cy.get(addEditSelectors.txtHomeUrl)
.should('have.value', dataTest.homeurl)
break
case 'component_owner':
Expand All @@ -54,15 +55,15 @@ function verifyComponentAfterCreated(testId) {
case 'additional_roles':
break
case 'external_id':
cy.get(':nth-child(4) > :nth-child(2) > .row > .col-lg-6 > .form-control')
cy.get(addEditSelectors.addRowExternalId.key)
.should('have.value', fieldValue.key)
cy.get(':nth-child(4) > :nth-child(2) > .row > .col-lg-5 > .form-control')
cy.get(addEditSelectors.addRowExternalId.value)
.should('have.value', fieldValue.value)
break
case 'additional_data':
cy.get(':nth-child(5) > :nth-child(2) > .row > .col-lg-6 > .form-control')
cy.get(addEditSelectors.addRowAdditionalData.key)
.should('have.value', fieldValue.key)
cy.get(':nth-child(5) > :nth-child(2) > .row > .col-lg-5 > .form-control')
cy.get(addEditSelectors.addRowAdditionalData.value)
.should('have.value', fieldValue.value)
break
default:
Expand Down
89 changes: 89 additions & 0 deletions cypress/e2e/components/selectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright (C) TOSHIBA CORPORATION, 2024. Part of the SW360 Frontend Project.
// Copyright (C) Toshiba Software Development (Vietnam) Co., Ltd., 2024. Part of the SW360 Frontend Project.

// This program and the accompanying materials are made
// available under the terms of the Eclipse Public License 2.0
// which is available at https://www.eclipse.org/legal/epl-2.0/

// SPDX-License-Identifier: EPL-2.0
// License-Filename: LICENSE

// elements of add/edit component page
export const addEditSelectors = {
btnCreateComponent: '.btn-toolbar button[type="submit"]',
btnUpdateComponent: '.btn-group > :nth-child(1) > .btn',
fillData: (key) => `#${key}`,
txtHomeUrl: '#tag',
btnDeleteAllModerators: ':nth-child(2) > :nth-child(3) > :nth-child(2) > span',
dialogVendor: {
"openDialog": "#default_vendor",
"dialog": ".modal.show > .modal-dialog > .modal-content",
"addVendorBtn": ".justify-content-end > :nth-child(2)",
"addVendorBtnInAddVendorDialog": "",
"searchBtn": ":nth-child(2) > .modal-body > :nth-child(1) > .col-lg-4 > :nth-child(1)",
"selectUser": "[data-column-id=\"vendorId\"] > :nth-child(1) > div > .form-check-input",
"selectVendorBtn": ".justify-content-end > :nth-child(3)"
},

dialogOwner: {
"openDialog": "#component_owner",
"dialog": ".modal.show > .modal-dialog > .modal-content",
"searchBtn": ".modal.show > .modal-dialog > .modal-content > .modal-body > :nth-child(1) > .col-lg-4 > :nth-child(1)",
"selectUser": "[data-column-id=\"user-selection\"] .form-check-input",
"selectUsersBtn": ".justify-content-end > .btn-primary"
},

dialogModerator: {
"openDialog": "#moderators",
"dialog": ".modal.show > .modal-dialog > .modal-content",
"searchBtn": ".modal.show > .modal-dialog > .modal-content > .modal-body > :nth-child(1) > .col-lg-4 > :nth-child(1)",
"selectUser": "[data-column-id=\"user-selection\"] .form-check-input",
"selectUsersBtn": ".justify-content-end > .btn-primary"
},

addRowExternalId: {
'btnAddRow': ':nth-child(4) > .row > .col-lg-4 > .btn',
'key': '.form-control[aria-describedby="external id key"]',
'value': '.form-control[aria-describedby="external id value"]'
},

addRowAdditionalData: {
'btnAddRow': ':nth-child(5) > .row > .col-lg-4 > .btn',
'key': '.form-control[aria-describedby="additional data key"]',
'value': '.form-control[aria-describedby="additional data value"]'
}
}

//elements of view page
export const viewSelectors = {
navComponents: '[href="/components"]',
tblComponentList: '[style="margin-bottom: 20px;"] > .col',
hyperlinkComponentNames: '[data-column-id="name"] > div > .link',
tabReleaseOverview:'#tab-Releases',
tblReleasesList: ':nth-child(3) > .row > :nth-child(2) > .gridjs',
dialogDeleteComponent: {
dialog: '.modal-content',
btnDeleteComponent: '.login-btn',
alertSuccess: '.alert-success',
btnClose: '.delete-btn'

},
btnExportSpreadsheet: '#project-export',
btnExportComponentsOnly: '.dropdown-menu > :nth-child(1)',
btnExportComponentsWithReleases: '.dropdown-menu > :nth-child(2)',
btnImportSBOM: 'a>.btn-secondary',
uploadFiles: 'input[type="file"]',
dialogUploadSBOM: {
message1: '.modal-body > div > p',
message2: '.modal-body > div > div:nth-child(2)',
message3: '.modal-body > div > div:nth-child(3)',
btnImportAndClose: '.modal-content .btn-primary'

},

// Release Overview tab
actionsInReleaseListTbl: '[data-column-id="action"] > div > span',
btnDeleteRelease: '.login-btn'
}

viewSelectors.btnImportAndClose
Loading

0 comments on commit 79eb089

Please sign in to comment.