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

Updated command to create headless objects in Cypress #9024

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 17 additions & 9 deletions tests/cypress/e2e/actions_objects/regression_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ context('Regression tests', () => {
};

const rectanglePayload = {
shapeType: 'rectangle',
type: 'rectangle',
occluded: false,
labelName: taskPayload.labels[0].name,
};
Expand All @@ -42,14 +42,22 @@ context('Regression tests', () => {
taskID = response.taskID;
[jobID] = response.jobIDs;

cy.headlessCreateObjects([
{
...rectanglePayload, frame: 99, points: [250, 64, 491, 228], objectType: 'shape',
},
{
...rectanglePayload, frame: 0, points: [10, 10, 30, 30], objectType: 'track',
},
], jobID);
cy.headlessCreateObjects([{
...rectanglePayload,
frame: 99,
points: [250, 64, 491, 228],
objectType: 'shape',
}, {
labelName: rectanglePayload.labelName,
objectType: 'track',
frame: 0,
shapes: [{
type: rectanglePayload.type,
frame: 0,
occluded: rectanglePayload.occluded,
points: [10, 10, 30, 30],
}],
}], jobID);
});
});

Expand Down
4 changes: 2 additions & 2 deletions tests/cypress/e2e/features/ground_truth_jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,9 @@ context('Ground truth jobs', () => {
return cy.headlessCreateObjects(groundTruthFrames.map((frame, index) => {
const gtRect = groundTruthRectangles[index];
return {
labelName,
objectType: 'shape',
shapeType: 'rectangle',
labelName,
type: 'rectangle',
occluded: false,
frame,
points: [gtRect.firstX, gtRect.firstY, gtRect.secondX, gtRect.secondY],
Expand Down
8 changes: 5 additions & 3 deletions tests/cypress/e2e/features/requests_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ context('Requests page', () => {
manifest: 'manifest.jsonl',
endpointUrl: Cypress.config('minioUrl'),
};

const rectanglePayload = {
frame: 0,
objectType: 'shape',
shapeType: 'rectangle',
labelName: mainLabelName,
frame: 0,
type: 'rectangle',
points: [250, 64, 491, 228],
occluded: false,
labelName: mainLabelName,
};

const attrName = 'requests_attr';
const imagesCount = 3;
const imageFileName = `image_${mainLabelName}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ context('Dump annotation if cuboid created.', () => {
[jobID] = response.jobIDs;

const cuboidPayload = {
frame: 0,
objectType: 'shape',
shapeType: 'cuboid',
labelName,
frame: 0,
type: 'cuboid',
points: [
38, 58, 38, 174, 173,
58, 173, 174, 186, 46,
Expand Down
65 changes: 52 additions & 13 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,23 +287,62 @@ Cypress.Commands.add('headlessLogin', ({
});

Cypress.Commands.add('headlessCreateObjects', (objects, jobID) => {
const convertShape = ($win, job) => (shape) => ({
frame: shape.frame,
type: shape.type,
points: $win.Array.from(shape.points),
label_id: job.labels.find((label) => label.name === shape.labelName).id,
occluded: shape.occluded || false,
outside: shape.outside || false,
source: shape.source || 'manual',
attributes: $win.Array.from(shape.attributes || []),
elements: $win.Array.from(shape.elements ? shape.elements.map(convertShape) : []),
rotation: shape.rotation || 0,
group: shape.group || 0,
z_order: shape.zOrder || 0,
});

const convertTag = ($win, job) => (tag) => ({
frame: tag.frame,
label_id: job.labels.find((label) => label.name === tag.labelName).id,
source: tag.source || 'manual',
attributes: $win.Array.from(tag.attributes || []),
group: tag.group || 0,
});

const convertTrack = ($win, job) => (track) => ({
frame: track.frame,
label_id: job.labels.find((label) => label.name === track.labelName).id,
group: track.group || 0,
source: track.source || 'manual',
attributes: $win.Array.from(track.attributes || []),
elements: $win.Array.from(track.elements ? track.elements.map(convertTrack) : []),
shapes: track.shapes.map((shape) => ({
attributes: $win.Array.from(shape.attributes || []),
points: $win.Array.from(shape.points),
frame: shape.frame,
occluded: shape.occluded || false,
outside: shape.outside || false,
rotation: shape.rotation || 0,
type: shape.type,
z_order: shape.zOrder || 0,
})),
});

cy.window().then(async ($win) => {
const job = (await $win.cvat.jobs.get({ jobID }))[0];
await job.annotations.clear({ reload: true });

const objectStates = objects
.map((object) => new $win.cvat.classes
.ObjectState({
frame: object.frame,
objectType: object.objectType,
shapeType: object.shapeType,
points: $win.Array.from(object.points),
occluded: object.occluded,
label: job.labels.find((label) => label.name === object.labelName),
zOrder: 0,
}));

await job.annotations.put($win.Array.from(objectStates));
const shapes = objects.filter((object) => object.objectType === 'shape').map(convertShape($win, job));
const tracks = objects.filter((object) => object.objectType === 'track').map(convertTrack($win, job));
const tags = objects.filter((object) => object.objectType === 'tag').map(convertTag($win, job));

await job.annotations.import({
shapes: $win.Array.from(shapes),
tracks: $win.Array.from(tracks),
tags: $win.Array.from(tags),
});

await job.annotations.save();
return cy.wrap();
});
Expand Down
Loading