Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test autosaving of gamma correction setting #9124

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,33 @@
//
// SPDX-License-Identifier: MIT

/// <reference types="cypress" />
/// / <reference types="../../support/index.d.ts" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type file is not implemented yet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed


import { taskName } from '../../support/const';
import { generateString } from '../../support/utils';

context('Saving setting to local storage.', () => {
const caseId = '68';
const defaultGammaValue = 1;
const nbumps = 5;
const step = 0.01;
function bumpGamma(nsteps) {
const gammaFilterClass = '.cvat-image-setups-gamma';
const wrapper = '.cvat-image-setups-filters';
const action = generateString(nsteps, 'rightarrow');
cy.applyActionToSliders(wrapper, [gammaFilterClass], action);
}
function setUpGamma(nsteps) {
cy.get('.cvat-canvas-image-setups-trigger').click();
cy.contains('Reset color settings').click();
bumpGamma(nsteps);
cy.get('.cvat-canvas-image-setups-trigger').click();
}
function resetColorSettings() {
cy.get('.cvat-canvas-image-setups-trigger').click();
cy.contains('Reset color settings').click();
cy.get('.cvat-canvas-image-setups-trigger').click();
}

function setupAndSaveSettings(check) {
cy.openSettings();
Expand Down Expand Up @@ -54,16 +75,28 @@ context('Saving setting to local storage.', () => {

cy.closeSettings();
}
function testGammaSetting() {
const expValue = defaultGammaValue + nbumps * step;
cy.get('.cvat-canvas-image-setups-trigger').click();
cy.get('.cvat-image-setups-gamma').within(() => {
cy.get('[role=slider]').should('have.attr', 'aria-valuenow', expValue);
});
cy.get('.cvat-canvas-image-setups-trigger').click();
}

before(() => {
cy.openTaskJob(taskName);
});

describe(`Testing case "${caseId}"`, () => {
it('Check some settings. Reload a page. The settings are saved.', () => {
setUpGamma(nbumps);
setupAndSaveSettings(true);
cy.reload();
testCheckedSettings(true);
testGammaSetting();
resetColorSettings();

setupAndSaveSettings(false);
cy.reload();
testCheckedSettings(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,6 @@ context('Canvas color settings feature', () => {
);
}

function applyStringAction(wrapper, slidersClassNames, action) {
cy.get(wrapper).within(() => {
cy.wrap(slidersClassNames).each(($el) => {
cy.wrap($el)
.get($el)
.within(() => {
cy.get('[role=slider]').type(action);
});
});
});
cy.get('.ant-tooltip').invoke('hide');
}

function checkSlidersValue(wrapper, slidersClassNames, expectedResult) {
cy.get(wrapper).within(() => {
cy.wrap(slidersClassNames).each(($el, index) => {
cy.wrap($el)
.get($el)
.within(() => {
cy.get('[role=slider]')
.should('have.attr', 'aria-valuenow', expectedResult[index]);
});
});
});
}

before(() => {
cy.openTaskJob(taskName);
cy.get('.cvat-canvas-image-setups-trigger').click();
Expand All @@ -82,10 +56,10 @@ context('Canvas color settings feature', () => {
describe(`Testing case "${caseId}"`, () => {
it('Check application of CSS filters', () => {
const stringAction = generateString(countActionMoveSlider, 'rightarrow');
applyStringAction(
cy.applyActionToSliders(
'.cvat-canvas-image-setups-content', classNameSliders, stringAction,
);
checkSlidersValue(
cy.checkSlidersValues(
'.cvat-canvas-image-setups-content', classNameSliders, expectedResultInSetting,
);
const expectedResultInBackground = (defaultValueInSidebar + countActionMoveSlider) / 100;
Expand All @@ -94,10 +68,10 @@ context('Canvas color settings feature', () => {

it('Check application of image processing filters', () => {
const stringAction = generateString(countActionMoveFilterSlider, 'rightarrow');
applyStringAction(
cy.applyActionToSliders(
'.cvat-image-setups-filters', filterSlidersClassNames, stringAction,
);
checkSlidersValue(
cy.checkSlidersValues(
'.cvat-image-setups-filters', filterSlidersClassNames, expectedResultInSettingFilters,
);
cy.get('.cvat-notification-notice-image-processing-error').should('not.exist');
Expand All @@ -107,30 +81,30 @@ context('Canvas color settings feature', () => {
cy.get('.cvat-image-setups-reset-color-settings').find('button').click();
const expectedResultInBackground = defaultValueInSidebar / 100;
checkStateValuesInBackground(expectedResultInBackground);
checkSlidersValue(
cy.checkSlidersValues(
'.cvat-canvas-image-setups-content', classNameSliders, defaultValueInSetting,
);
checkSlidersValue(
cy.checkSlidersValues(
'.cvat-image-setups-filters', filterSlidersClassNames, defaultValueInSettingFilters,
);
});

it('Check persisting image filters across jobs', () => {
const sliderAction = generateString(countActionMoveSlider, 'rightarrow');
const filterAction = generateString(countActionMoveFilterSlider, 'rightarrow');
applyStringAction(
cy.applyActionToSliders(
'.cvat-canvas-image-setups-content', classNameSliders, sliderAction,
);
applyStringAction(
cy.applyActionToSliders(
'.cvat-image-setups-filters', filterSlidersClassNames, filterAction,
);
cy.interactMenu('Open the task');
cy.openJob(1);
cy.get('.cvat-canvas-image-setups-trigger').click();
checkSlidersValue(
cy.checkSlidersValues(
'.cvat-canvas-image-setups-content', classNameSliders, expectedResultInSetting,
);
checkSlidersValue(
cy.checkSlidersValues(
'.cvat-image-setups-filters', filterSlidersClassNames, expectedResultInSettingFilters,
);
cy.get('.cvat-notification-notice-image-processing-error').should('not.exist');
Expand Down
4 changes: 2 additions & 2 deletions tests/cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

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

/* eslint security/detect-non-literal-fs-filename: 0 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will /* eslint-disable security/detect-non-literal-fs-filename */ work?
Looks a bit cleaner than : 0

Copy link
Contributor Author

@archibald1418 archibald1418 Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that works. Applied


const fs = require('fs');
// eslint-disable-next-line import/no-extraneous-dependencies
const { isFileExist } = require('cy-verify-downloads');
Expand All @@ -28,7 +30,6 @@ module.exports = (on, config) => {
});
on('task', {
listFiles(folderName) {
// eslint-disable-next-line security/detect-non-literal-fs-filename
return fs.readdirSync(folderName);
},
});
Expand All @@ -45,7 +46,6 @@ module.exports = (on, config) => {
});
on('after:spec', (spec, results) => {
if (results && results.stats.failures === 0 && results.video) {
// eslint-disable-next-line security/detect-non-literal-fs-filename
fs.unlinkSync(results.video);
}
});
Expand Down
26 changes: 26 additions & 0 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -1805,3 +1805,29 @@ Cypress.Commands.add('makeCustomImage', (directory, fileName,
);
});
});

Cypress.Commands.add('checkSlidersValues', (wrapper, slidersClassNames, expectedResults) => {
cy.get(wrapper).within(() => {
cy.wrap(slidersClassNames).each(($el, index) => {
cy.wrap($el)
.get($el)
.within(() => {
cy.get('[role=slider]')
.should('have.attr', 'aria-valuenow', expectedResults[index]);
});
});
});
});

Cypress.Commands.add('applyActionToSliders', (wrapper, slidersClassNames, action) => {
cy.get(wrapper).within(() => {
cy.wrap(slidersClassNames).each(($el) => {
cy.wrap($el)
.get($el)
.within(() => {
cy.get('[role=slider]').type(action);
});
});
});
cy.get('.ant-tooltip').invoke('hide');
});
Loading