Mailspring/spec/mailbox-perspective-spec.coffee
Ben Gotow f63b7e66e4 feat(swipe-to-*): Gesture support and animation in thread list
Summary:
This diff does two things:
- It adds a new SwipeContainer that makes it easy to implement swipe gestures. This is built into listTabular, so you can create a list and define onSwipeLeft/Right to enable gestures.

- It adds support for basic add/remove animations to the thread list. This works by adding a CSS transition to `top` and also leaving removed rows around for a specified time. (these times need to match.) Pretty much just cloned the core idea from TimeoutTransitionGroup.

Test Plan: No tests yet

Reviewers: evan, juan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D2581
2016-02-19 18:22:28 -08:00

107 lines
3.9 KiB
CoffeeScript

{AccountStore,
MailboxPerspective,
TaskFactory,
Category,
Thread,
Actions,
DatabaseStore} = require 'nylas-exports'
describe 'MailboxPerspective', ->
beforeEach ->
spyOn(AccountStore, 'accountForId').andReturn(AccountStore.accounts()[0])
@accountIds = ['a1', 'a2', 'a3']
@perspective = new MailboxPerspective(@accountIds)
describe 'isEqual', ->
# TODO
describe 'canReceiveThreads', ->
it 'returns true if the thread account ids are included in the current account ids', ->
expect(@perspective.canReceiveThreads(['a1'])).toBe true
it 'returns false otherwise', ->
expect(@perspective.canReceiveThreads(['a4'])).toBe false
expect(@perspective.canReceiveThreads([])).toBe false
expect(@perspective.canReceiveThreads()).toBe false
describe 'CategoriesMailboxPerspective', ->
beforeEach ->
@accountIds = ['a1', 'a2']
@categories = [
new Category(displayName: 'c1', accountId: 'a1')
new Category(displayName: 'c2', accountId: 'a2')
new Category(displayName: 'c3', accountId: 'a2')
]
@perspective = MailboxPerspective.forCategories(@categories)
describe 'canReceiveThreads', ->
it 'returns true if the thread account ids are included in the current account ids', ->
expect(@perspective.canReceiveThreads(['a2'])).toBe true
it 'returns false otherwise', ->
expect(@perspective.canReceiveThreads(['a4'])).toBe false
expect(@perspective.canReceiveThreads([])).toBe false
expect(@perspective.canReceiveThreads()).toBe false
it 'returns false if it is not a locked category', ->
@perspective._categories.push(
new Category(name: 'sent', displayName: 'c4', accountId: 'a1')
)
expect(@perspective.canReceiveThreads(['a2'])).toBe false
describe 'receiveThreads', ->
# TODO
describe 'removeThreads', ->
beforeEach ->
@threads = [new Thread(id:'t1'), new Thread(id: 't2')]
spyOn(Actions, 'queueTasks')
spyOn(DatabaseStore, 'modelify').andReturn then: (cb) => cb(@threads)
it 'moves the threads to finished category if in inbox', ->
spyOn(TaskFactory, 'tasksForRemovingCategories')
@categories = [
new Category(name: 'inbox', accountId: 'a1')
new Category(name: 'inbox', accountId: 'a2')
new Category(name: 'inbox', accountId: 'a2')
]
@perspective = MailboxPerspective.forCategories(@categories)
@perspective.removeThreads(@threads)
expect(TaskFactory.tasksForRemovingCategories).toHaveBeenCalledWith({
threads: @threads,
moveToFinishedCategory: true,
categories: @categories
})
it 'moves threads to inbox if in trash', ->
spyOn(TaskFactory, 'tasksForMovingToInbox')
@categories = [
new Category(name: 'trash', accountId: 'a1')
new Category(name: 'trash', accountId: 'a2')
new Category(name: 'trash', accountId: 'a2')
]
@perspective = MailboxPerspective.forCategories(@categories)
@perspective.removeThreads(@threads)
expect(TaskFactory.tasksForMovingToInbox).toHaveBeenCalledWith({
threads: @threads,
fromPerspective: @perspective
})
it 'removes categories if the current perspective does not correspond to archive or sent', ->
spyOn(TaskFactory, 'tasksForRemovingCategories')
@categories = [
new Category(displayName: 'c1', accountId: 'a1')
new Category(displayName: 'c2', accountId: 'a2')
new Category(displayName: 'c3', accountId: 'a2')
]
@perspective = MailboxPerspective.forCategories(@categories)
@perspective.removeThreads(@threads)
expect(TaskFactory.tasksForRemovingCategories).toHaveBeenCalledWith({
threads: @threads,
moveToFinishedCategory: false,
categories: @categories
})