Skip to content

Commit

Permalink
Tests for basic Management tab on Quality control page (#8447)
Browse files Browse the repository at this point in the history
<!-- Raise an issue to propose your change
(https://github.com/cvat-ai/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://docs.cvat.ai/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. -->
This PR adds tests for `management` tab that was introduced in #8329 

### 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. -->

### 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 created a changelog fragment <!-- see top comment in
CHANGELOG.md -->~~
- ~~[ ] 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/cvat-ai/cvat/tree/develop/cvat-canvas#versioning),

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

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

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

### License

- [x] I submit _my code changes_ under the same [MIT License](
https://github.com/cvat-ai/cvat/blob/develop/LICENSE) that covers the
project.
  Feel free to contact the maintainers if that's a concern.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced styling for the Allocation Table and Summary components with
new CSS class names for better visual representation.
- Introduced a new Cypress command for creating jobs, improving the
testing process.
- Added a new testing suite for ground truth management, validating key
functionalities in the management page.

- **Bug Fixes**
- Updated test data for regression tests to ensure accuracy in testing
scenarios.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
klakhov authored Sep 19, 2024
1 parent ace55bf commit 6d38124
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ function AllocationTable(props: Readonly<Props>): JSX.Element {
render: (active: boolean, record: RowData): JSX.Element => (
active ? (
<DeleteOutlined
className='cvat-allocation-frame-delete'
onClick={() => { onDeleteFrames([record.frame]); }}
/>
) : (
<Icon
className='cvat-allocation-frame-restore'
onClick={() => { onRestoreFrames([record.frame]); }}
component={RestoreIcon}
/>
Expand All @@ -130,7 +132,7 @@ function AllocationTable(props: Readonly<Props>): JSX.Element {
{
selection.selectedRowKeys.length !== 0 ? (
<>
<Col>
<Col className='cvat-allocation-selection-frame-delete'>
<DeleteOutlined
onClick={() => {
const framesToUpdate = selection.selectedRows
Expand All @@ -141,7 +143,7 @@ function AllocationTable(props: Readonly<Props>): JSX.Element {
}}
/>
</Col>
<Col>
<Col className='cvat-allocation-selection-frame-restore'>
<Icon
onClick={() => {
const framesToUpdate = selection.selectedRows
Expand All @@ -163,7 +165,7 @@ function AllocationTable(props: Readonly<Props>): JSX.Element {
if (!rowData.active) {
return 'cvat-allocation-frame-row cvat-allocation-frame-row-excluded';
}
return 'cvat-allocation-frame';
return 'cvat-allocation-frame-row';
}}
columns={columns}
dataSource={data}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ export default function SummaryComponent(props: Readonly<Props>): JSX.Element {
<Row>
<Col span={10} className='cvat-allocation-summary'>
<Row>
<Col span={12}>
<Col span={12} className='cvat-allocation-summary-excluded'>
<Text>
Excluded count:
{' '}
<Text strong>{excludedCount}</Text>
</Text>
</Col>
<Col span={12}>
<Col span={12} className='cvat-allocation-summary-total'>
<Text>
Total count:
{' '}
Expand All @@ -36,7 +36,7 @@ export default function SummaryComponent(props: Readonly<Props>): JSX.Element {
</Col>
</Row>
<Row>
<Col span={12}>
<Col span={12} className='cvat-allocation-summary-active'>
<Text>
Active count:
{' '}
Expand Down
131 changes: 129 additions & 2 deletions tests/cypress/e2e/features/ground_truth_jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ context('Ground truth jobs', () => {
.should('be.visible');
}

function openManagementTab() {
cy.clickInTaskMenu('Quality control', true);
cy.get('.cvat-task-control-tabs')
.within(() => {
cy.contains('Management').click();
});
}

before(() => {
cy.visit('auth/login');
cy.login();
Expand Down Expand Up @@ -187,6 +195,121 @@ context('Ground truth jobs', () => {
});
});

describe('Testing ground truth management basics', () => {
const serverFiles = ['images/image_1.jpg', 'images/image_2.jpg', 'images/image_3.jpg'];

before(() => {
cy.headlessCreateTask({
labels: [{ name: labelName, attributes: [], type: 'any' }],
name: taskName,
project_id: null,
source_storage: { location: 'local' },
target_storage: { location: 'local' },
}, {
server_files: serverFiles,
image_quality: 70,
use_zip_chunks: true,
use_cache: true,
sorting_method: 'lexicographical',
}).then((taskResponse) => {
taskID = taskResponse.taskID;
[jobID] = taskResponse.jobIDs;
}).then(() => (
cy.headlessCreateJob({
task_id: taskID,
frame_count: 3,
type: 'ground_truth',
frame_selection_method: 'random_uniform',
})
)).then((jobResponse) => {
groundTruthJobID = jobResponse.jobID;
}).then(() => {
cy.visit(`/tasks/${taskID}`);
cy.get('.cvat-task-details').should('exist').and('be.visible');
openManagementTab();
});
});

after(() => {
cy.headlessDeleteTask(taskID);
});

it('Check management page contents.', () => {
cy.get('.cvat-annotations-quality-allocation-table-summary').should('exist');
cy.contains('.cvat-allocation-summary-excluded', '0').should('exist');
cy.contains('.cvat-allocation-summary-total', '3').should('exist');
cy.contains('.cvat-allocation-summary-active', '3').should('exist');

cy.get('.cvat-frame-allocation-table').should('exist');
cy.get('.cvat-allocation-frame-row').should('have.length', 3);
cy.get('.cvat-allocation-frame-row').each(($el, index) => {
cy.wrap($el).within(() => {
cy.contains(`#${index}`).should('exist');
cy.contains(`images/image_${index + 1}.jpg`).should('exist');
});
});
});

it('Check link to frame.', () => {
cy.get('.cvat-allocation-frame-row').last().within(() => {
cy.get('.cvat-open-frame-button').first().click();
});
cy.get('.cvat-spinner').should('not.exist');
cy.url().should('contain', `/tasks/${taskID}/jobs/${groundTruthJobID}`);
cy.checkFrameNum(2);

cy.interactMenu('Open the task');
openManagementTab();
});

it('Disable single frame, enable it back.', () => {
cy.get('.cvat-allocation-frame-row').last().within(() => {
cy.get('.cvat-allocation-frame-delete').click();
});
cy.get('.cvat-spinner').should('not.exist');

cy.get('.cvat-allocation-frame-row-excluded').should('exist');
cy.contains('.cvat-allocation-summary-excluded', '1').should('exist');
cy.contains('.cvat-allocation-summary-active', '2').should('exist');

cy.get('.cvat-allocation-frame-row-excluded').within(() => {
cy.get('.cvat-allocation-frame-restore').click();
});
cy.get('.cvat-spinner').should('not.exist');
cy.get('.cvat-allocation-frame-row-excluded').should('not.exist');
cy.contains('.cvat-allocation-summary-excluded', '0').should('exist');
cy.contains('.cvat-allocation-summary-active', '3').should('exist');
});

it('Select several frames, use group operations.', () => {
function selectFrames() {
cy.get('.cvat-allocation-frame-row').each(($el, index) => {
if (index !== 0) {
cy.wrap($el).within(() => {
cy.get('.ant-table-selection-column input[type="checkbox"]').should('not.be.checked').check();
});
}
});
}

selectFrames();
cy.get('.cvat-allocation-selection-frame-delete').click();
cy.get('.cvat-spinner').should('not.exist');

cy.get('.cvat-allocation-frame-row-excluded').should('have.length', 2);
cy.contains('.cvat-allocation-summary-excluded', '2').should('exist');
cy.contains('.cvat-allocation-summary-active', '1').should('exist');

selectFrames();
cy.get('.cvat-allocation-selection-frame-restore').click();
cy.get('.cvat-spinner').should('not.exist');

cy.get('.cvat-allocation-frame-row-excluded').should('not.exist');
cy.contains('.cvat-allocation-summary-excluded', '0').should('exist');
cy.contains('.cvat-allocation-summary-active', '3').should('exist');
});
});

describe('Regression tests', () => {
const imagesCount = 20;
const imageFileName = 'ground_truth_2';
Expand All @@ -205,8 +328,12 @@ context('Ground truth jobs', () => {
cy.imageGenerator(imagesFolder, imageFileName, width, height, color, posX, posY, labelName, imagesCount);
cy.createZipArchive(directoryToArchive, archivePath);
cy.createAnnotationTask(
taskName, labelName, attrName,
textDefaultValue, archiveName, false,
taskName,
labelName,
attrName,
textDefaultValue,
archiveName,
false,
{ multiJobs: true, segmentSize: 1 },
);
cy.openTask(taskName);
Expand Down
19 changes: 16 additions & 3 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ Cypress.Commands.add(
attrName = 'Some attr name',
textDefaultValue = 'Some default value for type Text',
image = 'image.png',
multiAttrParams,
advancedConfigurationParams,
multiAttrParams = null,
advancedConfigurationParams = null,
forProject = false,
attachToProject = false,
projectName,
projectName = '',
expectedResult = 'success',
projectSubsetFieldValue = 'Test',
) => {
Expand Down Expand Up @@ -365,6 +365,19 @@ Cypress.Commands.add('headlessLogout', () => {
cy.clearAllLocalStorage();
});

Cypress.Commands.add('headlessCreateJob', (jobSpec) => {
cy.window().then(async ($win) => {
const data = {
...jobSpec,
};

const job = new $win.cvat.classes.Job(data);

const result = await job.save(data);
return cy.wrap({ jobID: result.id });
});
});

Cypress.Commands.add('openTask', (taskName, projectSubsetFieldValue) => {
cy.contains('strong', new RegExp(`^${taskName}$`))
.parents('.cvat-tasks-list-item')
Expand Down

0 comments on commit 6d38124

Please sign in to comment.