wisemapping-frontend/packages/mindplot/test/unit/EventsTestSuite.js
Matias Arriola cb2ca74a20 Merged in web2d-coreJS-solutions (pull request #5)
Core-js, web2d and mindplot working baseline

* fix .eslintignore
remove Raphael dependency

* Fix to avoid crashes in  _plotPrediction whitout Raphael

* Fix minplot basic code inspections

* Fix last inspections errors

* Inital refactor copying files

* Clean up.

* Fix web2d cyclic dependencies
remove only-warn eslint plugin
set import/no-extraneous-dependencies to warn (incorrectly complaining about root package)

* Fix web2d Point references (no need to assign it to core)
Fix web2d imports in mindplot and update Point refs

* Merge 'feature/mindplot_tests' into web2d-coreJS-solutions

* mindplot fixes and add viewmode.html playground

setup playground config to run the map-render examples
fix mindplot components export
mootools Static was not working so refactored it
fix some references to _peer
fix messages __bundle undefined
add web2d missing export: Image
downgrade cypress to avoid SIGSEGV error


Approved-by: Paulo Veiga
2021-12-02 00:41:56 +00:00

42 lines
1.4 KiB
JavaScript

const TestClass = new Class({
Extends: mindplot.Events,
getEvents() {
return this.$events;
},
removeEvents() {
this.$events = {};
},
});
// Test class and variables
const expectedChangeFn1 = function () { return 'change1'; };
const expectedChangeFn2 = function () { return 'change2'; };
const expectedLoadFn = function () { return 'loaded'; };
const myTestClass = new TestClass();
describe('Events class suite', () => {
afterEach(() => {
myTestClass.removeEvents();
});
it('addEventTest', () => {
expect(myTestClass.getEvents()).toEqual({});
myTestClass.addEvent('change', expectedChangeFn1);
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn1] });
myTestClass.addEvent('change', expectedChangeFn2);
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn1, expectedChangeFn2] });
myTestClass.addEvent('load', expectedLoadFn);
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn1, expectedChangeFn2], load: [expectedLoadFn] });
});
it('removeEventTest', () => {
expect(myTestClass.getEvents()).toEqual({});
myTestClass.addEvent('change', expectedChangeFn1);
myTestClass.addEvent('change', expectedChangeFn2);
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn1, expectedChangeFn2] });
myTestClass.removeEvent('change', expectedChangeFn1);
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn2] });
});
});