Mailspring/spec-inbox/inbox-sync-worker-spec.coffee
Ben Gotow d9ee12cf81 refactor(*): Thread list fixes, flexible workspace store, multiple root sheets
Summary:
Remember to remove all the event listeners added to email frame

New files tab, queryable filename, not attribute

Rename ThreadSelectionBar to RootSelectionBar to go with RootCenterComponent, make it appear for draft selection and file selection as well

Initial file list and file list store, File Location

Remove unnecessary shouldComponentUpdate

Always track whether new requests have happened since ours to prevent out of order triggers

Always scroll to the current [focused/keyboard-cursor] in lists

So goodbye to the trash tag

Only scroll to current item if focus or keyboard has moved

Show message snippet in notification if no subject line

Make the RootSelectionBar pull items from Component Registry

New Archive button (prettier than the other one)

Refactor event additions to iframe so iframe can be used for file display also

Thread List is no longer the uber root package - drafts and files moved to separate packages

WorkspaceStore now allows packages to register sheets, "view" concept replaced with "root sheet" concept, "mode" may not be observed by all sheets, and is now called "preferred mode"

Don't animate transitions between two root sheets

Mode switch is only visible on root sheets that support multiple modes

Account sidebar now shows "Views" that have registered themselves: drafts and files for now

Model Selection Bar is now a component, just like ModelList. Meant to be in the toolbar above a Model List

Misc supporting changes

New files package which registers it's views and components

Rename files package to `file-list`

Move checkmark column down into model list

Don't throw exception if shift-down arrow and nothing selected

Takes a long time on login to fetch first page of threads, make pages smaller

Displaynames, spec fixes

Test Plan: Run tests

Reviewers: evan

Reviewed By: evan

Differential Revision: https://review.inboxapp.com/D1412
2015-04-10 14:33:05 -07:00

121 lines
4 KiB
CoffeeScript

_ = require 'underscore-plus'
InboxLongConnection = require '../src/flux/inbox-long-connection'
InboxSyncWorker = require '../src/flux/inbox-sync-worker'
Thread = require '../src/flux/models/thread'
describe "InboxSyncWorker", ->
beforeEach ->
@apiRequests = []
@api =
getCollection: (namespace, model, params, requestOptions) =>
@apiRequests.push({namespace, model, params, requestOptions})
getThreads: (namespace, params, requestOptions) =>
@apiRequests.push({namespace, model:'threads', params, requestOptions})
@state =
"contacts": {busy: true}
"calendars": {complete: true}
spyOn(atom.config, 'get').andCallFake (key) =>
expected = "inbox.namespace-id.worker-state"
return throw new Error("Not stubbed!") unless key is expected
return @state
spyOn(atom.config, 'set').andCallFake (key, val) =>
expected = "inbox.namespace-id.worker-state"
return throw new Error("Not stubbed!") unless key is expected
@state = val
@worker = new InboxSyncWorker(@api, 'namespace-id')
@connection = @worker.connection()
describe "start", ->
it "should open the long polling connection", ->
spyOn(@connection, 'start')
@worker.start()
expect(@connection.start).toHaveBeenCalled()
it "should start querying for model collections that haven't been fully cached", ->
@worker.start()
expect(@apiRequests.length).toBe(3)
modelsRequested = _.map @apiRequests, (r) -> r.model
expect(modelsRequested).toEqual(['threads', 'contacts', 'files'])
it "should mark incomplete collections as `busy`", ->
@worker.start()
expect(@state).toEqual({
"contacts": {busy: true}
"threads": {busy: true}
"files": {busy: true}
"calendars": {complete: true}
})
describe "when an API request completes", ->
beforeEach ->
@worker.start()
@request = @apiRequests[0]
@apiRequests = []
describe "successfully, with models", ->
it "should request the next page", ->
models = []
models.push(new Thread) for i in [0..249]
@request.requestOptions.success(models)
expect(@apiRequests.length).toBe(1)
expect(@apiRequests[0].params).toEqual({limit:250; offset: 250})
describe "successfully, with fewer models than requested", ->
beforeEach ->
models = []
models.push(new Thread) for i in [0..100]
@request.requestOptions.success(models)
it "should not request another page", ->
@request.requestOptions.success([])
expect(@apiRequests.length).toBe(0)
it "should update the state to complete", ->
@request.requestOptions.success([])
expect(@state).toEqual({
"contacts": {busy: true}
"files": {busy: true}
"threads": {complete : true}
"calendars": {complete: true}
})
describe "successfully, with no models", ->
it "should not request another page", ->
@request.requestOptions.success([])
expect(@apiRequests.length).toBe(0)
it "should update the state to complete", ->
@request.requestOptions.success([])
expect(@state).toEqual({
"contacts": {busy: true}
"files": {busy: true}
"threads": {complete : true}
"calendars": {complete: true}
})
describe "with an error", ->
it "should log the error to the state", ->
err = new Error("Oh no a network error")
@request.requestOptions.error(err)
expect(@state).toEqual({
"contacts": {busy: true}
"files": {busy: true}
"threads": {busy: false, error: err.toString()}
"calendars": {complete: true}
})
it "should not request another page", ->
@request.requestOptions.error(new Error("Oh no a network error"))
expect(@apiRequests.length).toBe(0)
describe "cleanup", ->
it "should termiate the long polling connection", ->
spyOn(@connection, 'end')
@worker.cleanup()
expect(@connection.end).toHaveBeenCalled()