Skip to content

Commit cdf23b5

Browse files
Zckr07Luis Alberto Martinez
andauthored
fix: Fix RotateTool on mobile devices (#1385)
* Fix - RotateTool for mobile devices * Refactor fix RotateTool * Feature - testUnit for RotateTool on mobile devices * Refactor validation on RotateTool * Change validation structure Co-authored-by: Luis Alberto Martinez <zckr@MacBook-Pro-de-Luis.local>
1 parent c9837ca commit cdf23b5

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/tools/RotateTool.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ export default class RotateTool extends BaseTool {
5656
function defaultStrategy(evt) {
5757
const { roundAngles, rotateScale } = this.configuration;
5858
const { element, viewport, startPoints, currentPoints } = evt.detail;
59-
const initialRotation = viewport.initialRotation;
59+
60+
const initialRotation = viewport.initialRotation
61+
? viewport.initialRotation
62+
: viewport.rotation;
6063

6164
// Calculate the center of the image
6265
const rect = element.getBoundingClientRect(element);

src/tools/RotateTool.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ const mockEvt = {
1313
},
1414
};
1515

16+
const forMobileMockEvt = {
17+
detail: {
18+
viewport: {
19+
rotation: 50,
20+
initialRotation: undefined,
21+
},
22+
},
23+
};
24+
1625
describe('RotateTool.js', () => {
1726
describe('default values', () => {
1827
it('has a default name of "Rotate"', () => {
@@ -48,5 +57,15 @@ describe('RotateTool.js', () => {
4857
instantiatedTool.dragCallback(mockEvt);
4958
expect(external.cornerstone.setViewport).toHaveBeenCalled();
5059
});
60+
61+
it('can be created on mobile device', () => {
62+
const instantiatedTool = new RotateTool();
63+
64+
instantiatedTool.applyActiveStrategy = jest.fn();
65+
external.cornerstone.setViewport = jest.fn();
66+
67+
instantiatedTool.dragCallback(forMobileMockEvt);
68+
expect(external.cornerstone.setViewport).toHaveBeenCalled();
69+
});
5170
});
5271
});

0 commit comments

Comments
 (0)