Last active
September 10, 2015 12:38
-
-
Save lolmaus/16c095d1c104cede9cd6 to your computer and use it in GitHub Desktop.
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 StartExamMixin from '../../../mixins/start-exam'; | |
import { module, test } from 'qunit'; | |
import sinon from 'sinon'; | |
const { | |
RSVP, | |
ActionHandler | |
} = Ember; | |
module('Unit | Mixin | start exam'); | |
test('action start', function(assert) { | |
assert.expect(3); | |
let spy, resolve; | |
const exam = { | |
createExamSession() { | |
return new RSVP.Promise((res) => { resolve = res; }); | |
} | |
}; | |
const StartExamObject = Ember.Object.extend(ActionHandler, StartExamMixin, { | |
attrs: { | |
actionTransitionToSession: spy = sinon.spy() | |
} | |
}); | |
const subject = StartExamObject.create(); | |
const done = assert.async(); | |
const promiseWaiter = (prm) => { | |
prm.then(() => { | |
assert.ok(spy.calledOnce); | |
assert.ok(spy.calledWith('foo')); | |
done(); | |
}); | |
}; | |
subject.send('start', exam, promiseWaiter); | |
assert.ok(spy.notCalled); | |
resolve({id: 'foo'}); | |
}); |
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 _ from 'npm:lodash'; | |
export default Ember.Mixin.create({ | |
actions: { | |
start(exam, promiseWaiter) { | |
const prm = | |
exam | |
.createExamSession() | |
.then((session) => { | |
this.attrs.actionTransitionToSession(session.id); | |
}); | |
if (_.isFunction(promiseWaiter)) { | |
promiseWaiter(prm); | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment