Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

tests/MM-T2369 : Aspect Ratio is preserved in RHS #8165

Merged
merged 2 commits into from
Jun 1, 2021
Merged
Changes from 1 commit
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
71 changes: 71 additions & 0 deletions e2e/cypress/integration/scroll/image_aspect_ratio_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

// ***************************************************************
// - [#] indicates a test step (e.g. # Go to a page)
// - [*] indicates an assertion (e.g. * Check the title)
// - Use element ID when selecting an element. Create one if none.
// ***************************************************************

describe('scroll', () => {
saturninoabril marked this conversation as resolved.
Show resolved Hide resolved
let testTeam;

beforeEach(() => {
// # Create new team and new user and visit Town Square channel
cy.apiInitSetup().then(({team, channel}) => {
testTeam = team;

cy.visit(`/${testTeam.name}/channels/${channel.name}`);
});
});

it('MM-T2369 Aspect Ratio is preserved in RHS', () => {
const uploadedImages = [
{
alt: 'Wide image',
width: 960,
height: 246,
src:
'https://cdn.pixabay.com/photo/2017/10/10/22/24/wide-format-2839089_960_720.jpg',
},
{
alt: 'Tall image',
width: 400,
height: 950,
src:
'https://media.npr.org/programs/atc/features/2009/may/short/abetall3-0483922b5fb40887fc9fbe20a606e256cbbd10ee-s800-c85.jpg',
},
];

uploadedImages.forEach((uploadedImage) => {
// # Post the image as markdown image in the center
cy.uiPostMessageQuickly(`![${uploadedImage.alt}](${uploadedImage.src})`);

// # Get uploaded image in the center
cy.getLastPost().within(() => {
// * Verify image was uploaded and its aspect ratio is unchanged
verifyImageAspectRatioCorrectness(uploadedImage);
});

// # Open the message with image in RHS
cy.clickPostCommentIcon();

// # Go to RHS where image is now opened
cy.get('#rhsContainer').within(() => {
// * Verify image in the RHS has correct aspect ratio
verifyImageAspectRatioCorrectness(uploadedImage);
});
});
});
});

function verifyImageAspectRatioCorrectness(originalImage) {
cy.findByAltText(originalImage.alt).
should('exist').
and((img) => {
expect(img.width() / img.height()).to.be.closeTo(
originalImage.width / originalImage.height,
0.01,
);
});
}