Skip to content

Commit d7d608c

Browse files
committed
Update spec for internal move method to test for transforms when available
1 parent 3003925 commit d7d608c

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

test/spec/easyzoom.js

+21-9
Original file line numberDiff line numberDiff line change
@@ -226,25 +226,37 @@
226226

227227
var spy = sinon.spy(api, "hide");
228228

229+
var getPosition = function () {
230+
if ('transform' in document.body.style) {
231+
var transform = api.$zoom.attr("style");
232+
var matches = transform.match(/translate\((-?\d+px), (-?\d+px)\)/);
233+
234+
return {
235+
left: matches[1],
236+
top: matches[2]
237+
}
238+
} else {
239+
return api.$zoom.css(["left", "top"])
240+
}
241+
}
242+
229243
// Must open the flyout with a zoom image first
230244
api.opts.onShow = function () {
231-
var left, top;
245+
var position;
232246

233247
api._move(mock_1);
234248

235-
left = parseInt(api.$zoom.css("left"), 10);
236-
top = parseInt(api.$zoom.css("top"), 10);
249+
position = getPosition()
237250

238-
assert.equal(left, -20, "2x scale zoom image moved 20px left given 10px offset");
239-
assert.equal(top, -20, "2x scale zoom image moved 20px top given 10px offset");
251+
assert.equal(position.left, '-20px', "2x scale zoom image moved 20px left given 10px offset");
252+
assert.equal(position.top, '-20px', "2x scale zoom image moved 20px top given 10px offset");
240253

241254
api._move(mock_2);
242255

243-
left = parseInt(api.$zoom.css("left"), 10);
244-
top = parseInt(api.$zoom.css("top"), 10);
256+
position = getPosition()
245257

246-
assert.equal(left, -200, "2x scale zoom image moved 200px left given 100px offset");
247-
assert.equal(top, -200, "2x scale zoom image moved 200px top given 100px offset");
258+
assert.equal(position.left, '-200px', "2x scale zoom image moved 200px left given 100px offset");
259+
assert.equal(position.top, '-200px', "2x scale zoom image moved 200px top given 100px offset");
248260

249261
api._move(mock_3);
250262

0 commit comments

Comments
 (0)