mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-29 03:17:47 +08:00
3a947ccf54
Summary: Give UpdateThreadsTask a description method for strings like "Marked as read" Give ChangeLabelsTask a better description method that returns shorter strings and is specific when possible Give ChangeFolderTask a more specific description and don't assume folderOrId will always be a folder Make it so that passive "mark as read" from the message store isn't undoable Give the base class a description method that names the object Change UndoRedo component CSS a bit: - Use "inline-flexbox" with a max-width so that we can define shrinking rules on the label and Undo button (label gets ellipsis, button does not shrink at all) - Avoid left:39%, since it assumed that the undo-redo element would be 22% of the width of the thread list, which wasn't always true. Instead, make the `undo-redo-manager` container "text-align:center", so the `undo-redo` div is always centered within it. - Add `cursor:default` so that the user sees the pointer, not the text insertion cursor when hovering over "Undo" - Add overflow / text-overflow so that if the message is ever too long, the user sees `...` ellipsis properly. Test Plan: Run a few new tests Reviewers: evan, ethanb Reviewed By: ethanb Differential Revision: https://phab.nylas.com/D1830
142 lines
5.1 KiB
CoffeeScript
142 lines
5.1 KiB
CoffeeScript
Task = require '../../src/flux/tasks/task'
|
|
Model = require '../../src/flux/models/model'
|
|
NylasAPI = require '../../src/flux/nylas-api'
|
|
Attributes = require '../../src/flux/attributes'
|
|
DatabaseStore = require '../../src/flux/stores/database-store'
|
|
UpdateNylasObjectsTask = require '../../src/flux/tasks/update-nylas-objects-task'
|
|
|
|
{APIError} = require '../../src/flux/errors'
|
|
|
|
class TestModel extends Model
|
|
@attributes:
|
|
'name': Attributes.String
|
|
modelKey: 'name'
|
|
'unread': Attributes.Boolean
|
|
modelKey: 'unread'
|
|
'starred': Attributes.Boolean
|
|
modelKey: 'starred'
|
|
|
|
describe 'UpdateNylasObjectsTask', ->
|
|
|
|
beforeEach ->
|
|
@origValues =
|
|
"id-1":
|
|
id: "id-1"
|
|
name: "Evan"
|
|
unread: true
|
|
starred: false
|
|
"id-2":
|
|
id: "id-2"
|
|
name: "Ben"
|
|
unread: true
|
|
starred: false
|
|
"id-3":
|
|
id: "id-3"
|
|
name: "Michael"
|
|
unread: true
|
|
starred: false
|
|
|
|
@newValues =
|
|
unread: false
|
|
starred: true
|
|
|
|
@objects = [
|
|
new TestModel(@origValues["id-1"])
|
|
new TestModel(@origValues["id-2"])
|
|
new TestModel(@origValues["id-3"])
|
|
]
|
|
@objects[0].id = "id-1"
|
|
@objects[1].id = "id-2"
|
|
@objects[2].id = "id-3"
|
|
|
|
spyOn(DatabaseStore, 'persistModels').andCallFake -> Promise.resolve()
|
|
|
|
@task = new UpdateNylasObjectsTask(@objects, @newValues)
|
|
|
|
describe 'when performing local', ->
|
|
it "saves the updates to the db", ->
|
|
waitsForPromise =>
|
|
@task.performLocal().then =>
|
|
expect(DatabaseStore.persistModels).toHaveBeenCalledWith(@objects)
|
|
objects = DatabaseStore.persistModels.calls[0].args[0]
|
|
for obj in objects
|
|
expect(obj.unread).toBe @newValues.unread
|
|
expect(obj.starred).toBe @newValues.starred
|
|
|
|
describe 'when performing remote', ->
|
|
it "persists data to the api", ->
|
|
spyOn(NylasAPI, 'makeRequest').andCallFake -> Promise.resolve()
|
|
waitsForPromise =>
|
|
@task.performRemote().then (status) =>
|
|
expect(NylasAPI.makeRequest).toHaveBeenCalled()
|
|
for call, i in NylasAPI.makeRequest.calls
|
|
opts = call.args[0]
|
|
expect(opts.path).toBe "/n/nsid/testmodels/#{@objects[i].id}"
|
|
expect(status).toBe Task.Status.Finished
|
|
|
|
it "reverts if there's an error", ->
|
|
spyOn(NylasAPI, 'makeRequest').andCallFake ->
|
|
Promise.reject(new APIError(statusCode: 404))
|
|
waitsForPromise =>
|
|
@task.performRemote().then =>
|
|
expect(NylasAPI.makeRequest).toHaveBeenCalled()
|
|
origIds = @objects.map (obj) -> obj.id
|
|
calledIds = DatabaseStore.persistModels.calls[0].args[0].map (o) -> o.id
|
|
expect(origIds).toEqual calledIds
|
|
objects = DatabaseStore.persistModels.calls[0].args[0]
|
|
for obj in objects
|
|
expect(obj.unread).toBe true
|
|
expect(obj.starred).toBe false
|
|
|
|
it "retries if there are retryable errors", ->
|
|
spyOn(NylasAPI, 'makeRequest').andCallFake ->
|
|
Promise.reject(new APIError(statusCode: 0))
|
|
spyOn(@task, "performLocal")
|
|
waitsForPromise =>
|
|
@task.performRemote().then (status) =>
|
|
expect(NylasAPI.makeRequest).toHaveBeenCalled()
|
|
for call, i in NylasAPI.makeRequest.calls
|
|
opts = call.args[0]
|
|
expect(opts.path).toBe "/n/nsid/testmodels/#{@objects[i].id}"
|
|
expect(status).toBe Task.Status.Retry
|
|
expect(@task.performLocal).not.toHaveBeenCalled()
|
|
|
|
describe 'description', ->
|
|
it 'should default to "Updated `count` `type``"', ->
|
|
objects = [
|
|
new TestModel(@origValues["id-1"])
|
|
new TestModel(@origValues["id-2"])
|
|
new TestModel(@origValues["id-3"])
|
|
]
|
|
task = new UpdateNylasObjectsTask(objects, {bla: true})
|
|
expect(task.description()).toEqual("Updated 3 testmodels")
|
|
task = new UpdateNylasObjectsTask([objects[0]], {bla: true})
|
|
expect(task.description()).toEqual("Updated 1 testmodel")
|
|
|
|
describe 'when undoing', ->
|
|
beforeEach ->
|
|
@undoTask = new UpdateNylasObjectsTask(@objects, {}, @origValues)
|
|
@undoTask._isUndoTask = true
|
|
|
|
describe 'when performing local', ->
|
|
it "saves the old values to the db", ->
|
|
waitsForPromise =>
|
|
@undoTask.performLocal().then =>
|
|
expect(DatabaseStore.persistModels).toHaveBeenCalledWith(@objects)
|
|
objects = DatabaseStore.persistModels.calls[0].args[0]
|
|
for obj in objects
|
|
expect(obj.unread).toBe true
|
|
expect(obj.starred).toBe false
|
|
|
|
describe 'when performing remote', ->
|
|
it "persists the old values to the API", ->
|
|
spyOn(NylasAPI, 'makeRequest').andCallFake -> Promise.resolve()
|
|
waitsForPromise =>
|
|
@undoTask.performRemote().then (status) =>
|
|
expect(NylasAPI.makeRequest).toHaveBeenCalled()
|
|
for call, i in NylasAPI.makeRequest.calls
|
|
opts = call.args[0]
|
|
expect(opts.path).toBe "/n/nsid/testmodels/#{@objects[i].id}"
|
|
expect(opts.body.unread).toBe true
|
|
expect(opts.body.starred).toBe false
|
|
expect(status).toBe Task.Status.Finished
|