Skip to content

Commit

Permalink
Cypress test for issue 1819
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Kruchinin committed Aug 17, 2020
1 parent 90cc36e commit 32b5814
Show file tree
Hide file tree
Showing 8 changed files with 372 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*/

/// <reference types="cypress" />

context('First part of a splitted track is visible', () => {

const issueId = '1819'
const labelName = `Issue ${issueId}`
const taskName = `New annotation task for ${labelName}`
const attrName = `Attr for ${labelName}`
const textDefaultValue = 'Some default value for type Text'
const images = [`image_${issueId}_1.png`,
`image_${issueId}_2.png`,
`image_${issueId}_3.png`]
const width = 800
const height = 800
const posX = 10
const posY = 10
const color = 'gray'
const archiveName = `images_issue_${issueId}.zip`
const archivePath = `cypress/fixtures/${archiveName}`
const imagesFolder = `cypress/fixtures/image_issue_${issueId}`
const directoryToArchive = imagesFolder

before(() => {
cy.visit('auth/login')
cy.login()
for (let img of images) {
cy.imageGenerator(imagesFolder, img, width, height, color, posX, posY, labelName)
}
cy.createZipArchive(directoryToArchive, archivePath)
cy.createAnnotationTask(taskName, labelName, attrName, textDefaultValue, archiveName)
cy.openTaskJob(taskName)
})

describe(`Testing issue "${issueId}"`, () => {
it('Create a track', () => {
cy.createTrack(309, 431, 616, 671)
})
it('Go next with a step', () => {
cy.get('.cvat-player-forward-button')
.click()
cy.get('.cvat-player-frame-selector').within(() => {
cy.get('input[role="spinbutton"]')
.should('have.value', '2')
})
})
it('Split track', () => {
cy.get('body')
.type('{alt}m')
cy.get('#cvat_canvas_shape_1')
.trigger('mousemove', {which: 1})
.trigger('click', {which: 1})
})
it('Go to previous frame', () => {
cy.get('.cvat-player-previous-button')
.click()
cy.get('.cvat-player-frame-selector').within(() => {
cy.get('input[role="spinbutton"]')
.should('have.value', '1')
})
})
it('First part of a splitted track is visible', () => {
cy.get('#cvat_canvas_shape_2')
.should('be.visible')
})
})
})
30 changes: 30 additions & 0 deletions tests/cypress/plugins/createZipArchive/addPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*/

exports.createZipArchive = createZipArchive

const archiver = require('archiver')
const fs = require('fs-extra')

function createZipArchive(args) {
const directoryToArchive = args.directoryToArchive
const output = fs.createWriteStream(args.arhivePath)
const archive = archiver('zip', {
gzip: true,
zlib: { level: 9 }
})

archive.on('error', function(err) {
throw err
})

archive.pipe(output)

archive.directory(`${directoryToArchive}/`, false)
archive.finalize()

return fs.pathExists(archive)
}
12 changes: 12 additions & 0 deletions tests/cypress/plugins/createZipArchive/createZipArchiveCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*/

Cypress.Commands.add('createZipArchive', function (directoryToArchive, arhivePath) {
return cy.task('createZipArchive', {
directoryToArchive: directoryToArchive,
arhivePath: arhivePath
})
})
14 changes: 8 additions & 6 deletions tests/cypress/plugins/imageGenerator/addPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ function imageGenerator(args) {
const posY = args.posY
const message = args.message
const file = path.join(directory, fileName)
const image = new jimp(width, height, color, function (err, image) {
if (err) throw err
jimp.loadFont(jimp.FONT_SANS_64_BLACK, function (err, font) {
return new Promise((resolve) => {
const image = new jimp(width, height, color, function (err, image) {
if (err) throw err
image.print(font, Number(posX), Number(posY), message)
.write(file)
jimp.loadFont(jimp.FONT_SANS_64_BLACK, function (err, font) {
if (err) throw err
image.print(font, Number(posX), Number(posY), message)
.write(file)
})
})
setTimeout(() => resolve(null), '1000')
})
return file
}
2 changes: 2 additions & 0 deletions tests/cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
/// <reference types="cypress" />

const {imageGenerator} = require('../plugins/imageGenerator/addPlugin')
const {createZipArchive} = require('../plugins/createZipArchive/addPlugin')

module.exports = (on) => {
on('task', {imageGenerator})
on('task', {createZipArchive})
}
20 changes: 18 additions & 2 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

require('cypress-file-upload')
require('../plugins/imageGenerator/imageGeneratorCommand')
require('../plugins/createZipArchive/createZipArchiveCommand')

Cypress.Commands.add('login', (username='admin', password='12qwaszx') => {
cy.get('[placeholder="Username"]').type(username)
Expand Down Expand Up @@ -56,8 +57,23 @@ Cypress.Commands.add('openTaskJob', (taskName) => {
})

Cypress.Commands.add('createShape', (ferstX, ferstY, lastX, lastY) => {
cy.get(':nth-child(8) > svg').trigger('mousemove').click()
cy.get(':nth-child(6) > :nth-child(1) > .ant-btn').click()
cy.get('.cvat-draw-rectangle-control').click()
cy.get('.cvat-draw-shape-popover-content')
.find('button')
.contains('Shape')
.click({force: true})
cy.get('.cvat-canvas-container')
.click(ferstX, ferstY)
cy.get('.cvat-canvas-container')
.click(lastX, lastY)
})

Cypress.Commands.add('createTrack', (ferstX, ferstY, lastX, lastY) => {
cy.get('.cvat-draw-rectangle-control').click()
cy.get('.cvat-draw-shape-popover-content')
.find('button')
.contains('Track')
.click({force: true})
cy.get('.cvat-canvas-container')
.click(ferstX, ferstY)
cy.get('.cvat-canvas-container')
Expand Down
Loading

0 comments on commit 32b5814

Please sign in to comment.