c4effc9734
`window` and `document` are easily injected anyhow, but this primarily this keeps everything dom related in the same place. Included here are changes to make all ember related objects use the dom service `document` and `viewport` instead of just `document` and `window`. Quote from a previous PR (#4924) which explains the thinking around this: > Now I have all these things in the dom service, it would make sense to get window from there also. I was thinking of making a viewport method, which would be a nice word whether window was a browser window, an iframe (not really a window) like when ember testing, or anything else. To me the viewport is what we are actually talking about here.
32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
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 dom = {
|
|
viewport: function() {
|
|
return win;
|
|
},
|
|
};
|
|
const subject = EmberObject.extend(Mixin, {
|
|
dom: dom,
|
|
}).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);
|
|
});
|
|
});
|