Skip to content

Instantly share code, notes, and snippets.

@skitterm
Created October 10, 2017 18:49
Show Gist options
  • Save skitterm/b565b1ac3bee48da863922ce1ec5b14e to your computer and use it in GitHub Desktop.
Save skitterm/b565b1ac3bee48da863922ce1ec5b14e to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Component.extend({
attributeBindings: ['style'],
style: 'height: 600px; overflow: auto; position: relative;',
result: 'Waiting...',
timeoutWaiting: false,
animationWaiting: false,
actions: {
callAjax() {
$.ajax({
url: 'https://testing-story.maps.arcgis.com/sharing/rest/content/items/5910edd71293446b8275891761f1b31a/data?f=json',
success: () => {
Ember.run(() => {
this.set('result', 'ajax');
});
}
});
},
callPromise() {
this.get('getThePromise')()
.then(() => {
this.set('result', 'promise');
});
},
callTimeout() {
this.set('timeoutWaiting', true);
Ember.Test.registerWaiter(() => {
return this.get('timeoutWaiting') === false;
});
setTimeout(() => {
Ember.run(() => {
this.set('result', 'timeout');
this.set('timeoutWaiting', false);
});
}, 1000);
},
callImage() {
this.set('result', 'image');
},
callAnimation() {
this.set('animationWaiting', true);
Ember.Test.registerWaiter(() => {
return this.get('animationWaiting') === false;
});
this.$().scroll(() => {
if (this.$().scrollTop() === 50) {
Ember.run(() => {
this.set('result', 'animation');
this.set('animationWaiting', false);
});
}
});
this.$().animate({
scrollTop: 50
}, 1000);
}
},
getThePromise() {
return new Ember.RSVP.Promise((resolve) => {
$.ajax({
url: 'https://testing-story.maps.arcgis.com/sharing/rest/content/items/5910edd71293446b8275891761f1b31a/data?f=json',
success: () => {
resolve();
}
});
});
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<div id="divvy" style="height: 2000px;">
<button {{action "callAjax"}} class="ajax">Ajax</button>
<button {{action "callPromise"}} class="promise">Promise</button>
<button {{action "callTimeout"}} class="timeout">Timeout</button>
<button {{action "callImage"}} class="image">Image</button>
<button {{action "callAnimation"}} class="animation">Animation</button>
<h2 class="result">{{result}}</h2>
</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 wait from 'ember-test-helpers/wait';
moduleForComponent('async-component', 'TODO: put something here', {
integration: true
});
test('ajax sets property', function(assert) {
this.render(hbs`{{async-component}}`);
this.$('.ajax')[0].click();
return wait().then(() => {
assert.equal(this.$('.result').text(), 'ajax');
});
});
test('promise sets property', function(assert) {
this.render(hbs`{{async-component}}`);
this.$('.promise')[0].click();
return wait().then(() => {
assert.equal(this.$('.result').text(), 'promise');
});
});
test('timeout sets property', function(assert) {
this.render(hbs`{{async-component}}`);
this.$('.timeout')[0].click();
return wait().then(() => {
assert.equal(this.$('.result').text(), 'timeout');
});
});
test('animation sets property', function(assert) {
assert.expect(2);
this.render(hbs`{{async-component}}`);
this.$('.animation')[0].click();
return wait().then(() => {
assert.equal(this.$('.result').text(), 'animation');
assert.equal(this.$('#divvy').position().top, -50);
});
});
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
{
"version": "0.12.1",
"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.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment