forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes MAT-427, MAT-428 flag=rce_buttons_and_icons test plan: - Navigate to a RCE instance - Click Buttons & Icons button. - In the tray, navigate to images section - Select a course image - Wait until the preview is loaded - Click crop button > Verify zoom in/out buttons work as expected, also consider zoom should not exceed thresholds (1.0 - 2.0) > Verify mouse wheel zooms in/out the image, also consider zoom should not exceed thresholds (1.0 - 2.0) Change-Id: Iba5de5eddd621d5f794e5030a7838800344deb11 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/284505 Tested-by: Service Cloud Jenkins <[email protected]> Reviewed-by: Jacob DeWar <[email protected]> QA-Review: Jacob DeWar <[email protected]> Product-Review: David Lyons <[email protected]>
- Loading branch information
Juan Chavez
committed
Feb 9, 2022
1 parent
32ca331
commit 45296ec
Showing
18 changed files
with
636 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
...re_buttons/components/CreateButtonForm/ImageCropper/__tests__/ImageCropperPreview.test.js
This file was deleted.
Oops, something went wrong.
112 changes: 112 additions & 0 deletions
112
...ns/instructure_buttons/components/CreateButtonForm/ImageCropper/__tests__/Preview.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright (C) 2022 - present Instructure, Inc. | ||
* | ||
* This file is part of Canvas. | ||
* | ||
* Canvas is free software: you can redistribute it and/or modify it under | ||
* the terms of the GNU Affero General Public License as published by the Free | ||
* Software Foundation, version 3 of the License. | ||
* | ||
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License along | ||
* with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import React from 'react' | ||
import {fireEvent, render, waitFor} from '@testing-library/react' | ||
|
||
import {Preview} from '../Preview' | ||
|
||
describe('Preview', () => { | ||
let settings, dispatch | ||
|
||
beforeEach(() => { | ||
settings = { | ||
image: 'https://www.fillmurray.com/640/480', | ||
shape: 'square', | ||
scaleRatio: 1 | ||
} | ||
dispatch = jest.fn() | ||
}) | ||
|
||
describe('renders', () => { | ||
it('the image', () => { | ||
const {container} = render(<Preview settings={settings} dispatch={dispatch} />) | ||
expect(container.querySelector('img')).toBeInTheDocument() | ||
}) | ||
|
||
it('the image with src', () => { | ||
const {container} = render(<Preview settings={settings} dispatch={dispatch} />) | ||
expect(container.querySelector('img')).toMatchInlineSnapshot(` | ||
<img | ||
alt="Image to crop" | ||
src="https://www.fillmurray.com/640/480" | ||
style="position: absolute; top: 0px; left: 0px; height: 100%; width: 100%; object-fit: contain; text-align: center; transform: scale(1);" | ||
/> | ||
`) | ||
}) | ||
|
||
it('the crop shape container', () => { | ||
const {container} = render(<Preview settings={settings} dispatch={dispatch} />) | ||
expect(container.querySelector('#cropShapeContainer')).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
it('changes the crop shape', () => { | ||
const {container, rerender} = render(<Preview settings={settings} dispatch={dispatch} />) | ||
const svgContainer = container.querySelector('#cropShapeContainer') | ||
const squareContent = svgContainer.innerHTML | ||
settings.shape = 'octagon' | ||
rerender(<Preview settings={settings} dispatch={dispatch} />) | ||
const octagonContent = svgContainer.innerHTML | ||
expect(squareContent).not.toEqual(octagonContent) | ||
}) | ||
|
||
describe('calls dispatch using wheel', () => { | ||
it('when zoom in', async () => { | ||
const {container} = render(<Preview settings={settings} dispatch={dispatch} />) | ||
const event = {deltaY: -25} | ||
fireEvent.wheel(container.firstChild, event) | ||
await waitFor(() => { | ||
expect(dispatch).toHaveBeenCalledWith({type: 'SetScaleRatio', payload: 1.125}) | ||
}) | ||
}) | ||
|
||
it('when zoom out', async () => { | ||
settings.scaleRatio = 2 | ||
const {container} = render(<Preview settings={settings} dispatch={dispatch} />) | ||
const event = {deltaY: 25} | ||
fireEvent.wheel(container.firstChild, event) | ||
await waitFor(() => { | ||
expect(dispatch).toHaveBeenCalledWith({type: 'SetScaleRatio', payload: 1.875}) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('sets scale style using wheel', () => { | ||
it('when zoom in', async () => { | ||
const {container} = render(<Preview settings={settings} dispatch={dispatch} />) | ||
const event = {deltaY: -25} | ||
fireEvent.wheel(container.firstChild, event) | ||
await waitFor(() => { | ||
const img = container.querySelector('img') | ||
expect(img.style.transform).toEqual('scale(1.125)') | ||
}) | ||
}) | ||
|
||
it('when zoom out', async () => { | ||
settings.scaleRatio = 2 | ||
const {container} = render(<Preview settings={settings} dispatch={dispatch} />) | ||
const event = {deltaY: 25} | ||
fireEvent.wheel(container.firstChild, event) | ||
await waitFor(() => { | ||
const img = container.querySelector('img') | ||
expect(img.style.transform).toEqual('scale(1.875)') | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.