Skip to content

Instantly share code, notes, and snippets.

@code0100fun
Forked from Gaurav0/components.my-component.js
Last active September 20, 2017 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save code0100fun/58027e0abcdbda5ee6001ce01245eac5 to your computer and use it in GitHub Desktop.
Save code0100fun/58027e0abcdbda5ee6001ce01245eac5 to your computer and use it in GitHub Desktop.
ember-native-dom-helpers
import Ember from 'ember';
export default Ember.Component.extend({
showPopup: false,
actions: {
blurA() {
this.set('showPopup', false);
},
focusA() {
this.set('showPopup', true);
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
{{my-component}}
<div>
<input id="field-a"
onblur={{action "blurA"}}
onfocus={{action "focusA"}}
type="text">
{{#if showPopup}}
<span class="popup">Popup</span>
{{/if}}
</div>
<div>
<input id="field-b" type="text">
</div>
import Ember from 'ember';
export default function destroyApp(application) {
Ember.run(application, 'destroy');
}
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
const { run } = Ember;
const assign = Ember.assign || Ember.merge;
export default function startApp(attrs) {
let application;
let attributes = assign({rootElement: "#test-root"}, config.APP);
attributes = assign(attributes, attrs); // use defaults, but you can override;
run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
//import { click } from 'ember-native-dom-helpers/test-support/helpers';
moduleForComponent('my-component', 'My Component', {
integration: true
});
test('shows popup when field A has focus', function(assert) {
this.render(hbs`{{my-componnet}}`);
assert.ok(this.$('.popup').not(':visible'), 'popup is not visible');
this.$('#field-a').click();
//click('#field-a');
assert.ok(this.$('.popup').is(':visible'), 'popup is visible');
this.$('#field-b').click();
//click('#field-b');
assert.ok(this.$('.popup').not(':visible'), 'popup is not visible');
});
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
{
"version": "0.10.7",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": true
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.10.0",
"ember-data": "2.10.0",
"ember-template-compiler": "2.10.0",
"ember-testing": "2.10.0"
},
"addons": {
"ember-native-dom-helpers": "0.3.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment