mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 21:57:55 +08:00
51602f69a5
Converted all references of global atom to NylasEnv Temporary rename atom.io find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.io/temporaryAtomIoReplacement/g' atom.config to NylasEnv.config find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.config/NylasEnv.config/g' atom.packages -> NylasEnv.packages atom.commands -> NylasEnv.commands atom.getLoadSettings find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.commands/NylasEnv.commands/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.getLoadSettings/NylasEnv.getLoadSettings/g' More common atom methods find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.styles/NylasEnv.styles/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.emitError/NylasEnv.emitError/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.inSpecMode/NylasEnv.inSpecMode/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.inDevMode/NylasEnv.inDevMode/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.getWindowType/NylasEnv.getWindowType/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.displayWindow/NylasEnv.displayWindow/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.quit/NylasEnv.quit/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.close/NylasEnv.close/g' More atom method changes find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.keymaps/NylasEnv.keymaps/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.hide/NylasEnv.hide/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.getCurrentWindow/NylasEnv.getCurrentWindow/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.menu/NylasEnv.menu/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.getConfigDirPath/NylasEnv.getConfigDirPath/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.isMainWindow/NylasEnv.isMainWindow/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.finishUnload/NylasEnv.finishUnload/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.isWorkWindow/NylasEnv.isWorkWindow/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.showSaveDialog/NylasEnv.showSaveDialog/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.append/NylasEnv.append/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.confirm/NylasEnv.confirm/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.clipboard/NylasEnv.clipboard/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.getVersion/NylasEnv.getVersion/g' More atom renaming Rename atom methods More atom methods Fix grunt config variable Change atom.cmd to N1.cmd Rename atom.coffee and atom.js to nylas-env.coffee nylas-env.js Fix atom global reference in specs manually Fix atom requires Change engine from atom to nylas got rid of global/nylas-env rename to nylas-win-bootup Fix onWindowPropsChanged to onWindowPropsReceived fix nylas-workspace atom-text-editor to nylas-theme-wrap atom-text-editor -> nylas-theme-wrap Replacing atom keyword AtomWindow -> NylasWindow Replace Atom -> N1 Rename atom items nylas.asar -> atom.asar Remove more atom references Remove 6to5 references Remove license exception for atom
192 lines
7 KiB
CoffeeScript
192 lines
7 KiB
CoffeeScript
_ = require 'underscore'
|
|
React = require "react/addons"
|
|
ReactTestUtils = React.addons.TestUtils
|
|
CategoryPicker = require '../lib/category-picker'
|
|
{Popover} = require 'nylas-component-kit'
|
|
|
|
{Utils,
|
|
Label,
|
|
Folder,
|
|
Thread,
|
|
Actions,
|
|
AccountStore,
|
|
CategoryStore,
|
|
DatabaseStore,
|
|
TaskFactory,
|
|
SyncbackCategoryTask,
|
|
FocusedMailViewStore,
|
|
TaskQueueStatusStore} = require 'nylas-exports'
|
|
|
|
describe 'CategoryPicker', ->
|
|
beforeEach ->
|
|
CategoryStore._categoryCache = {}
|
|
|
|
afterEach ->
|
|
NylasEnv.testOrganizationUnit = null
|
|
|
|
setupFor = (organizationUnit) ->
|
|
NylasEnv.testOrganizationUnit = organizationUnit
|
|
@categoryClass = if organizationUnit is "label" then Label else Folder
|
|
|
|
@inboxCategory = new @categoryClass(id: 'id-123', name: 'inbox', displayName: "INBOX")
|
|
@archiveCategory = new @categoryClass(id: 'id-456', name: 'archive', displayName: "ArCHIVe")
|
|
@userCategory = new @categoryClass(id: 'id-789', name: null, displayName: "MyCategory")
|
|
|
|
spyOn(CategoryStore, "getStandardCategories").andReturn [ @inboxCategory, @archiveCategory ]
|
|
spyOn(CategoryStore, "getUserCategories").andReturn [ @userCategory ]
|
|
spyOn(CategoryStore, "getStandardCategory").andReturn @inboxCategory
|
|
|
|
# By default we're going to set to "inbox". This has implications for
|
|
# what categories get filtered out of the list.
|
|
f = FocusedMailViewStore
|
|
f._setMailView f._defaultMailView()
|
|
|
|
setupForCreateNew = (orgUnit = "folder") ->
|
|
setupFor.call(@, orgUnit)
|
|
|
|
@testThread = new Thread(id: 't1', subject: "fake")
|
|
@picker = ReactTestUtils.renderIntoDocument(
|
|
<CategoryPicker thread={@testThread} />
|
|
)
|
|
|
|
@popover = ReactTestUtils.findRenderedComponentWithType @picker, Popover
|
|
@popover.open()
|
|
|
|
describe 'when using labels', ->
|
|
beforeEach ->
|
|
setupFor.call(@, "label")
|
|
|
|
describe 'when using folders', ->
|
|
beforeEach ->
|
|
setupFor.call(@, "folder")
|
|
|
|
@testThread = new Thread(id: 't1', subject: "fake")
|
|
@picker = ReactTestUtils.renderIntoDocument(
|
|
<CategoryPicker thread={@testThread} />
|
|
)
|
|
|
|
it 'lists the desired categories', ->
|
|
data = @picker.state.categoryData
|
|
# NOTE: The inbox category is not included here because it's the
|
|
# currently focused category, which gets filtered out of the list.
|
|
expect(data[0].id).toBe "id-456"
|
|
expect(data[0].name).toBe "archive"
|
|
expect(data[0].category).toBe @archiveCategory
|
|
expect(data[1].divider).toBe true
|
|
expect(data[1].id).toBe "category-divider"
|
|
expect(data[2].id).toBe "id-789"
|
|
expect(data[2].name).toBeUndefined()
|
|
expect(data[2].category).toBe @userCategory
|
|
|
|
describe "'create new' item", ->
|
|
beforeEach ->
|
|
setupForCreateNew.call @
|
|
|
|
afterEach -> NylasEnv.testOrganizationUnit = null
|
|
|
|
it "is not visible when the search box is empty", ->
|
|
count = ReactTestUtils.scryRenderedDOMComponentsWithClass(@picker, 'category-create-new').length
|
|
expect(count).toBe 0
|
|
|
|
it "is visible when the search box has text", ->
|
|
inputNode = React.findDOMNode(ReactTestUtils.scryRenderedDOMComponentsWithTag(@picker, "input")[0])
|
|
ReactTestUtils.Simulate.change inputNode, target: { value: "calendar" }
|
|
count = ReactTestUtils.scryRenderedDOMComponentsWithClass(@picker, 'category-create-new').length
|
|
expect(count).toBe 1
|
|
|
|
it "shows folder icon if we're using exchange", ->
|
|
inputNode = React.findDOMNode(ReactTestUtils.scryRenderedDOMComponentsWithTag(@picker, "input")[0])
|
|
ReactTestUtils.Simulate.change inputNode, target: { value: "calendar" }
|
|
count = ReactTestUtils.scryRenderedDOMComponentsWithClass(@picker, 'category-create-new-folder').length
|
|
expect(count).toBe 1
|
|
|
|
describe "'create new' item with labels", ->
|
|
beforeEach ->
|
|
setupForCreateNew.call @, "label"
|
|
|
|
it "shows label icon if we're using gmail", ->
|
|
inputNode = React.findDOMNode(ReactTestUtils.scryRenderedDOMComponentsWithTag(@picker, "input")[0])
|
|
ReactTestUtils.Simulate.change inputNode, target: { value: "calendar" }
|
|
count = ReactTestUtils.scryRenderedDOMComponentsWithClass(@picker, 'category-create-new-tag').length
|
|
expect(count).toBe 1
|
|
|
|
describe "_onSelectCategory()", ->
|
|
beforeEach ->
|
|
setupForCreateNew.call @, "folder"
|
|
spyOn(TaskFactory, 'taskForRemovingCategory').andCallThrough()
|
|
spyOn(TaskFactory, 'taskForApplyingCategory').andCallThrough()
|
|
spyOn(Actions, "queueTask")
|
|
|
|
it "closes the popover", ->
|
|
spyOn(@popover, "close")
|
|
@picker._onSelectCategory { usage: 0, category: "asdf" }
|
|
expect(@popover.close).toHaveBeenCalled()
|
|
|
|
describe "when selecting a category currently on all the selected items", ->
|
|
it "fires a task to remove the category", ->
|
|
input =
|
|
category: "asdf"
|
|
usage: 1
|
|
|
|
@picker._onSelectCategory(input)
|
|
expect(TaskFactory.taskForRemovingCategory).toHaveBeenCalledWith
|
|
threads: [@testThread]
|
|
category: "asdf"
|
|
expect(Actions.queueTask).toHaveBeenCalled()
|
|
|
|
describe "when selecting a category not on all the selected items", ->
|
|
it "fires a task to add the category", ->
|
|
input =
|
|
category: "asdf"
|
|
usage: 0
|
|
|
|
@picker._onSelectCategory(input)
|
|
expect(TaskFactory.taskForApplyingCategory).toHaveBeenCalledWith
|
|
threads: [@testThread]
|
|
category: "asdf"
|
|
expect(Actions.queueTask).toHaveBeenCalled()
|
|
|
|
describe "when selecting a new category", ->
|
|
beforeEach ->
|
|
@input =
|
|
newCategoryItem: true
|
|
@picker.setState(searchValue: "teSTing!")
|
|
|
|
it "queues a new syncback task for creating a category", ->
|
|
@picker._onSelectCategory(@input)
|
|
expect(Actions.queueTask).toHaveBeenCalled()
|
|
syncbackTask = Actions.queueTask.calls[0].args[0]
|
|
newCategory = syncbackTask.category
|
|
expect(newCategory instanceof @categoryClass).toBe(true)
|
|
expect(newCategory.displayName).toBe "teSTing!"
|
|
expect(newCategory.accountId).toBe TEST_ACCOUNT_ID
|
|
|
|
it "queues a task for applying the category after it has saved", ->
|
|
category = false
|
|
resolveSave = false
|
|
spyOn(TaskQueueStatusStore, "waitForPerformRemote").andCallFake (task) ->
|
|
expect(task instanceof SyncbackCategoryTask).toBe true
|
|
new Promise (resolve, reject) ->
|
|
resolveSave = resolve
|
|
|
|
spyOn(DatabaseStore, "findBy").andCallFake (klass, {clientId}) ->
|
|
expect(klass).toBe(Folder)
|
|
expect(typeof clientId).toBe("string")
|
|
Promise.resolve(category)
|
|
|
|
@picker._onSelectCategory(@input)
|
|
|
|
waitsFor ->
|
|
Actions.queueTask.callCount > 0
|
|
|
|
runs ->
|
|
category = Actions.queueTask.calls[0].args[0].category
|
|
resolveSave()
|
|
|
|
waitsFor ->
|
|
TaskFactory.taskForApplyingCategory.calls.length is 1
|
|
|
|
runs ->
|
|
expect(TaskFactory.taskForApplyingCategory).toHaveBeenCalledWith
|
|
threads: [@testThread]
|
|
category: category
|