-
-
Save acorncom/211e91357ce01bca31c745690a8f182c to your computer and use it in GitHub Desktop.
so#43547516
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('simple-ajax-route'); | |
this.route('test-promise-route'); | |
this.route('rsvp-promise-route'); | |
this.route('simple-timeout-route'); | |
}); | |
export default Router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
return {title: 'Initial Title'}; | |
}, | |
actions: { | |
doAjaxCall() { | |
new Ember.RSVP.Promise((resolve)=> { | |
Ember.run.later(this, ()=> { | |
this.controllerFor(this.get('routeName')).set('model.title', 'modified'); | |
resolve(1); | |
}, 1000); | |
}); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
return {title: 'Initial Title'}; | |
}, | |
actions: { | |
doAjaxCall() { | |
let requestParams = {url: `https://jsonplaceholder.typicode.com/photos/1`, | |
type: 'GET', contentType: 'application/json', dataType:'json'}; | |
Ember.$.ajax(requestParams).then((json)=>{ | |
Ember.run(()=>{ | |
this.controllerFor(this.get('routeName')).set('model.title', json.title); | |
}); | |
}); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
return {title: 'Initial Title'}; | |
}, | |
actions: { | |
doAjaxCall() { | |
Ember.run.later(this, ()=> { | |
this.controllerFor(this.get('routeName')).set('model.title', 'modified'); | |
}, 3000); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
return {title: 'Initial Title'}; | |
}, | |
actions: { | |
doAjaxCall() { | |
new Ember.Test.Promise((resolve)=> { | |
window.setTimeout(()=> { | |
Ember.run(()=> { | |
this.controllerFor(this.get('routeName')).set('model.title', 'modified'); | |
resolve(1); | |
}); | |
}, 1000); | |
}); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { test } from 'qunit'; | |
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; | |
moduleForAcceptance('rsvp-promise-route: andThen works with rsvp promise'); | |
test('visiting /rsvp-promise-route', function(assert) { | |
visit('/rsvp-promise-route'); | |
andThen(function() { | |
assert.equal(currentURL(), '/rsvp-promise-route'); | |
assert.equal(find('.title').text().trim(), 'Title is : Initial Title'); | |
}); | |
click('button'); | |
andThen(function() { | |
assert.equal(find('.title').text().trim(), 'Title is : modified'); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { test } from 'qunit'; | |
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; | |
moduleForAcceptance('simple-ajax-route: andThen simply works for ajax call'); | |
test('visiting /simple-ajax-route', function(assert) { | |
visit('/simple-ajax-route'); | |
andThen(function() { | |
assert.equal(currentURL(), '/simple-ajax-route'); | |
assert.equal(find('.title').text().trim(), 'Title is : Initial Title'); | |
}); | |
click('button'); | |
andThen(function() { | |
assert.equal(find('.title').text().trim(), 'Title is : accusamus beatae ad facilis cum similique qui sunt'); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { test } from 'qunit'; | |
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; | |
moduleForAcceptance('simple-timeout-route: andThen works for timeouting routes'); | |
test('visiting /simple-timeout-route', function(assert) { | |
visit('/simple-timeout-route'); | |
andThen(function() { | |
assert.equal(currentURL(), '/simple-timeout-route'); | |
assert.equal(find('.title').text().trim(), 'Title is : Initial Title'); | |
}); | |
click('button'); | |
andThen(function() { | |
assert.equal(find('.title').text().trim(), 'Title is : modified'); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { test } from 'qunit'; | |
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; | |
moduleForAcceptance('test-promise-route: andThen works for test promise'); | |
test('visiting /test-promise-route', function(assert) { | |
visit('/test-promise-route'); | |
andThen(function() { | |
assert.equal(currentURL(), '/test-promise-route'); | |
assert.equal(find('.title').text().trim(), 'Title is : Initial Title'); | |
}); | |
click('button'); | |
andThen(function() { | |
assert.equal(find('.title').text().trim(), 'Title is : modified'); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default function destroyApp(application) { | |
Ember.run(application, 'destroy'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { module } from 'qunit'; | |
import Ember from 'ember'; | |
import startApp from '../helpers/start-app'; | |
import destroyApp from '../helpers/destroy-app'; | |
const { RSVP: { Promise } } = Ember; | |
export default function(name, options = {}) { | |
module(name, { | |
beforeEach() { | |
this.application = startApp(); | |
if (options.beforeEach) { | |
return options.beforeEach.apply(this, arguments); | |
} | |
}, | |
afterEach() { | |
let afterEach = options.afterEach && options.afterEach.apply(this, arguments); | |
return Promise.resolve(afterEach).then(() => destroyApp(this.application)); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Resolver from '../../resolver'; | |
import config from '../../config/environment'; | |
const resolver = Resolver.create(); | |
resolver.namespace = { | |
modulePrefix: config.modulePrefix, | |
podModulePrefix: config.podModulePrefix | |
}; | |
export default resolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import resolver from './helpers/resolver'; | |
import { | |
setResolver | |
} from 'ember-qunit'; | |
setResolver(resolver); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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-route-action-helper": "2.0.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment