Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Add test for gamma correction filter (cvat-ai#6833)
Browse files Browse the repository at this point in the history
<!-- Raise an issue to propose your change
(https://github.com/opencv/cvat/issues).
It helps to avoid duplication of efforts from multiple independent
contributors.
Discuss your ideas with maintainers to be sure that changes will be
approved and merged.
Read the [Contribution
guide](https://opencv.github.io/cvat/docs/contributing/). -->

<!-- Provide a general summary of your changes in the Title above -->

### Motivation and context
<!-- Why is this change required? What problem does it solve? If it
fixes an open
issue, please link to the issue here. Describe your changes in detail,
add
screenshots. -->
Test for cvat-ai#6771

### How has this been tested?
<!-- Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc. -->
Added cypress test

### Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply.
If an item isn't applicable for some reason, then ~~explicitly
strikethrough~~ the whole
line. If you don't do that, GitHub will show incorrect progress for the
pull request.
If you're unsure about any of these, don't hesitate to ask. We're here
to help! -->
- [x] I submit my changes into the `develop` branch
- ~~[ ] I have added a description of my changes into the
[CHANGELOG](https://github.com/opencv/cvat/blob/develop/CHANGELOG.md)
file~~
- ~~[ ] I have updated the documentation accordingly~~
- [x] I have added tests to cover my changes
- ~~[ ] I have linked related issues (see [GitHub docs](

https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword))~~
- ~~[ ] I have increased versions of npm packages if it is necessary

([cvat-canvas](https://github.com/opencv/cvat/tree/develop/cvat-canvas#versioning),

[cvat-core](https://github.com/opencv/cvat/tree/develop/cvat-core#versioning),

[cvat-data](https://github.com/opencv/cvat/tree/develop/cvat-data#versioning)
and

[cvat-ui](https://github.com/opencv/cvat/tree/develop/cvat-ui#versioning))~~

### License

- [x] I submit _my code changes_ under the same [MIT License](
https://github.com/opencv/cvat/blob/develop/LICENSE) that covers the
project.
  Feel free to contact the maintainers if that's a concern.
  • Loading branch information
klakhov authored and mikhail-treskin committed Oct 25, 2023
1 parent f79bfbf commit 830c0e4
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 59 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright (C) 2020-2022 Intel Corporation
// Copyright (C) 2023 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

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

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

context('Canvas color settings feature', () => {
const caseId = '26';
const countActionMoveSlider = 10;
const defaultValueInSidebar = 100;
const defaultValueInSetting = [
defaultValueInSidebar,
defaultValueInSidebar,
defaultValueInSidebar,
];
const expectedResultInSetting = [
defaultValueInSidebar + countActionMoveSlider,
defaultValueInSidebar + countActionMoveSlider,
defaultValueInSidebar + countActionMoveSlider,
];
const classNameSliders = [
'.cvat-image-setups-brightness',
'.cvat-image-setups-contrast',
'.cvat-image-setups-saturation',
];

const countActionMoveFilterSlider = 30;
const defaultValueInSettingFilters = [
1.0,
];
const expectedResultInSettingFilters = [
1.3,
];
const filterSlidersClassNames = [
'.cvat-image-setups-gamma',
];

function checkStateValuesInBackground(expectedValue) {
cy.get('#cvat_canvas_background')
.should('have.attr', 'style')
.and(
'contain',
`filter: brightness(${expectedValue}) contrast(${expectedValue}) saturate(${expectedValue})`,
);
}

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);
});
});
});
}

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();
});

describe(`Testing case "${caseId}"`, () => {
it('Check application of CSS filters', () => {
const stringAction = generateString(countActionMoveSlider, 'rightarrow');
applyStringAction(
'.cvat-canvas-image-setups-content', classNameSliders, stringAction,
);
checkSlidersValue(
'.cvat-canvas-image-setups-content', classNameSliders, expectedResultInSetting,
);
const expectedResultInBackground = (defaultValueInSidebar + countActionMoveSlider) / 100;
checkStateValuesInBackground(expectedResultInBackground);
});

it('Check application of image processing filters', () => {
const stringAction = generateString(countActionMoveFilterSlider, 'rightarrow');
applyStringAction(
'.cvat-image-setups-filters', filterSlidersClassNames, stringAction,
);
checkSlidersValue(
'.cvat-image-setups-filters', filterSlidersClassNames, expectedResultInSettingFilters,
);
cy.get('.cvat-notification-notice-image-processing-error').should('not.exist');
});

it('Check reset of settings', () => {
cy.get('.cvat-image-setups-reset-color-settings').find('button').click();
const expectedResultInBackground = defaultValueInSidebar / 100;
checkStateValuesInBackground(expectedResultInBackground);
checkSlidersValue(
'.cvat-canvas-image-setups-content', classNameSliders, defaultValueInSetting,
);
checkSlidersValue(
'.cvat-image-setups-filters', filterSlidersClassNames, defaultValueInSettingFilters,
);
});
});
});

0 comments on commit 830c0e4

Please sign in to comment.