Skip to content

Commit

Permalink
Merge pull request #1257 from boluwatifee/patch-1
Browse files Browse the repository at this point in the history
Changed Regular functions to arrow function
  • Loading branch information
TildaDares committed Nov 2, 2022
2 parents 1b75f44 + 72a885b commit c0ef610
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions test/src/edit/DistortableImageEditSpec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe('L.DistortableImage.Edit', function() {
describe('L.DistortableImage.Edit', () => {
let map; let ov;

beforeEach(function(done) {
beforeEach((done) => {
map = L.map(L.DomUtil.create('div', '', document.body)).setView([41.7896, -87.5996], 15);

ov = L.distortableImageOverlay('/examples/example.jpg', {
Expand All @@ -14,18 +14,18 @@ describe('L.DistortableImage.Edit', function() {
}).addTo(map);

/* Forces the image to load before any tests are run. */
L.DomEvent.on(ov.getElement(), 'load', function() { done(); });
L.DomEvent.on(ov.getElement(), 'load', () => { done(); });

afterEach(function() {
afterEach(() => {
L.DomUtil.remove(ov);
});
});

it('Should be initialized along with each instance of L.DistortableImageOverlay.', function() {
it('Should be initialized along with each instance of L.DistortableImageOverlay.', () => {
expect(ov.editing).to.be.an.instanceOf(L.DistortableImage.Edit);
});

it('Should keep handles on the map in sync with the corners of the image.', function() {
it('Should keep handles on the map in sync with the corners of the image.', () => {
const corners = ov.getCorners();
const edit = ov.editing;
edit.enable();
Expand All @@ -35,20 +35,20 @@ describe('L.DistortableImage.Edit', function() {
ov.setCorner(0, L.latLng(41.7934, -87.6252));

/* Warp handles are currently on the map; they should have been updated. */
edit._distortHandles.eachLayer(function(handle) {
edit._distortHandles.eachLayer((handle) => {
expect(handle.getLatLng()).to.be.closeToLatLng(corners[handle._corner]);
});

edit._freeRotateMode();

/* After we toggle modes, the freeRotateHandles are on the map and should be synced. */
edit._freeRotateHandles.eachLayer(function(handle) {
edit._freeRotateHandles.eachLayer((handle) => {
expect(handle.getLatLng()).to.be.closeToLatLng(corners[handle._corner]);
});
});

describe('#replaceTool', function() {
it('It should replace an existing action', function() {
describe('#replaceTool', () => {
it('It should replace an existing action', () => {
const old = ov.editing.editActions[0];
const next = ov.editing.editActions[1];
const edit = ov.editing;
Expand All @@ -62,7 +62,7 @@ describe('L.DistortableImage.Edit', function() {
expect(edit.editActions[0]).to.equal(next);
});

it('It should do nothing if the first parameter does not exist', function() {
it('It should do nothing if the first parameter does not exist', () => {
const old = ov.editing.editActions[0];
const next = ov.editing.editActions[1];
const edit = ov.editing;
Expand All @@ -75,7 +75,7 @@ describe('L.DistortableImage.Edit', function() {
expect(edit.hasTool(next)).to.be.true;
});

it('It should do nothing if the second parameter already exists', function() {
it('It should do nothing if the second parameter already exists', () => {
const old = ov.editing.editActions[0];
const next = ov.editing.editActions[1];
const edit = ov.editing;
Expand All @@ -86,15 +86,15 @@ describe('L.DistortableImage.Edit', function() {
expect(edit.hasTool(next)).to.be.true;
});

it('Should add the new action to the image\'s `modes` if it is also a mode', function(done) {
it('Should add the new action to the image\'s `modes` if it is also a mode', (done) => {
const old = L.ScaleAction;
const next = L.DragAction;

const ov3 = L.distortableImageOverlay('/examples/example.jpg', {
actions: [old],
}).addTo(map);

L.DomEvent.on(ov3.getElement(), 'load', function() {
L.DomEvent.on(ov3.getElement(), 'load', () => {
const edit = ov3.editing;
expect(edit.hasMode('scale')).to.be.true;
expect(edit.hasMode('drag')).to.be.false;
Expand All @@ -109,24 +109,24 @@ describe('L.DistortableImage.Edit', function() {
});
});

describe('#_deselect', function() {
it('It should hide an unlocked image\'s handles by updating their opacity', function() {
describe('#_deselect', () => {
it('It should hide an unlocked image\'s handles by updating their opacity', () => {
const edit = ov.editing;

edit.enable();
// then trigger _deselect
map.getContainer().click();

const handleState = [];
edit._handles.distort.eachLayer(function(handle) {
edit._handles.distort.eachLayer((handle) => {
const icon = handle.getElement();
handleState.push(L.DomUtil.getStyle(icon, 'opacity'));
});

expect(handleState).to.deep.equal(['0', '0', '0', '0']);
});

it('But it should not hide a locked image\'s handles', function() {
it('But it should not hide a locked image\'s handles', () => {
const edit = ov.editing;

edit.enable();
Expand All @@ -136,15 +136,15 @@ describe('L.DistortableImage.Edit', function() {
map.getContainer().click();

const lockHandleState = [];
edit._handles.lock.eachLayer(function(handle) {
edit._handles.lock.eachLayer((handle) => {
const icon = handle.getElement();
lockHandleState.push(L.DomUtil.getStyle(icon, 'opacity'));
});

expect(lockHandleState).to.deep.equal(['1', '1', '1', '1']);
});

it('Should remove an image\'s individual toolbar instance regardless of lock handles', function() {
it('Should remove an image\'s individual toolbar instance regardless of lock handles', () => {
const edit = ov.editing;

edit.enable();
Expand All @@ -159,14 +159,14 @@ describe('L.DistortableImage.Edit', function() {
map.getContainer().click();

// we deselect after 3ms to confirm the click wasn't a dblclick
setTimeout(function() {
setTimeout(() => {
expect(edit.toolbar).to.be.false;
}, 3000);
});
});

describe('#nextMode', function() {
it('Should update image\'s mode to the next in its modes array', function() {
describe('#nextMode', () => {
it('Should update image\'s mode to the next in its modes array', () => {
const edit = ov.editing;
const modes = Object.keys(edit.getModes());

Expand All @@ -177,17 +177,17 @@ describe('L.DistortableImage.Edit', function() {
expect(newIdx).to.equal((idx + 1) % modes.length);
});

it('Will also select the image when triggerd by dblclick', function() {
it('Will also select the image when triggerd by dblclick', () => {
ov.deselect();
expect(ov.isSelected()).to.be.false;

chai.simulateEvent(ov.getElement(), 'dblclick');
setTimeout(function() {
setTimeout(() => {
expect(ov.isSelected()).to.be.true;
}, 3000);
});

it('It prevents dblclick events from propagating to the map', function() {
it('It prevents dblclick events from propagating to the map', () => {
const overlaySpy = sinon.spy();
const mapSpy = sinon.spy();

Expand All @@ -196,7 +196,7 @@ describe('L.DistortableImage.Edit', function() {

chai.simulateEvent(ov.getElement(), 'dblclick');

setTimeout(function() {
setTimeout(() => {
expect(ov.editing.nextMode).to.have.been.called;
expect(L.DomEvent.stop).to.have.been.called;

Expand All @@ -205,19 +205,19 @@ describe('L.DistortableImage.Edit', function() {
}, 3000);
});

it('Should call #setMode', function() {
it('Should call #setMode', () => {
const edit = ov.editing;
const spy = sinon.spy(edit, 'setMode');
chai.simulateEvent(ov.getElement(), 'dblclick');
expect(spy.called).to.be.ok;
});

it('Will still update the mode of an initialized image with suppressToolbar: true', function(done) {
it('Will still update the mode of an initialized image with suppressToolbar: true', (done) => {
const ov2 = L.distortableImageOverlay('/examples/example.jpg', {
suppressToolbar: true,
}).addTo(map);

L.DomEvent.on(ov2.getElement(), 'load', function() {
L.DomEvent.on(ov2.getElement(), 'load', () => {
const edit = ov2.editing;
const modes = Object.keys(edit.getModes());
const mode = edit.getMode();
Expand All @@ -233,32 +233,32 @@ describe('L.DistortableImage.Edit', function() {
});
});

describe('#setMode', function() {
it('Will return undefined if the passed value is not in the image\'s modes array', function() {
describe('#setMode', () => {
it('Will return undefined if the passed value is not in the image\'s modes array', () => {
const edit = ov.editing;
expect(edit.setMode('lock')).to.be.ok;
expect(edit.setMode('blah')).to.be.undefined;
});

it('Will return undefined if image editing is not enabled', function() {
it('Will return undefined if image editing is not enabled', () => {
const edit = ov.editing;
edit.disable();
expect(edit.setMode('lock')).to.be.undefined;
});

it('Will return undefined if the passed mode is already the image\'s mode', function() {
it('Will return undefined if the passed mode is already the image\'s mode', () => {
const edit = ov.editing;
edit.setMode('distort');
expect(edit.setMode('lock')).to.be.ok;
expect(edit.setMode('lock')).to.be.undefined;
});

it('Will still update the mode of an initialized image with suppressToolbar: true', function(done) {
it('Will still update the mode of an initialized image with suppressToolbar: true', (done) => {
const ov2 = L.distortableImageOverlay('/examples/example.jpg', {
suppressToolbar: true,
}).addTo(map);

L.DomEvent.on(ov2.getElement(), 'load', function() {
L.DomEvent.on(ov2.getElement(), 'load', () => {
const edit = ov2.editing;
expect(edit.toolbar).to.be.undefined;
expect(edit.getMode()).to.not.eql('lock');
Expand Down

0 comments on commit c0ef610

Please sign in to comment.