-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathconsensus.js
225 lines (208 loc) · 10.1 KB
/
consensus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// Copyright (C) CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT
/// <reference types="cypress" />
import { translatePoints } from '../../support/utils';
context('Basic manipulations with consensus job replicas', () => {
const labelName = 'Consensus';
const replicas = 4;
const taskName = 'Test consensus';
const serverFiles = ['archive.zip'];
before(() => {
cy.visit('auth/login');
cy.login();
cy.get('.cvat-create-task-dropdown').click();
cy.get('.cvat-create-task-button').should('be.visible').click();
});
describe('Consensus job creation', () => {
const maxReplicas = 10;
it('Check allowed number of replicas', () => {
// Fill the fields to create the task
cy.get('#name').type(taskName);
cy.addNewLabel({ name: labelName });
cy.selectFilesFromShare(serverFiles);
cy.contains('[role="tab"]', 'My computer').click();
cy.contains('Advanced configuration').click();
// 'Consensus Replicas' field cannot equal to 1
cy.get('#consensusReplicas').type(`{backspace}${1}`);
cy.get('.ant-form-item-explain-error')
.should('be.visible')
.invoke('text').should('eq', 'Value can not be equal to 1');
cy.contains('button', 'Submit & Continue').click();
cy.get('.ant-notification-notice-error').should('exist').and('be.visible');
cy.closeNotification('.ant-notification-notice-error');
// 'Consensus Replicas' field cannot be > 10
cy.get('#consensusReplicas').type(`{backspace}${maxReplicas + 1}`);
cy.get('.ant-form-item-explain-error').should('be.visible')
.invoke('text').should('eq', `Value must be less than ${maxReplicas}`);
cy.contains('button', 'Submit & Continue').click();
cy.get('.ant-notification-notice-error').should('exist').and('be.visible');
cy.closeNotification('.ant-notification-notice-error');
cy.get('#consensusReplicas').clear();
});
it('Check new consensus task has correct tags and drop-down with replicas', () => {
// Create task with consensus
cy.get('#consensusReplicas').type(replicas);
cy.contains('button', 'Submit & Open').click();
cy.get('.cvat-task-details-wrapper').should('be.visible');
cy.get('.ant-notification-notice-error').should('not.exist');
// Check tags
cy.get('.cvat-tag-consensus').then((tags) => {
expect(tags.length).to.equal(2);
cy.wrap(tags).each(($el) => {
cy.wrap($el).should('have.text', 'Consensus');
});
});
cy.get('.cvat-consensus-job-collapse').should('be.visible')
.within(($el) => {
expect($el.text()).to.equal(`${replicas} Replicas`);
cy.wrap($el).click();
});
});
});
describe('Cosensus jobs merging', () => {
const shape = {
objectType: 'shape',
labelName,
frame: 0,
type: 'rectangle',
points: [250, 64, 491, 228],
occluded: false,
};
const jobIDs = [];
const attrName = labelName;
const advancedConfigurationParams = { consensusReplicas: replicas };
const defaultArgs1 = ['Some default value for type Text', '', null];
const deafultArgs2 = [false, false, '', 'success', 'Test', null];
before(() => {
cy.goToTaskList();
cy.createAnnotationTask(
taskName, labelName, attrName,
...defaultArgs1,
advancedConfigurationParams,
...deafultArgs2,
serverFiles,
); // TODO: rewrite to headless call once the task consensus endpoint is finished
cy.openTask(taskName);
cy.get('.cvat-consensus-job-collapse').click();
});
it("Check new merge buttons exist and are visible. Trying to merge 'new' jobs should trigger errors", () => {
// Merge all consensus jobs in task
cy.mergeConsensusTask(400);
cy.get('.cvat-notification-notice-consensus-merge-task-failed')
.should('be.visible')
.invoke('text')
.should('include', 'Could not merge the task');
cy.closeNotification('.cvat-notification-notice-consensus-merge-task-failed');
// Merge one consensus job
cy.mergeConsensusJob(400);
cy.get('.cvat-notification-notice-consensus-merge-task-failed')
.should('be.visible')
.invoke('text').should('include', 'Could not merge the job');
cy.closeNotification('.cvat-notification-notice-consensus-merge-task-failed');
// Check asc order of jobs and save job ids
function parseJobId(jobItem) {
const jobItemText = jobItem.innerText;
const [start, stop] = [0, jobItemText.indexOf('\n')];
return +(jobItemText.substring(start, stop).split('#')[1]);
}
cy.get('.cvat-job-item').then((jobItems) => {
const sourceJobId = parseJobId(jobItems[0]);
jobIDs.push(sourceJobId);
for (let i = 1; i <= replicas; i++) {
const jobId = parseJobId(jobItems[i]);
jobIDs.push(jobId);
expect(jobId).equals(sourceJobId + i);
}
});
});
it('Check consensus management page', () => {
const defaultQuorum = 50;
const defaultIoU = 40;
cy.contains('button', 'Actions').click();
cy.contains('Consensus management').should('be.visible').click();
cy.get('.cvat-consensus-management-inner').should('be.visible');
// Save settings, confirm request is sent
let requestCount = 0;
cy.intercept('PATCH', 'api/consensus/settings/**', () => {
requestCount++;
}).as('settingsMeta');
cy.contains('button', 'Save').click();
cy.wait('@settingsMeta');
cy.get('.ant-notification-notice-message')
.should('be.visible')
.invoke('text')
.should('eq', 'Settings have been updated');
cy.closeNotification('.ant-notification-notice-closable');
// Forms and invalid saving
cy.get('#quorum').then(([$el]) => {
cy.wrap($el).invoke('val').should('eq', `${defaultQuorum}`);
cy.wrap($el).clear();
});
cy.get('.ant-form-item-explain-error').should('be.visible');
cy.contains('button', 'Save').click();
cy.get('#iouThreshold').then(([$el]) => {
cy.wrap($el).invoke('val').should('eq', `${defaultIoU}`);
cy.wrap($el).clear();
});
cy.get('.ant-form-item-explain-error').should('be.visible');
cy.contains('button', 'Save').click();
cy.then(() => {
expect(requestCount).to.equal(1);
});
cy.get('.ant-notification-notice').should('not.exist');
// Go back to task page
cy.get('.ant-btn-default').should('be.visible').click();
});
it('Create annotations and check that job replicas merge correctly', () => {
// Create annotations for job replicas
const delta = 50;
const [consensusJobID, ...replicaJobIDs] = jobIDs;
for (let i = 0, s = shape; i < replicas; i++) {
cy.headlessCreateObjects([s], replicaJobIDs[i]); // only 'in progress' jobs can be merged
cy.headlessUpdateJob(replicaJobIDs[i], { state: 'in progress' });
const points = translatePoints(s.points, delta, 'x');
s = { ...s, points };
}
// Merging of consensus job should go without errors in network and UI
cy.mergeConsensusJob();
cy.get('.cvat-notification-notice-consensus-merge-job-failed').should('not.exist');
cy.get('.ant-notification-notice-message')
.should('be.visible')
.invoke('text')
.should('eq', `Consensus job #${consensusJobID} has been merged`);
cy.closeNotification('.ant-notification-notice-closable');
// Shapes in consensus job and a job replica in the middle should be equal
const middle = Math.floor(jobIDs.length / 2);
const consensusRect = {};
cy.openJob(0, false).then(() => {
cy.get('.cvat_canvas_shape').trigger('mousemove');
cy.get('.cvat_canvas_shape').then(($el) => {
consensusRect.x = $el.attr('x');
consensusRect.y = $el.attr('y');
consensusRect.width = $el.attr('width');
consensusRect.height = $el.attr('height');
});
cy.get('#cvat_canvas_text_content').should('be.visible')
.invoke('text')
.should('include', `${labelName}`)
.and('include', 'consensus');
});
cy.go('back'); // go to previous page
// After returning to task page, consensus job should be 'completed'
cy.get('.cvat-job-item').first()
.find('.cvat-job-item-state').first()
.invoke('text')
.should('eq', 'completed');
cy.contains('.cvat-job-item', `Job #${jobIDs[middle]}`).scrollIntoView();
cy.openJob(middle, false).then(() => {
cy.get('.cvat_canvas_shape').then(($el) => {
expect($el.attr('x')).to.equal(consensusRect.x);
expect($el.attr('y')).to.equal(consensusRect.y);
expect($el.attr('width')).to.equal(consensusRect.width);
expect($el.attr('height')).to.equal(consensusRect.height);
});
});
});
});
});