c619223367
1. Split the resizing functionality of into a separate mixin to be shared across components 2. Add basic integration tests to prove that everything is getting called through out the lifetime of the app. I decided against unit testing as there isn't really any isolated logic to be tested, more checking that things are being called in the correct order etc i.e. the integration is correct. Adds assertion to with-resizing so its obvious to override `resize`
27 lines
1,003 B
JavaScript
27 lines
1,003 B
JavaScript
import { module } from 'qunit';
|
|
import test from 'ember-sinon-qunit/test-support/test';
|
|
import { setupTest } from 'ember-qunit';
|
|
import EmberObject from '@ember/object';
|
|
import Mixin from 'consul-ui/mixins/with-resizing';
|
|
module('Integration | Mixin | with-resizing', function(hooks) {
|
|
setupTest(hooks);
|
|
test('window.addEventListener, resize and window.removeEventListener are called once each through the entire lifecycle', function(assert) {
|
|
const win = {
|
|
innerWidth: 0,
|
|
innerHeight: 0,
|
|
addEventListener: this.stub(),
|
|
removeEventListener: this.stub(),
|
|
};
|
|
const subject = EmberObject.extend(Mixin, {
|
|
win: win,
|
|
}).create();
|
|
const resize = this.stub(subject, 'resize');
|
|
subject.didInsertElement();
|
|
subject.willDestroyElement();
|
|
assert.ok(win.addEventListener.calledOnce);
|
|
assert.ok(resize.calledOnce);
|
|
assert.ok(resize.calledWith({ detail: { width: 0, height: 0 } }));
|
|
assert.ok(win.removeEventListener.calledOnce);
|
|
});
|
|
});
|