Skip to content

Commit

Permalink
fix: ensure resize service is present in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-north committed Aug 23, 2018
1 parent a220271 commit b7a518b
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 12 deletions.
14 changes: 5 additions & 9 deletions app/initializers/resize.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
// eslint-disable-next-line no-unused-vars
import ApplicationInstance from '@ember/application/instance';
import Application from '@ember/application';
import { getWithDefault } from '@ember/object';
import ResizeService from 'ember-resize/services/resize';
import config from '../config/environment';

export function initialize(application: {
register: ApplicationInstance['register'],
unregister: ApplicationInstance['unregister'],
inject: ApplicationInstance['inject'],
}) {
export function initialize(application: Pick<Application, 'register'|'inject'|'unregister'|'resolveRegistration'>) {
const resizeServiceDefaults = getWithDefault(config, 'resizeServiceDefaults', {
debounceTimeout: 200,
heightSensitive: true,
Expand All @@ -17,11 +13,11 @@ export function initialize(application: {
const injectionFactories = getWithDefault(resizeServiceDefaults, 'injectionFactories', ['view', 'component']) || [];

application.unregister('config:resize-service');
application.unregister('service:resize');

application.register('config:resize-service', resizeServiceDefaults, { instantiate: false });
application.register('config:resize-service', resizeServiceDefaults as any, { instantiate: false });
application.register('service:resize', ResizeService);
application.inject('service:resize', 'resizeServiceDefaults', 'config:resize-service');
const resizeService = application.resolveRegistration('service:resize');
resizeService.prototype.resizeServiceDefaults = resizeServiceDefaults;

injectionFactories.forEach((factory) => {
application.inject(factory, 'resizeService', 'service:resize');
Expand Down
16 changes: 16 additions & 0 deletions tests/acceptance/index-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { currentURL, find, visit } from '@ember/test-helpers';
import { EmberApplicationTest } from 'ember-qunit-decorators/test-support';
import { suite, test } from 'qunit-decorators';

@suite('Acceptance | index')
export class IndexAcceptanceTest extends EmberApplicationTest {

@test async 'visiting /'(assert: Assert) {
await visit('/');
assert.equal(currentURL(), '/');

const codeElement: Element | null = find('.index-view code');
if (codeElement === null) { throw new Error('no <code>'); }
assert.ok(/min\-width:\s[0-9]+px/.test('' + codeElement.textContent), 'min-width text found');
}
}
4 changes: 3 additions & 1 deletion tests/dummy/app/components/x-foo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Component from '@ember/component';
import { inject } from '@ember/service';

export default Component.extend({
classNames: ['test-component']
classNames: ['test-component'],
resize: inject()
});
28 changes: 28 additions & 0 deletions tests/integration/components/x-foo-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { render } from '@ember/test-helpers';
import { EmberRenderingTest } from 'ember-qunit-decorators/test-support';
import hbs from 'htmlbars-inline-precompile';
import { suite, test } from 'qunit-decorators';

@suite('Integration | Component | x-foo')
export class XFooComponentTest extends EmberRenderingTest {

@test async 'it renders when used in {{inline-form}}'(assert: Assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });

await render(hbs`{{x-foo}}`);

assert.equal(('' + this.element.textContent).trim(), '');
}

@test async 'it renders when used in {{#block-form}} {{/block-form}}'(assert: Assert) {
// Template block usage:
await render(hbs`
{{#x-foo}}
template block text
{{/x-foo}}
`);

assert.equal(('' + this.element.textContent).trim(), 'template block text');
}
}
2 changes: 1 addition & 1 deletion tests/unit/initializers/resize-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export class ResizeInitializerTest extends EmberTest {
this.testApplication = Application.extend();

this.application = this.testApplication.create({ autoboot: false });
initialize(this.application);
this.instance = (this.application as any).buildInstance();
initialize(this.instance);
}
public afterEach() {
run(this.application, 'destroy');
Expand Down
3 changes: 2 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"rules": {
"quotemark": [true, "single"],
"variable-name": [true, "allow-leading-underscore"],
"interface-name": false
"interface-name": false,
"member-access": false
},
"rulesDirectory": []
}
1 change: 1 addition & 0 deletions types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "dummy/initializers/resize";

0 comments on commit b7a518b

Please sign in to comment.