2017-06-29 14:48:45 +08:00
|
|
|
{Folder, Label} = require 'nylas-exports'
|
2016-01-09 01:31:24 +08:00
|
|
|
|
2017-08-26 12:25:49 +08:00
|
|
|
describe 'Category classes', ->
|
2017-06-28 02:31:22 +08:00
|
|
|
describe '.categoriesSharedRole', ->
|
2016-03-08 10:13:53 +08:00
|
|
|
|
2017-06-28 02:31:22 +08:00
|
|
|
it 'returns the name if all the categories on the perspective have the same role', ->
|
2017-08-26 12:25:49 +08:00
|
|
|
expect(Folder.categoriesSharedRole([
|
2017-06-29 14:48:45 +08:00
|
|
|
new Folder({path: 'c1', role: 'c1', accountId: 'a1'}),
|
|
|
|
new Folder({path: 'c1', role: 'c1', accountId: 'a2'}),
|
2016-03-08 10:13:53 +08:00
|
|
|
])).toEqual('c1')
|
|
|
|
|
|
|
|
it 'returns null if there are no categories', ->
|
2017-08-26 12:25:49 +08:00
|
|
|
expect(Folder.categoriesSharedRole([])).toEqual(null)
|
2016-03-08 10:13:53 +08:00
|
|
|
|
2017-06-28 02:31:22 +08:00
|
|
|
it 'returns null if the categories have different roles', ->
|
2017-08-26 12:25:49 +08:00
|
|
|
expect(Folder.categoriesSharedRole([
|
2017-06-29 14:48:45 +08:00
|
|
|
new Folder({path: 'c1', role: 'c1', accountId: 'a1'}),
|
|
|
|
new Folder({path: 'c2', role: 'c2', accountId: 'a2'}),
|
2016-03-08 10:13:53 +08:00
|
|
|
])).toEqual(null)
|
|
|
|
|
2017-06-28 02:31:22 +08:00
|
|
|
describe 'displayName', ->
|
2016-05-13 05:31:49 +08:00
|
|
|
it "should strip the INBOX. prefix from FastMail folders", ->
|
2017-06-29 14:48:45 +08:00
|
|
|
foo = new Folder({path: 'INBOX.Foo'})
|
2016-05-13 05:31:49 +08:00
|
|
|
expect(foo.displayName).toEqual('Foo')
|
2017-06-29 14:48:45 +08:00
|
|
|
foo = new Folder({path: 'INBOX'})
|
2016-05-13 05:31:49 +08:00
|
|
|
expect(foo.displayName).toEqual('Inbox')
|
2016-01-09 01:31:24 +08:00
|
|
|
|
2016-05-13 05:31:49 +08:00
|
|
|
describe 'category types', ->
|
2016-01-09 01:31:24 +08:00
|
|
|
it 'assigns type correctly when it is a user category', ->
|
|
|
|
cat = new Label
|
2017-06-28 02:31:22 +08:00
|
|
|
cat.role = undefined
|
2016-01-09 01:31:24 +08:00
|
|
|
expect(cat.isUserCategory()).toBe true
|
|
|
|
expect(cat.isStandardCategory()).toBe false
|
|
|
|
expect(cat.isHiddenCategory()).toBe false
|
|
|
|
expect(cat.isLockedCategory()).toBe false
|
|
|
|
|
|
|
|
it 'assigns type correctly when it is a standard category', ->
|
|
|
|
cat = new Label
|
2017-06-28 02:31:22 +08:00
|
|
|
cat.role = 'inbox'
|
2016-01-09 01:31:24 +08:00
|
|
|
expect(cat.isUserCategory()).toBe false
|
|
|
|
expect(cat.isStandardCategory()).toBe true
|
|
|
|
expect(cat.isHiddenCategory()).toBe false
|
|
|
|
expect(cat.isLockedCategory()).toBe false
|
|
|
|
|
2016-01-09 09:49:27 +08:00
|
|
|
it 'assigns type for `important` category when should not show important', ->
|
|
|
|
cat = new Label
|
2017-06-28 02:31:22 +08:00
|
|
|
cat.role = 'important'
|
2016-01-09 09:49:27 +08:00
|
|
|
expect(cat.isUserCategory()).toBe false
|
|
|
|
expect(cat.isStandardCategory(false)).toBe false
|
|
|
|
expect(cat.isHiddenCategory()).toBe true
|
|
|
|
expect(cat.isLockedCategory()).toBe false
|
|
|
|
|
2016-01-09 01:31:24 +08:00
|
|
|
it 'assigns type correctly when it is a hidden category', ->
|
|
|
|
cat = new Label
|
2017-06-28 02:31:22 +08:00
|
|
|
cat.role = 'archive'
|
2016-01-09 01:31:24 +08:00
|
|
|
expect(cat.isUserCategory()).toBe false
|
|
|
|
expect(cat.isStandardCategory()).toBe true
|
|
|
|
expect(cat.isHiddenCategory()).toBe true
|
|
|
|
expect(cat.isLockedCategory()).toBe false
|
|
|
|
|
|
|
|
it 'assigns type correctly when it is a locked category', ->
|
|
|
|
cat = new Label
|
2017-06-28 02:31:22 +08:00
|
|
|
cat.role = 'sent'
|
2016-01-09 01:31:24 +08:00
|
|
|
expect(cat.isUserCategory()).toBe false
|
|
|
|
expect(cat.isStandardCategory()).toBe true
|
2016-03-15 02:22:42 +08:00
|
|
|
expect(cat.isHiddenCategory()).toBe true
|
2016-01-14 06:20:44 +08:00
|
|
|
expect(cat.isLockedCategory()).toBe true
|