Skip to content

Commit

Permalink
Add tests for onSubjectAdvance middleware
Browse files Browse the repository at this point in the history
Override the mock feedback store with stores that have active and inactive feedback. Test the middleware for both cases.
  • Loading branch information
eatyourgreens committed Mar 20, 2019
1 parent 8a33b93 commit aeaefc7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/lib-classifier/src/store/FeedbackStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const FeedbackStore = types
setOnHide,
showFeedback,
hideFeedback,
onSubjectAdvance,
update,
reset
}
Expand Down
45 changes: 42 additions & 3 deletions packages/lib-classifier/src/store/FeedbackStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ describe('Model > FeedbackStore', function () {

describe('hideFeedback', function () {
beforeEach(function () {
feedback.subjects = {
advance: () => true
}
feedback.setOnHide(sinon.stub())
feedback.hideFeedback()
})
Expand Down Expand Up @@ -160,4 +157,46 @@ describe('Model > FeedbackStore', function () {
expect(feedback.hideSubjectViewer).to.equal(false)
})
})

describe('when the subject queue advances', function () {
const call = {
name: 'advance',
args: []
}
const next = sinon.stub()
const abort = sinon.stub()

describe('when feedback is inactive', function () {
beforeEach(function () {
feedback = FeedbackStore.create({ isActive: false })
feedback.onSubjectAdvance(call, next, abort)
})

it('should continue the action', function () {
expect(next.withArgs(call)).to.have.been.calledOnce
})
})

describe('when feedback is active', function () {
beforeEach(function () {
feedback = FeedbackStore.create(feedbackStub)
feedback.subjects = {
advance: sinon.stub()
}
feedback.onSubjectAdvance(call, next, abort)
})

it('should abort the action', function () {
expect(abort).to.have.been.calledOnce
})

it('should show feedback', function () {
expect(feedback.showModal).to.be.true
})

it('should set the onHide callback', function () {
expect(feedback.onHide).to.equal(feedback.subjects.advance)
})
})
})
})

0 comments on commit aeaefc7

Please sign in to comment.