Skip to content

Commit

Permalink
test: fix image movement tests (ImagePane)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Hartmann authored and JackUrb committed Mar 20, 2023
1 parent 89b7292 commit e7deb6a
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 34 deletions.
170 changes: 136 additions & 34 deletions cypress/integration/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const path = require('path');
const win_selector = '.layout .react-grid-item';
const container_selector = `${win_selector} .content > div`;
const img_selector = `${container_selector} img`;
const [moveX, moveY] = [12, 34]; // required for drag/drop action
const [imgWidth, imgHeight] = [255, 510]; // required for drag/drop action
const basepos = 10; // required for drag/drop action

describe('Image Pane', () => {
it('image_basic', () => {
Expand All @@ -16,77 +19,176 @@ describe('Image Pane', () => {
.should('have.length', 1);
});

it('Image Movement (Alt + Wheel or Drag)', () => {
// check default position
it('Image Move (Drag and Drop)', () => {
// check new position
cy.get(container_selector)
.first()
.should('have.css', 'top', '0px')
.should('have.css', 'left', '0px');

// drag image
cy.get(img_selector)
.drag(img_selector, {
source: { x: basepos, y: basepos },
target: { x: basepos + moveX, y: basepos + moveY },
force: true,
})
.wait(100);

// check new position
cy.get(container_selector)
.should('have.css', 'top', `${moveY}px`)
.should('have.css', 'left', `${moveX}px`);
cy.get(img_selector)
.should('have.attr', 'width', `${imgWidth}px`)
.should('have.attr', 'height', `${imgHeight}px`);

// drag again
cy.get(img_selector)
.drag(img_selector, {
source: { x: basepos, y: basepos },
target: { x: basepos + moveX, y: basepos + moveY },
force: true,
})
.wait(100);

// check new position
cy.get(container_selector)
.should('have.css', 'top', `${2 * moveY}px`)
.should('have.css', 'left', `${2 * moveX}px`);
cy.get(img_selector)
.should('have.attr', 'width', `${imgWidth}px`)
.should('have.attr', 'height', `${imgHeight}px`);
});

it('Image Reset (Double-Click)', () => {
// reset image
cy.get(img_selector).dblclick();

// check new position & image size
cy.get(container_selector)
.should('have.css', 'top', '0px')
.should('have.css', 'left', '0px');
cy.get(img_selector)
.should('have.attr', 'width', `${imgWidth}px`)
.should('have.attr', 'height', `${imgHeight}px`);
});

it('Image Zoom From Image Corner (Ctrl + Wheel)', () => {
// scroll a bit
cy.get(img_selector)
.first()
.trigger('wheel', {
altKey: true,
deltaY: 20,
deltaX: 30,
ctrlKey: true,
deltaY: 200,
bubbles: true,
});
clientX: 0,
clientY: 0,
})
.trigger('wheel', {
ctrlKey: true,
deltaY: 200,
bubbles: true,
clientX: 0,
clientY: 0,
})
.trigger('wheel', {
ctrlKey: true,
deltaY: 200,
bubbles: true,
clientX: 0,
clientY: 0,
})
.trigger('wheel', {
ctrlKey: true,
deltaY: 200,
bubbles: true,
clientX: 0,
clientY: 0,
})
.trigger('wheel', {
ctrlKey: true,
deltaY: 200,
bubbles: true,
clientX: 0,
clientY: 0,
})
.should('have.attr', 'width', '156px')
.should('have.attr', 'height', '312px');

// check new position
cy.get(container_selector)
.first()
.should('have.css', 'top', '-50px')
.should('have.css', 'left', '-50px');
.should('have.css', 'top', '-32.658px')
.should('have.css', 'left', '-3.93469px');
});

// check drag and drop
it('Image Zoom From Image Center (Ctrl + Wheel)', () => {
// reset image
cy.get(img_selector).dblclick();

// scroll a bit
cy.get(img_selector)
.first()
.trigger('mousemove', {
button: 0,
clientX: 120,
clientY: 300,
})
.trigger('dragover');
.trigger('wheel', { ctrlKey: true, deltaY: 200, bubbles: true })
.trigger('wheel', { ctrlKey: true, deltaY: 200, bubbles: true })
.trigger('wheel', { ctrlKey: true, deltaY: 200, bubbles: true })
.trigger('wheel', { ctrlKey: true, deltaY: 200, bubbles: true })
.trigger('wheel', { ctrlKey: true, deltaY: 200, bubbles: true })
.should('have.attr', 'width', '156px')
.should('have.attr', 'height', '312px');

// check new position
cy.get(container_selector)
.first()
.should('have.css', 'top', '256px')
.should('have.css', 'left', '38px');
.should('have.css', 'top', '105.77px')
.should('have.css', 'left', '49.9706px');
});

it('Image Zoom (Ctrl + Wheel)', () => {
it('Image Move & Zoom', () => {
// reset image
cy.get(img_selector).first().dblclick();

// check default position
cy.get(container_selector)
.first()
.should('have.css', 'top', '0px')
.should('have.css', 'left', '0px');

// scroll a bit
cy.get(img_selector)
.first()
.trigger('wheel', { ctrlKey: true, deltaY: 200, bubbles: true })
.trigger('wheel', { ctrlKey: true, deltaY: 200, bubbles: true })
.trigger('wheel', { ctrlKey: true, deltaY: 200, bubbles: true })
.trigger('wheel', { ctrlKey: true, deltaY: 200, bubbles: true })
.trigger('wheel', { ctrlKey: true, deltaY: 200, bubbles: true })
.should('have.attr', 'width', '157px')
.should('have.attr', 'height', '314px');
.trigger('wheel', { ctrlKey: true, deltaY: 200, bubbles: true });

// check new position
cy.get(container_selector)
.first()
.should('have.css', 'top', '276.786px')
.should('have.css', 'left', '81.5211px');
});
.should('have.css', 'top', '105.77px')
.should('have.css', 'left', '49.9706px');
cy.get(img_selector)
.should('have.attr', 'width', '156px')
.should('have.attr', 'height', '312px');

it('Image Reset (Double-Click)', () => {
// now drag as well
cy.get(img_selector)
.first()
.dblclick()
.should('have.attr', 'width', '257px')
.should('have.attr', 'height', '514px');
.drag(img_selector, {
source: { x: basepos, y: basepos },
target: { x: basepos + moveX, y: basepos + moveY },
force: true,
})
.wait(100);

// check new position
cy.get(container_selector)
.first()
.should('have.css', 'top', '0px')
.should('have.css', 'left', '0px');
.should('have.css', 'top', `139.77px`)
.should('have.css', 'left', '61.9706px');
cy.get(img_selector)
.should('have.attr', 'width', '156px')
.should('have.attr', 'height', '312px');
});

it('image_basic download', () => {
Expand Down Expand Up @@ -149,8 +251,8 @@ describe('Image Pane', () => {
cy.run('image_grid', { asyncrun: true });
cy.get(img_selector)
.should('have.length', 1)
.should('have.attr', 'width', '545px')
.should('have.attr', 'height', '205px');
.should('have.attr', 'width', '543px')
.should('have.attr', 'height', '204px');
});

it('image_svg', () => {
Expand Down
2 changes: 2 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
//
//

import '@4tw/cypress-drag-drop';

Cypress.Commands.add('run', (name, opts) => {
var saveto = (opts && "env" in opts) ? opts["env"] : name + "_" + Cypress._.random(0, 1e6);
var argscli = (opts && "args" in opts) ? (' -arg '+opts["args"].join(' ')) : '';
Expand Down

0 comments on commit e7deb6a

Please sign in to comment.