-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Cypress): Add test script for licenses page
Signed-off-by: hoangnt2 <[email protected]>
- Loading branch information
1 parent
480fe68
commit 39ac555
Showing
15 changed files
with
819 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// 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 | ||
|
||
import { addEditSelectors, viewSelectors } from './selectors' | ||
import { deleteLicensesBeforeRegisterUpdate, gotoUpdateLicensePage } from './utils' | ||
|
||
function deleteLicense() { | ||
cy.get(addEditSelectors.btnDeleteLicense).click() | ||
cy.get(addEditSelectors.dlgDeleteLicense.dialog).should('be.visible') | ||
.then(() => { | ||
cy.get(addEditSelectors.dlgDeleteLicense.btnDeleteLicense).click() | ||
}) | ||
cy.get(addEditSelectors.dlgDeleteLicense.dialog).should('not.exist') | ||
cy.get(viewSelectors.alertMessage).contains('Success: License removed successfully!') | ||
} | ||
|
||
function verifyDeletedLicense(licenseShortName) { | ||
cy.get(viewSelectors.tblLicenseList).then(() => { | ||
cy.contains('a', licenseShortName).should('not.exist') | ||
}) | ||
} | ||
|
||
describe('Delete a license', () => { | ||
|
||
before(() => { | ||
deleteLicensesBeforeRegisterUpdate('licenses/update', true) | ||
cy.fixture('licenses/delete').then((license) => { | ||
const fullName = license['TC05_DELETE_LICENSE'].full_name | ||
const shortName = license['TC05_DELETE_LICENSE'].short_name | ||
cy.createLicenseByAPI(fullName, shortName) | ||
}) | ||
}) | ||
|
||
beforeEach(() => { | ||
cy.login('admin') | ||
}) | ||
|
||
it('TC05: Delete an existing license', () => { | ||
cy.fixture('licenses/delete').then((license) => { | ||
const shortName = license['TC05_DELETE_LICENSE'].short_name | ||
// todo search a license by quick filter | ||
gotoUpdateLicensePage(shortName) | ||
deleteLicense() | ||
verifyDeletedLicense(shortName) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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 | ||
|
||
import { viewSelectors } from './selectors' | ||
|
||
const verifyFileExported = () => { | ||
const downloadedFileName = 'Licenses.xlsx' | ||
cy.verifyDownloadedFile(downloadedFileName) | ||
} | ||
|
||
describe('Export License', () => { | ||
beforeEach(() => { | ||
cy.login('admin') | ||
cy.visit(`${Cypress.env('sw360_base_url')}/licenses`) | ||
cy.get(viewSelectors.tblLicenseList).should('be.visible') | ||
cy.removeDownloadsFolder() | ||
}) | ||
|
||
it('TC06: Check Export Licenses', () => { | ||
cy.downloadFile(viewSelectors.btnExportSpreadsheet) | ||
verifyFileExported() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// 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 | ||
|
||
import { viewSelectors } from './selectors' | ||
import { registerLicense, verifyDetailsLicense, deleteLicensesBeforeRegisterUpdate } from './utils' | ||
|
||
function gotoLicenseDetailPage(licenseShortName) { | ||
cy.contains('a', licenseShortName).as('liceseName') | ||
cy.get('@liceseName').click() | ||
} | ||
|
||
function verifyAddedLicenseInLicenseList(licenseShortName) { | ||
cy.contains('a', licenseShortName).should('be.visible') | ||
} | ||
|
||
function updateExternalLink(testData) { | ||
cy.get(viewSelectors.externalLink).clear() | ||
.type(testData) | ||
cy.get(viewSelectors.btnSave).click() | ||
cy.get(viewSelectors.alertMessage).contains(' Success: Update External Link Success!') | ||
cy.get(viewSelectors.externalLink).should('have.value', testData) | ||
} | ||
|
||
function selectWhiteList(testData) { | ||
cy.get(viewSelectors.cbWhiteList).as('cbWhiteLists').then(($checkboxes) => { | ||
const checkUncheckPromises = $checkboxes.map(($checkbox, index) => { | ||
if (testData[index] === false) { | ||
return cy.wrap($checkbox).uncheck({ force: true }).then(() => $checkbox) | ||
} else if (testData[index] === true) { | ||
return cy.wrap($checkbox).check({ force: true }).then(() => $checkbox) | ||
} | ||
}) | ||
return Cypress.Promise.all(checkUncheckPromises); | ||
}) | ||
} | ||
|
||
function updateWhiteList(testData) { | ||
cy.get(viewSelectors.tabObligations).click() | ||
cy.get(viewSelectors.btnEditWhiteList).click() | ||
cy.get(viewSelectors.tblUpdateWhiteList).should('be.visible') | ||
selectWhiteList(testData) | ||
cy.get(viewSelectors.btnUpdateWhiteList).click() | ||
// todo verify ' Success: License updated successfully!') | ||
cy.contains('button', 'Edit License').should('exist') | ||
} | ||
|
||
function updateWhiteListAndVerify(testData) { | ||
cy.get(viewSelectors.tabObligations).click() | ||
cy.get(viewSelectors.btnEditWhiteList).click() | ||
cy.get(viewSelectors.tblUpdateWhiteList).as('tblWhiteList').should('be.visible') | ||
cy.wrap(selectWhiteList(testData)).then(() => { | ||
let obligationsOutput = 0 | ||
cy.get('@cbWhiteLists').each(($checkbox) => { | ||
if ($checkbox.is(':checked')) { | ||
obligationsOutput++ | ||
} | ||
}).then(() => { | ||
cy.get(viewSelectors.btnUpdateWhiteList).click() | ||
// todo verify ' Success: License updated successfully!') | ||
cy.contains('button', 'Edit License').should('exist') | ||
cy.get(viewSelectors.tabObligations).click() | ||
cy.get(viewSelectors.tblLinkedObligations).as('tblLinkedObligations') | ||
cy.get('@tblLinkedObligations').should('not.contain','No matching records found') | ||
cy.get('@tblLinkedObligations').find('tr').should('have.length', obligationsOutput) | ||
}) | ||
}) | ||
} | ||
|
||
describe('Register a license', () => { | ||
|
||
before(() => { | ||
deleteLicensesBeforeRegisterUpdate('licenses/register', false) | ||
}) | ||
|
||
beforeEach(() => { | ||
cy.login('admin') | ||
}) | ||
|
||
it('TC01: Create a license with mandatory fields then edit External link', () => { | ||
cy.fixture('licenses/register').then((license) => { | ||
const testData = license['TC01_REQUIRED_FIELDS'] | ||
const licenseShortName = testData.license_tab.short_name | ||
const externalLink = testData.external_link | ||
registerLicense(testData) | ||
verifyAddedLicenseInLicenseList(licenseShortName) | ||
gotoLicenseDetailPage(licenseShortName) | ||
updateExternalLink(externalLink) | ||
verifyDetailsLicense(testData) | ||
}) | ||
}) | ||
|
||
it('TC02: Create a license with all fields', () => { | ||
cy.fixture('licenses/register').then((license) => { | ||
const testData = license['TC02_ALL_FIELDS'] | ||
const licenseShortName = testData.license_tab.short_name | ||
registerLicense(testData) | ||
verifyAddedLicenseInLicenseList(licenseShortName) | ||
gotoLicenseDetailPage(licenseShortName) | ||
verifyDetailsLicense(testData) | ||
}) | ||
}) | ||
|
||
it('TC03: Create a license with linked obligations then edit whitelist', () => { | ||
cy.fixture('licenses/register').then((license) => { | ||
const testData = license['TC03_LINKED_OBLIGATION'] | ||
const licenseShortName = testData.license_tab.short_name | ||
registerLicense(testData) | ||
// todo search a license by quick filter | ||
verifyAddedLicenseInLicenseList(licenseShortName) | ||
gotoLicenseDetailPage(licenseShortName) | ||
updateWhiteListAndVerify(testData.update_white_list) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// 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 page | ||
const btnAddObligation = 'Add Obligation' | ||
const btnCreateLicense = '[href=""] > .btn-primary' | ||
const btnUpdateLicense = ':nth-child(1) > .btn' | ||
const txtFullName = '#fullName' | ||
const txtShortName = '#shortName' | ||
const selectLicenseType = '#licenseTypeDatabaseId' | ||
const selectOSIApproved = '#OSIApproved' | ||
const selectFSFFreeLibre = '#FSFLibre' | ||
const cbIsChecked = '#isChecked' | ||
const txtNote = '#note' | ||
const txtLicenseText = '#text' | ||
const tabLicense = '#tab-details' | ||
const tabLinkedObligations = '#tab-obligations' | ||
const tblObligations = '.gridjs' | ||
const dlgLicenseObligations = { | ||
'sltDialog': '.modal-content', | ||
'sltTable': '.modal-body > :nth-child(1) > .row > :nth-child(2) > .gridjs', | ||
'sltCheckbox': '[data-column-id="obligationId"] > div > .checkbox-control', | ||
'sltAddBtn': '.modal-footer [type="button"]:nth-child(2)' | ||
} | ||
const btnDeleteLicense = ':nth-child(2) > .btn' | ||
const dlgDeleteLicense = { | ||
'dialog': '.modal-content', | ||
'btnDeleteLicense': '.login-btn', | ||
'txtNotification': '.modal-body > .fade' | ||
} | ||
const rowsLinkedObligation = '.gridjs-tbody > .gridjs-tr' | ||
const dlgDeleteLinkedObligation = { | ||
'dialog': '.modal-content', | ||
'btnDeleteObligation': '.login-btn' | ||
} | ||
|
||
export const addEditSelectors = { | ||
btnAddObligation, | ||
btnCreateLicense, | ||
btnUpdateLicense, | ||
txtFullName, | ||
txtShortName, | ||
selectLicenseType, | ||
selectOSIApproved, | ||
selectFSFFreeLibre, | ||
cbIsChecked, | ||
txtNote, | ||
txtLicenseText, | ||
tabLicense, | ||
tabLinkedObligations, | ||
tblObligations, | ||
dlgLicenseObligations, | ||
btnDeleteLicense, | ||
dlgDeleteLicense, | ||
rowsLinkedObligation, | ||
dlgDeleteLinkedObligation | ||
} | ||
|
||
//elements of view page | ||
const tblLicenseList = '.gridjs-tbody' | ||
const btnAddLicense = '[href="/licenses/add"] > .btn' | ||
const navLicense = '.navbar-nav [href="/licenses"]' | ||
const externalLink = '[name="externalLicenseLink"]' | ||
const btnSave = '[class^="detail_button-save"]' | ||
const fullName = '.table > tbody > :nth-child(1) > :nth-child(2)' | ||
const shortName = '.table > tbody > :nth-child(2) > :nth-child(2)' | ||
const isChecked = '.badge' | ||
const licenseType = '.table > tbody > :nth-child(4) > :nth-child(2)' | ||
const OSIApproved = ':nth-child(5) > :nth-child(2) > span' | ||
const FSFFreeLibre = ':nth-child(6) > :nth-child(2) > span' | ||
const note = ':nth-child(8) > :nth-child(2)' | ||
const tabText = '#tab-text' | ||
const licenseText = '[class^=detail_pre-text]' | ||
const tabObligations = '#tab-obligations' | ||
const tblLinkedObligations = ':nth-child(4) > .row > :nth-child(1) > :nth-child(2) > .gridjs .gridjs-table .gridjs-tbody' | ||
const btnEditWhiteList = '[href=""] > .btn' | ||
const tblWhiteList = ':nth-child(4) > .row > :nth-child(1) > :nth-child(2) > .gridjs tbody' | ||
const tblUpdateWhiteList = ':nth-child(4) > .row > :nth-child(2) > .gridjs .gridjs-tbody' | ||
const cbWhiteList = '[data-column-id="obligationId"] > :nth-child(1) > div > .form-check-input' | ||
const btnUpdateWhiteList = '.btn-group > :nth-child(1) > .btn' | ||
const alertMessage = '.alert-success' | ||
const btnExportSpreadsheet = '[href="/licenses"] > .btn' | ||
|
||
export const viewSelectors = { | ||
tblLicenseList, | ||
btnAddLicense, | ||
navLicense, | ||
externalLink, | ||
btnSave, | ||
fullName, | ||
shortName, | ||
isChecked, | ||
licenseType, | ||
OSIApproved, | ||
FSFFreeLibre, | ||
note, | ||
tabText, | ||
licenseText, | ||
tabObligations, | ||
tblLinkedObligations, | ||
btnEditWhiteList, | ||
tblWhiteList, | ||
tblUpdateWhiteList, | ||
cbWhiteList, | ||
btnUpdateWhiteList, | ||
alertMessage, | ||
btnExportSpreadsheet | ||
} |
Oops, something went wrong.