From ca4563513b17cdcb692ad27da8c3178303fba205 Mon Sep 17 00:00:00 2001 From: Dmitry Kruchinin <33020454+dvkruchinin@users.noreply.github.com> Date: Thu, 12 Aug 2021 14:30:18 +0300 Subject: [PATCH] Cypress test. Project export feature. (#3539) * Add css class for modal export input * Added cypress test. Added command. * Update tests/cypress/support/commands_projects.js Co-authored-by: Dmitry Kalinin * Update cvat-ui/src/components/export-dataset/export-dataset-modal.tsx Co-authored-by: Dmitry Kalinin Co-authored-by: Dmitry Kalinin --- .../export-dataset/export-dataset-modal.tsx | 2 +- .../case_103_project_export.js | 113 ++++++++++++++++++ tests/cypress/support/commands_projects.js | 25 +++- 3 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 tests/cypress/integration/actions_projects_models/case_103_project_export.js diff --git a/cvat-ui/src/components/export-dataset/export-dataset-modal.tsx b/cvat-ui/src/components/export-dataset/export-dataset-modal.tsx index 400cdc4e..2446775a 100644 --- a/cvat-ui/src/components/export-dataset/export-dataset-modal.tsx +++ b/cvat-ui/src/components/export-dataset/export-dataset-modal.tsx @@ -135,7 +135,7 @@ function ExportDatasetModal(): JSX.Element { Save images - + diff --git a/tests/cypress/integration/actions_projects_models/case_103_project_export.js b/tests/cypress/integration/actions_projects_models/case_103_project_export.js new file mode 100644 index 00000000..78361179 --- /dev/null +++ b/tests/cypress/integration/actions_projects_models/case_103_project_export.js @@ -0,0 +1,113 @@ +// Copyright (C) 2021 Intel Corporation +// +// SPDX-License-Identifier: MIT + +/// + +import { projectName, labelName } from '../../support/const_project'; + +context('Export project dataset.', { browser: '!firefox' }, () => { + const caseID = 103; + const taskName = `Task case ${caseID}`; + const attrName = `Attr for ${labelName}`; + const textDefaultValue = 'Some value for type Text'; + const imagesCount = 1; + const imageFileName = `image_${taskName.replace(/\s+/g, '_').toLowerCase()}`; + const width = 800; + const height = 800; + const posX = 10; + const posY = 10; + const color = 'white'; + const archiveName = `${imageFileName}.zip`; + const archivePath = `cypress/fixtures/${archiveName}`; + const imagesFolder = `cypress/fixtures/${imageFileName}`; + const directoryToArchive = imagesFolder; + const advancedConfigurationParams = false; + const forProject = true; + const attachToProject = false; + const multiAttrParams = false; + let projectID = ''; + + function getProjectID(projectName) { + cy.contains('.cvat-project-name', projectName) + .parents('.cvat-project-details') + .should('have.attr', 'cvat-project-id') + .then(($projectID) => { + projectID = $projectID; + }); + } + + function testCheckFile(file) { + cy.task('listFiles', 'cypress/fixtures').each((fileName) => { + if (fileName.match(file)) { + cy.readFile(`cypress/fixtures/${fileName}`).should('exist'); + } + }); + } + + before(() => { + cy.imageGenerator(imagesFolder, imageFileName, width, height, color, posX, posY, labelName, imagesCount); + cy.createZipArchive(directoryToArchive, archivePath); + cy.openProject(projectName); + getProjectID(projectName); + cy.createAnnotationTask( + taskName, + labelName, + attrName, + textDefaultValue, + archiveName, + multiAttrParams, + advancedConfigurationParams, + forProject, + attachToProject, + projectName, + ); + }); + + after(() => { + cy.goToProjectsList(); + cy.deleteProject(projectName, projectID); + }); + + describe(`Testing "Case ${caseID}"`, () => { + it('Export project dataset. Annotation.', () => { + cy.goToProjectsList(); + const exportAnnotation = { + projectName: projectName, + as: 'exportAnnotations', + type: 'annotations', + dumpType: 'CVAT for images', + }; + cy.exportProject(exportAnnotation); + const regex = new RegExp(`^project_${projectName.toLowerCase()}-.*-${exportAnnotation.dumpType.toLowerCase()}.*.zip$`); + testCheckFile(regex); + }); + + it('Export project dataset. Dataset.', () => { + cy.goToProjectsList(); + const exportDataset = { + projectName: projectName, + as: 'exportDataset', + type: 'dataset', + dumpType: 'CVAT for video', + }; + cy.exportProject(exportDataset); + const regex = new RegExp(`^project_${projectName.toLowerCase()}-.*-${exportDataset.dumpType.toLowerCase()}.*.zip$`); + testCheckFile(regex); + }); + + it('Export project dataset. Annotation. Rename a archive.', () => { + cy.goToProjectsList(); + const exportAnnotationsRenameArchive = { + projectName: projectName, + as: 'exportAnnotationsRenameArchive', + type: 'annotations', + dumpType: 'CVAT for images', + archiveCustomeName: 'export_project_annotation', + }; + cy.exportProject(exportAnnotationsRenameArchive); + const regex = new RegExp(`^${exportAnnotationsRenameArchive.archiveCustomeName}.zip$`); + testCheckFile(regex); + }); + }); +}); diff --git a/tests/cypress/support/commands_projects.js b/tests/cypress/support/commands_projects.js index e0bb6258..bd12a61b 100644 --- a/tests/cypress/support/commands_projects.js +++ b/tests/cypress/support/commands_projects.js @@ -42,7 +42,7 @@ Cypress.Commands.add('openProject', (projectName) => { cy.get('.cvat-project-details').should('exist'); }); -Cypress.Commands.add('deleteProject', (projectName, projectID, expectedResult = 'success') => { +Cypress.Commands.add('projectActions', (projectName) => { cy.contains('.cvat-projects-project-item-title', projectName) .parents('.cvat-projects-project-item-card') .within(() => { @@ -50,6 +50,10 @@ Cypress.Commands.add('deleteProject', (projectName, projectID, expectedResult = cy.get('[type="button"]').trigger('mouseover'); }); }); +}); + +Cypress.Commands.add('deleteProject', (projectName, projectID, expectedResult = 'success') => { + cy.projectActions(projectName); cy.get('.cvat-project-actions-menu').contains('Delete').click(); cy.get('.cvat-modal-confirm-remove-project') .should('contain', `The project ${projectID} will be deleted`) @@ -63,6 +67,25 @@ Cypress.Commands.add('deleteProject', (projectName, projectID, expectedResult = } }); +Cypress.Commands.add('exportProject', ({ projectName, as, type, dumpType, archiveCustomeName }) => { + cy.projectActions(projectName); + cy.intercept('GET', `/api/v1/projects/**/${type}**`).as(as); + cy.get('.cvat-project-actions-menu').contains('Export project dataset').click(); + cy.get('.cvat-modal-export-project').find('.cvat-modal-export-select').click(); + cy.contains('.cvat-modal-export-option-item', dumpType).click(); + cy.get('.cvat-modal-export-select').should('contain.text', dumpType); + if (type === 'dataset') { + cy.get('.cvat-modal-export-project').find('[type="checkbox"]').should('not.be.checked').check(); + } + if (archiveCustomeName) { + cy.get('.cvat-modal-export-project').find('.cvat-modal-export-filename-input').type(archiveCustomeName); + } + cy.get('.cvat-modal-export-project').contains('button', 'OK').click(); + cy.get('.cvat-notification-notice-export-project-start').should('be.visible'); + cy.wait(`@${as}`, { timeout: 5000 }).its('response.statusCode').should('equal', 202); + cy.wait(`@${as}`).its('response.statusCode').should('equal', 201); +}); + Cypress.Commands.add('deleteProjectViaActions', (projectName) => { cy.get('.cvat-project-top-bar-actions').trigger('mouseover'); cy.get('.cvat-project-actions-menu').within(() => {