fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
|
|
|
require '../src/window'
|
|
|
|
atom.initialize()
|
|
|
|
atom.restoreWindowDimensions()
|
|
|
|
|
|
|
|
require 'jasmine-json'
|
|
|
|
require '../vendor/jasmine-jquery'
|
|
|
|
path = require 'path'
|
2015-05-20 07:06:59 +08:00
|
|
|
_ = require 'underscore'
|
|
|
|
_str = require 'underscore.string'
|
fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
|
|
|
fs = require 'fs-plus'
|
|
|
|
Grim = require 'grim'
|
|
|
|
KeymapManager = require '../src/keymap-extensions'
|
|
|
|
|
|
|
|
# FIXME: Remove jquery from this
|
|
|
|
{$} = require '../src/space-pen-extensions'
|
|
|
|
|
|
|
|
Config = require '../src/config'
|
|
|
|
ServiceHub = require 'service-hub'
|
|
|
|
pathwatcher = require 'pathwatcher'
|
|
|
|
clipboard = require 'clipboard'
|
|
|
|
|
2015-02-11 03:36:29 +08:00
|
|
|
NamespaceStore = require "../src/flux/stores/namespace-store"
|
|
|
|
Contact = require '../src/flux/models/contact'
|
2015-05-20 03:07:08 +08:00
|
|
|
{TaskQueue, ComponentRegistry} = require "nylas-exports"
|
2015-02-11 03:36:29 +08:00
|
|
|
|
fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
|
|
|
atom.themes.loadBaseStylesheets()
|
|
|
|
atom.themes.requireStylesheet '../static/jasmine'
|
|
|
|
atom.themes.initialLoadComplete = true
|
|
|
|
|
|
|
|
atom.keymaps.loadBundledKeymaps()
|
|
|
|
keyBindingsToRestore = atom.keymaps.getKeyBindings()
|
|
|
|
commandsToRestore = atom.commands.getSnapshot()
|
|
|
|
styleElementsToRestore = atom.styles.getSnapshot()
|
|
|
|
|
|
|
|
window.addEventListener 'core:close', -> window.close()
|
|
|
|
window.addEventListener 'beforeunload', ->
|
|
|
|
atom.storeWindowDimensions()
|
|
|
|
atom.saveSync()
|
|
|
|
$('html,body').css('overflow', 'auto')
|
|
|
|
|
|
|
|
# Allow document.title to be assigned in specs without screwing up spec window title
|
|
|
|
documentTitle = null
|
|
|
|
Object.defineProperty document, 'title',
|
|
|
|
get: -> documentTitle
|
|
|
|
set: (title) -> documentTitle = title
|
|
|
|
|
|
|
|
jasmine.getEnv().addEqualityTester(_.isEqual) # Use underscore's definition of equality for toEqual assertions
|
|
|
|
|
|
|
|
if process.env.JANKY_SHA1 and process.platform is 'win32'
|
|
|
|
jasmine.getEnv().defaultTimeoutInterval = 60000
|
|
|
|
else
|
|
|
|
jasmine.getEnv().defaultTimeoutInterval = 500
|
|
|
|
|
|
|
|
specPackageName = null
|
|
|
|
specPackagePath = null
|
|
|
|
isCoreSpec = false
|
|
|
|
|
|
|
|
{specDirectory, resourcePath} = atom.getLoadSettings()
|
|
|
|
|
|
|
|
if specDirectory
|
|
|
|
specPackagePath = path.resolve(specDirectory, '..')
|
|
|
|
try
|
|
|
|
specPackageName = JSON.parse(fs.readFileSync(path.join(specPackagePath, 'package.json')))?.name
|
|
|
|
|
|
|
|
isCoreSpec = specDirectory == fs.realpathSync(__dirname)
|
|
|
|
|
2015-02-19 06:09:46 +08:00
|
|
|
# Override React.addons.TestUtils.renderIntoDocument so that
|
|
|
|
# we can remove all the created elements after the test completes.
|
|
|
|
React = require "react/addons"
|
|
|
|
ReactTestUtils = React.addons.TestUtils
|
feat(unsafe-components): Wrap injected components, catch exceptions, clean up ComponentRegistry
Summary:
This diff gives the ComponentRegistry a cleaner, smaller API. Instead of querying by name, location or role,
it's now just location and role, and you can register components for one or more location and one or more
roles without assigning the entries in the registry separate names.
When you register with the ComponentRegistry, the syntax is also cleaner and uses the component's displayName
instead of requiring you to provide a name. You also provide the actual component when unregistering, ensuring
that you can't unregister someone else's component.
InjectedComponent and InjectedComponentSet now wrap their children in UnsafeComponent, which prevents
render/component lifecycle problems from propogating.
Existing components have been updated:
1. maxWidth / minWidth are now containerStyles.maxWidth/minWidth
2. displayName is now required to use the CR.
3. containerRequired = false can be provided to exempt a component from being wrapped in an UnsafeComponent.
This is useful because it's slightly faster and keeps DOM flat.
This diff also makes the "Show Component Regions" more awesome. It displays column regions, since they now
use the InjectedComponentSet, and also shows for InjectedComponent as well as InjectedComponentSet.
Change ComponentRegistry syntax, lots more work on safely wrapping items. See description.
Fix for inline flexbox scenarios (message actions)
Allow ~/.inbox/packages to be symlinked to a github repo
Test Plan: Run tests!
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1457
2015-05-01 07:10:15 +08:00
|
|
|
ReactTestUtils.scryRenderedComponentsWithTypeAndProps = (root, type, props) ->
|
2015-06-12 02:52:49 +08:00
|
|
|
if not root then throw new Error("Must supply a root to scryRenderedComponentsWithTypeAndProps")
|
feat(unsafe-components): Wrap injected components, catch exceptions, clean up ComponentRegistry
Summary:
This diff gives the ComponentRegistry a cleaner, smaller API. Instead of querying by name, location or role,
it's now just location and role, and you can register components for one or more location and one or more
roles without assigning the entries in the registry separate names.
When you register with the ComponentRegistry, the syntax is also cleaner and uses the component's displayName
instead of requiring you to provide a name. You also provide the actual component when unregistering, ensuring
that you can't unregister someone else's component.
InjectedComponent and InjectedComponentSet now wrap their children in UnsafeComponent, which prevents
render/component lifecycle problems from propogating.
Existing components have been updated:
1. maxWidth / minWidth are now containerStyles.maxWidth/minWidth
2. displayName is now required to use the CR.
3. containerRequired = false can be provided to exempt a component from being wrapped in an UnsafeComponent.
This is useful because it's slightly faster and keeps DOM flat.
This diff also makes the "Show Component Regions" more awesome. It displays column regions, since they now
use the InjectedComponentSet, and also shows for InjectedComponent as well as InjectedComponentSet.
Change ComponentRegistry syntax, lots more work on safely wrapping items. See description.
Fix for inline flexbox scenarios (message actions)
Allow ~/.inbox/packages to be symlinked to a github repo
Test Plan: Run tests!
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1457
2015-05-01 07:10:15 +08:00
|
|
|
_.compact _.map ReactTestUtils.scryRenderedComponentsWithType(root, type), (el) ->
|
|
|
|
if _.isEqual(_.pick(el.props, Object.keys(props)), props)
|
|
|
|
return el
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
|
2015-02-19 06:09:46 +08:00
|
|
|
ReactTestUtils.scryRenderedDOMComponentsWithAttr = (root, attrName, attrValue) ->
|
|
|
|
ReactTestUtils.findAllInRenderedTree root, (inst) ->
|
|
|
|
inst.props[attrName] and (!attrValue or inst.props[attrName] is attrValue)
|
|
|
|
|
|
|
|
ReactTestUtils.findRenderedDOMComponentWithAttr = (root, attrName, attrValue) ->
|
|
|
|
all = ReactTestUtils.scryRenderedDOMComponentsWithAttr(root, attrName, attrValue)
|
|
|
|
if all.length is not 1
|
|
|
|
throw new Error("Did not find exactly one match for data attribute: #{attrName} with value: #{attrValue}")
|
|
|
|
all[0]
|
|
|
|
|
|
|
|
ReactElementContainers = []
|
|
|
|
ReactTestUtils.renderIntoDocument = (element) ->
|
|
|
|
container = document.createElement('div')
|
|
|
|
ReactElementContainers.push(container)
|
|
|
|
React.render(element, container)
|
|
|
|
|
|
|
|
ReactTestUtils.unmountAll = ->
|
|
|
|
for container in ReactElementContainers
|
|
|
|
React.unmountComponentAtNode(container)
|
|
|
|
ReactElementContainers = []
|
|
|
|
|
feat(offline-mode, undo-redo): Tasks handle network errors better and retry, undo/redo based on tasks
Summary:
This diff does a couple things:
- Undo redo with a new undo/redo store that maintains it's own queue of undo/redo tasks. This queue is separate from the TaskQueue because not all tasks should be considered for undo history! Right now just the AddRemoveTagsTask is undoable.
- NylasAPI.makeRequest now returns a promise which resolves with the result or rejects with an error. For things that still need them, there's still `success` and `error` callbacks. I also added `started:(req) ->` which allows you to get the underlying request.
- Aborting a NylasAPI request now makes it call it's error callback / promise reject.
- You can now run code after perform local has completed using this syntax:
```
task = new AddRemoveTagsTask(focused, ['archive'], ['inbox'])
task.waitForPerformLocal().then ->
Actions.setFocus(collection: 'thread', item: nextFocus)
Actions.setCursorPosition(collection: 'thread', item: nextKeyboard)
Actions.queueTask(task)
```
- In specs, you can now use `advanceClock` to get through a Promise.then/catch/finally. Turns out it was using something low level and not using setTimeout(0).
- The TaskQueue uses promises better and defers a lot of the complexity around queueState for performLocal/performRemote to a task subclass called APITask. APITask implements "perform" and breaks it into "performLocal" and "performRemote".
- All tasks either resolve or reject. They're always removed from the queue, unless they resolve with Task.Status.Retry, which means they internally did a .catch (err) => Promise.resolve(Task.Status.Retry) and they want to be run again later.
- API tasks retry until they succeed or receive a NylasAPI.PermanentErrorCode (400,404,500), in which case they revert and finish.
- The AddRemoveTags Task can now take more than one thread! This is super cool because you can undo/redo a bulk action and also because we'll probably have a bulk tag modification API endpoint soon.
Getting undo / redo working revealed that the thread versioning system we built isn't working because the server was incrementing things by more than 1 at a time. Now we count the number of unresolved "optimistic" changes we've made to a given model, and only accept the server's version of it once the number of optimistic changes is back at zero.
Known Issues:
- AddRemoveTagsTasks aren't dependent on each other, so if you (undo/redo x lots) and then come back online, all the tasks try to add / remove all the tags at the same time. To fix this we can either allow the tasks to be merged together into a minimal set or make them block on each other.
- When Offline, you still get errors in the console for GET requests. Need to catch these and display an offline status bar.
- The metadata tasks haven't been updated yet to the new API. Wanted to get it reviewed first!
Test Plan: All the tests still pass!
Reviewers: evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D1694
2015-07-08 01:38:53 +08:00
|
|
|
# Make Bluebird use setTimeout so that it hooks into our stubs, and you can
|
|
|
|
# advance promises using `advanceClock()`. To avoid breaking any specs that
|
|
|
|
# `dont` manually call advanceClock, call it automatically on the next tick.
|
|
|
|
Promise.setScheduler (fn) ->
|
|
|
|
setTimeout(fn, 0)
|
|
|
|
process.nextTick -> advanceClock(1)
|
|
|
|
|
fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
|
|
|
beforeEach ->
|
|
|
|
Grim.clearDeprecations() if isCoreSpec
|
2015-02-19 06:09:46 +08:00
|
|
|
ComponentRegistry._clear()
|
2015-06-03 10:51:00 +08:00
|
|
|
global.localStorage.clear()
|
2015-02-19 06:09:46 +08:00
|
|
|
|
2015-05-20 03:07:08 +08:00
|
|
|
TaskQueue._queue = []
|
|
|
|
TaskQueue._completed = []
|
|
|
|
TaskQueue._onlineStatus = true
|
|
|
|
|
fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
|
|
|
$.fx.off = true
|
|
|
|
documentTitle = null
|
|
|
|
atom.packages.serviceHub = new ServiceHub
|
|
|
|
atom.keymaps.keyBindings = _.clone(keyBindingsToRestore)
|
|
|
|
atom.commands.restoreSnapshot(commandsToRestore)
|
|
|
|
atom.styles.restoreSnapshot(styleElementsToRestore)
|
|
|
|
atom.workspaceViewParentSelector = '#jasmine-content'
|
|
|
|
|
|
|
|
window.resetTimeouts()
|
|
|
|
spyOn(_._, "now").andCallFake -> window.now
|
|
|
|
spyOn(window, "setTimeout").andCallFake window.fakeSetTimeout
|
|
|
|
spyOn(window, "clearTimeout").andCallFake window.fakeClearTimeout
|
2015-05-20 06:59:37 +08:00
|
|
|
spyOn(window, "setInterval").andCallFake window.fakeSetInterval
|
|
|
|
spyOn(window, "clearInterval").andCallFake window.fakeClearInterval
|
fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
|
|
|
|
|
|
|
atom.packages.packageStates = {}
|
|
|
|
|
|
|
|
serializedWindowState = null
|
|
|
|
|
|
|
|
spyOn(atom, 'saveSync')
|
|
|
|
|
|
|
|
spy = spyOn(atom.packages, 'resolvePackagePath').andCallFake (packageName) ->
|
|
|
|
if specPackageName and packageName is specPackageName
|
|
|
|
resolvePackagePath(specPackagePath)
|
|
|
|
else
|
|
|
|
resolvePackagePath(packageName)
|
|
|
|
resolvePackagePath = _.bind(spy.originalValue, atom.packages)
|
|
|
|
|
|
|
|
# prevent specs from modifying Atom's menus
|
|
|
|
spyOn(atom.menu, 'sendToBrowserProcess')
|
|
|
|
|
2015-02-11 03:36:29 +08:00
|
|
|
# Log in a fake user
|
|
|
|
spyOn(NamespaceStore, 'current').andCallFake ->
|
2015-05-15 08:08:30 +08:00
|
|
|
emailAddress: 'tester@nylas.com'
|
2015-02-11 03:36:29 +08:00
|
|
|
id: 'nsid'
|
|
|
|
me: ->
|
2015-05-15 08:08:30 +08:00
|
|
|
new Contact(email: 'tester@nylas.com', name: 'Ben Tester')
|
2015-02-11 03:36:29 +08:00
|
|
|
|
fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
|
|
|
# reset config before each spec; don't load or save from/to `config.json`
|
|
|
|
spyOn(Config::, 'load')
|
|
|
|
spyOn(Config::, 'save')
|
|
|
|
config = new Config({resourcePath, configDirPath: atom.getConfigDirPath()})
|
|
|
|
atom.config = config
|
|
|
|
atom.loadConfig()
|
|
|
|
config.set "core.destroyEmptyPanes", false
|
|
|
|
config.set "editor.fontFamily", "Courier"
|
|
|
|
config.set "editor.fontSize", 16
|
|
|
|
config.set "editor.autoIndent", false
|
|
|
|
config.set "core.disabledPackages", ["package-that-throws-an-exception",
|
|
|
|
"package-with-broken-package-json", "package-with-broken-keymap"]
|
|
|
|
config.set "editor.useShadowDOM", true
|
|
|
|
advanceClock(1000)
|
|
|
|
window.setTimeout.reset()
|
|
|
|
config.load.reset()
|
|
|
|
config.save.reset()
|
|
|
|
|
|
|
|
spyOn(pathwatcher.File.prototype, "detectResurrectionAfterDelay").andCallFake -> @detectResurrection()
|
|
|
|
|
|
|
|
clipboardContent = 'initial clipboard content'
|
|
|
|
spyOn(clipboard, 'writeText').andCallFake (text) -> clipboardContent = text
|
|
|
|
spyOn(clipboard, 'readText').andCallFake -> clipboardContent
|
|
|
|
|
|
|
|
addCustomMatchers(this)
|
|
|
|
|
2015-06-16 09:29:59 +08:00
|
|
|
|
|
|
|
original_log = console.log
|
|
|
|
original_warn = console.warn
|
|
|
|
original_error = console.error
|
|
|
|
|
fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
|
|
|
afterEach ->
|
2015-06-16 09:29:59 +08:00
|
|
|
|
|
|
|
if console.log isnt original_log
|
|
|
|
console.log = original_log
|
|
|
|
if console.warn isnt original_warn
|
|
|
|
console.warn = original_warn
|
|
|
|
if console.error isnt original_error
|
|
|
|
console.error = original_error
|
|
|
|
|
fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
|
|
|
atom.packages.deactivatePackages()
|
|
|
|
atom.menu.template = []
|
2015-04-25 00:36:19 +08:00
|
|
|
|
fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
|
|
|
atom.themes.removeStylesheet('global-editor-styles')
|
|
|
|
|
2015-04-25 00:36:19 +08:00
|
|
|
delete atom.state?.packageStates
|
fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
|
|
|
|
|
|
|
$('#jasmine-content').empty() unless window.debugContent
|
|
|
|
|
2015-02-19 06:09:46 +08:00
|
|
|
ReactTestUtils.unmountAll()
|
|
|
|
|
fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
|
|
|
jasmine.unspy(atom, 'saveSync')
|
|
|
|
ensureNoPathSubscriptions()
|
|
|
|
waits(0) # yield to ui thread to make screen update more frequently
|
|
|
|
|
|
|
|
ensureNoPathSubscriptions = ->
|
|
|
|
watchedPaths = pathwatcher.getWatchedPaths()
|
|
|
|
pathwatcher.closeAllWatchers()
|
|
|
|
if watchedPaths.length > 0
|
|
|
|
throw new Error("Leaking subscriptions for paths: " + watchedPaths.join(", "))
|
|
|
|
|
|
|
|
ensureNoDeprecatedFunctionsCalled = ->
|
|
|
|
deprecations = Grim.getDeprecations()
|
|
|
|
if deprecations.length > 0
|
|
|
|
originalPrepareStackTrace = Error.prepareStackTrace
|
|
|
|
Error.prepareStackTrace = (error, stack) ->
|
|
|
|
output = []
|
|
|
|
for deprecation in deprecations
|
|
|
|
output.push "#{deprecation.originName} is deprecated. #{deprecation.message}"
|
2015-05-20 07:06:59 +08:00
|
|
|
output.push _str.repeat("-", output[output.length - 1].length)
|
fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
|
|
|
for stack in deprecation.getStacks()
|
|
|
|
for {functionName, location} in stack
|
|
|
|
output.push "#{functionName} -- #{location}"
|
|
|
|
output.push ""
|
|
|
|
output.join("\n")
|
|
|
|
|
|
|
|
error = new Error("Deprecated function(s) #{deprecations.map(({originName}) -> originName).join ', '}) were called.")
|
|
|
|
error.stack
|
|
|
|
Error.prepareStackTrace = originalPrepareStackTrace
|
|
|
|
|
|
|
|
throw error
|
|
|
|
|
|
|
|
emitObject = jasmine.StringPrettyPrinter.prototype.emitObject
|
|
|
|
jasmine.StringPrettyPrinter.prototype.emitObject = (obj) ->
|
|
|
|
if obj.inspect
|
|
|
|
@append obj.inspect()
|
|
|
|
else
|
|
|
|
emitObject.call(this, obj)
|
|
|
|
|
|
|
|
jasmine.unspy = (object, methodName) ->
|
|
|
|
throw new Error("Not a spy") unless object[methodName].hasOwnProperty('originalValue')
|
|
|
|
object[methodName] = object[methodName].originalValue
|
|
|
|
|
|
|
|
jasmine.attachToDOM = (element) ->
|
|
|
|
jasmineContent = document.querySelector('#jasmine-content')
|
|
|
|
jasmineContent.appendChild(element) unless jasmineContent.contains(element)
|
|
|
|
|
|
|
|
deprecationsSnapshot = null
|
|
|
|
jasmine.snapshotDeprecations = ->
|
|
|
|
deprecationsSnapshot = _.clone(Grim.deprecations)
|
|
|
|
|
|
|
|
jasmine.restoreDeprecationsSnapshot = ->
|
|
|
|
Grim.deprecations = deprecationsSnapshot
|
|
|
|
|
|
|
|
jasmine.useRealClock = ->
|
|
|
|
jasmine.unspy(window, 'setTimeout')
|
|
|
|
jasmine.unspy(window, 'clearTimeout')
|
feat(offline-mode, undo-redo): Tasks handle network errors better and retry, undo/redo based on tasks
Summary:
This diff does a couple things:
- Undo redo with a new undo/redo store that maintains it's own queue of undo/redo tasks. This queue is separate from the TaskQueue because not all tasks should be considered for undo history! Right now just the AddRemoveTagsTask is undoable.
- NylasAPI.makeRequest now returns a promise which resolves with the result or rejects with an error. For things that still need them, there's still `success` and `error` callbacks. I also added `started:(req) ->` which allows you to get the underlying request.
- Aborting a NylasAPI request now makes it call it's error callback / promise reject.
- You can now run code after perform local has completed using this syntax:
```
task = new AddRemoveTagsTask(focused, ['archive'], ['inbox'])
task.waitForPerformLocal().then ->
Actions.setFocus(collection: 'thread', item: nextFocus)
Actions.setCursorPosition(collection: 'thread', item: nextKeyboard)
Actions.queueTask(task)
```
- In specs, you can now use `advanceClock` to get through a Promise.then/catch/finally. Turns out it was using something low level and not using setTimeout(0).
- The TaskQueue uses promises better and defers a lot of the complexity around queueState for performLocal/performRemote to a task subclass called APITask. APITask implements "perform" and breaks it into "performLocal" and "performRemote".
- All tasks either resolve or reject. They're always removed from the queue, unless they resolve with Task.Status.Retry, which means they internally did a .catch (err) => Promise.resolve(Task.Status.Retry) and they want to be run again later.
- API tasks retry until they succeed or receive a NylasAPI.PermanentErrorCode (400,404,500), in which case they revert and finish.
- The AddRemoveTags Task can now take more than one thread! This is super cool because you can undo/redo a bulk action and also because we'll probably have a bulk tag modification API endpoint soon.
Getting undo / redo working revealed that the thread versioning system we built isn't working because the server was incrementing things by more than 1 at a time. Now we count the number of unresolved "optimistic" changes we've made to a given model, and only accept the server's version of it once the number of optimistic changes is back at zero.
Known Issues:
- AddRemoveTagsTasks aren't dependent on each other, so if you (undo/redo x lots) and then come back online, all the tasks try to add / remove all the tags at the same time. To fix this we can either allow the tasks to be merged together into a minimal set or make them block on each other.
- When Offline, you still get errors in the console for GET requests. Need to catch these and display an offline status bar.
- The metadata tasks haven't been updated yet to the new API. Wanted to get it reviewed first!
Test Plan: All the tests still pass!
Reviewers: evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D1694
2015-07-08 01:38:53 +08:00
|
|
|
jasmine.unspy(window, 'setInterval')
|
|
|
|
jasmine.unspy(window, 'clearInterval')
|
fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
|
|
|
jasmine.unspy(_._, 'now')
|
|
|
|
|
|
|
|
addCustomMatchers = (spec) ->
|
|
|
|
spec.addMatchers
|
|
|
|
toBeInstanceOf: (expected) ->
|
|
|
|
notText = if @isNot then " not" else ""
|
|
|
|
this.message = => "Expected #{jasmine.pp(@actual)} to#{notText} be instance of #{expected.name} class"
|
|
|
|
@actual instanceof expected
|
|
|
|
|
|
|
|
toHaveLength: (expected) ->
|
|
|
|
if not @actual?
|
|
|
|
this.message = => "Expected object #{@actual} has no length method"
|
|
|
|
false
|
|
|
|
else
|
|
|
|
notText = if @isNot then " not" else ""
|
|
|
|
this.message = => "Expected object with length #{@actual.length} to#{notText} have length #{expected}"
|
|
|
|
@actual.length == expected
|
|
|
|
|
|
|
|
toExistOnDisk: (expected) ->
|
|
|
|
notText = this.isNot and " not" or ""
|
|
|
|
@message = -> return "Expected path '" + @actual + "'" + notText + " to exist."
|
|
|
|
fs.existsSync(@actual)
|
|
|
|
|
|
|
|
toHaveFocus: ->
|
|
|
|
notText = this.isNot and " not" or ""
|
|
|
|
if not document.hasFocus()
|
|
|
|
console.error "Specs will fail because the Dev Tools have focus. To fix this close the Dev Tools or click the spec runner."
|
|
|
|
|
|
|
|
@message = -> return "Expected element '" + @actual + "' or its descendants" + notText + " to have focus."
|
|
|
|
element = @actual
|
|
|
|
element = element.get(0) if element.jquery
|
|
|
|
element is document.activeElement or element.contains(document.activeElement)
|
|
|
|
|
|
|
|
toShow: ->
|
|
|
|
notText = if @isNot then " not" else ""
|
|
|
|
element = @actual
|
|
|
|
element = element.get(0) if element.jquery
|
|
|
|
@message = -> return "Expected element '#{element}' or its descendants#{notText} to show."
|
|
|
|
element.style.display in ['block', 'inline-block', 'static', 'fixed']
|
|
|
|
|
|
|
|
window.keyIdentifierForKey = (key) ->
|
|
|
|
if key.length > 1 # named key
|
|
|
|
key
|
|
|
|
else
|
|
|
|
charCode = key.toUpperCase().charCodeAt(0)
|
|
|
|
"U+00" + charCode.toString(16)
|
|
|
|
|
|
|
|
window.keydownEvent = (key, properties={}) ->
|
|
|
|
originalEventProperties = {}
|
|
|
|
originalEventProperties.ctrl = properties.ctrlKey
|
|
|
|
originalEventProperties.alt = properties.altKey
|
|
|
|
originalEventProperties.shift = properties.shiftKey
|
|
|
|
originalEventProperties.cmd = properties.metaKey
|
|
|
|
originalEventProperties.target = properties.target?[0] ? properties.target
|
|
|
|
originalEventProperties.which = properties.which
|
|
|
|
originalEvent = KeymapManager.keydownEvent(key, originalEventProperties)
|
|
|
|
properties = $.extend({originalEvent}, properties)
|
|
|
|
$.Event("keydown", properties)
|
|
|
|
|
|
|
|
window.mouseEvent = (type, properties) ->
|
|
|
|
if properties.point
|
|
|
|
{point, editorView} = properties
|
|
|
|
{top, left} = @pagePixelPositionForPoint(editorView, point)
|
|
|
|
properties.pageX = left + 1
|
|
|
|
properties.pageY = top + 1
|
|
|
|
properties.originalEvent ?= {detail: 1}
|
|
|
|
$.Event type, properties
|
|
|
|
|
|
|
|
window.clickEvent = (properties={}) ->
|
|
|
|
window.mouseEvent("click", properties)
|
|
|
|
|
|
|
|
window.mousedownEvent = (properties={}) ->
|
|
|
|
window.mouseEvent('mousedown', properties)
|
|
|
|
|
|
|
|
window.mousemoveEvent = (properties={}) ->
|
|
|
|
window.mouseEvent('mousemove', properties)
|
|
|
|
|
|
|
|
# See docs/writing-specs.md
|
|
|
|
window.waitsForPromise = (args...) ->
|
|
|
|
if args.length > 1
|
|
|
|
{ shouldReject, timeout } = args[0]
|
|
|
|
else
|
|
|
|
shouldReject = false
|
|
|
|
fn = _.last(args)
|
|
|
|
|
|
|
|
window.waitsFor timeout, (moveOn) ->
|
|
|
|
promise = fn()
|
2015-06-03 10:51:00 +08:00
|
|
|
# Keep in mind we can't check `promise instanceof Promise` because parts of
|
|
|
|
# the app still use other Promise libraries (Atom used Q, we use Bluebird.)
|
|
|
|
# Just see if it looks promise-like.
|
|
|
|
if not promise or not promise.then
|
|
|
|
jasmine.getEnv().currentSpec.fail("Expected callback to return a promise-like object, but it returned #{promise}")
|
fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
|
|
|
moveOn()
|
|
|
|
else if shouldReject
|
|
|
|
promise.catch(moveOn)
|
|
|
|
promise.then ->
|
|
|
|
jasmine.getEnv().currentSpec.fail("Expected promise to be rejected, but it was resolved")
|
|
|
|
moveOn()
|
|
|
|
else
|
|
|
|
promise.then(moveOn)
|
|
|
|
promise.catch (error) ->
|
2015-03-26 03:41:48 +08:00
|
|
|
# I don't know what `pp` does, but for standard `new Error` objects,
|
|
|
|
# it sometimes returns "{ }". Catch this case and fall through to toString()
|
|
|
|
msg = jasmine.pp(error)
|
|
|
|
msg = error.toString() if msg is "{ }"
|
|
|
|
jasmine.getEnv().currentSpec.fail("Expected promise to be resolved, but it was rejected with #{msg}")
|
fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
|
|
|
moveOn()
|
|
|
|
|
|
|
|
window.resetTimeouts = ->
|
|
|
|
window.now = 0
|
|
|
|
window.timeoutCount = 0
|
|
|
|
window.intervalCount = 0
|
|
|
|
window.timeouts = []
|
|
|
|
window.intervalTimeouts = {}
|
|
|
|
|
|
|
|
window.fakeSetTimeout = (callback, ms) ->
|
|
|
|
id = ++window.timeoutCount
|
|
|
|
window.timeouts.push([id, window.now + ms, callback])
|
|
|
|
id
|
|
|
|
|
|
|
|
window.fakeClearTimeout = (idToClear) ->
|
|
|
|
window.timeouts = window.timeouts.filter ([id]) -> id != idToClear
|
|
|
|
|
|
|
|
window.fakeSetInterval = (callback, ms) ->
|
|
|
|
id = ++window.intervalCount
|
|
|
|
action = ->
|
|
|
|
callback()
|
|
|
|
window.intervalTimeouts[id] = window.fakeSetTimeout(action, ms)
|
|
|
|
window.intervalTimeouts[id] = window.fakeSetTimeout(action, ms)
|
|
|
|
id
|
|
|
|
|
|
|
|
window.fakeClearInterval = (idToClear) ->
|
|
|
|
window.fakeClearTimeout(@intervalTimeouts[idToClear])
|
|
|
|
|
|
|
|
window.advanceClock = (delta=1) ->
|
|
|
|
window.now += delta
|
|
|
|
callbacks = []
|
|
|
|
|
|
|
|
window.timeouts = window.timeouts.filter ([id, strikeTime, callback]) ->
|
|
|
|
if strikeTime <= window.now
|
|
|
|
callbacks.push(callback)
|
|
|
|
false
|
|
|
|
else
|
|
|
|
true
|
|
|
|
|
|
|
|
callback() for callback in callbacks
|
|
|
|
|
|
|
|
window.pagePixelPositionForPoint = (editorView, point) ->
|
|
|
|
point = Point.fromObject point
|
|
|
|
top = editorView.renderedLines.offset().top + point.row * editorView.lineHeight
|
|
|
|
left = editorView.renderedLines.offset().left + point.column * editorView.charWidth - editorView.renderedLines.scrollLeft()
|
|
|
|
{ top, left }
|
|
|
|
|
|
|
|
window.tokensText = (tokens) ->
|
|
|
|
_.pluck(tokens, 'value').join('')
|
|
|
|
|
|
|
|
window.setEditorWidthInChars = (editorView, widthInChars, charWidth=editorView.charWidth) ->
|
|
|
|
editorView.width(charWidth * widthInChars + editorView.gutter.outerWidth())
|
|
|
|
$(window).trigger 'resize' # update width of editor view's on-screen lines
|
|
|
|
|
|
|
|
window.setEditorHeightInLines = (editorView, heightInLines, lineHeight=editorView.lineHeight) ->
|
|
|
|
editorView.height(editorView.getEditor().getLineHeightInPixels() * heightInLines)
|
|
|
|
editorView.component?.measureHeightAndWidth()
|
|
|
|
|
|
|
|
$.fn.resultOfTrigger = (type) ->
|
|
|
|
event = $.Event(type)
|
|
|
|
this.trigger(event)
|
|
|
|
event.result
|
|
|
|
|
|
|
|
$.fn.enableKeymap = ->
|
|
|
|
@on 'keydown', (e) ->
|
|
|
|
originalEvent = e.originalEvent ? e
|
|
|
|
Object.defineProperty(originalEvent, 'target', get: -> e.target) unless originalEvent.target?
|
|
|
|
atom.keymaps.handleKeyboardEvent(originalEvent)
|
|
|
|
not e.originalEvent.defaultPrevented
|
|
|
|
|
|
|
|
$.fn.attachToDom = ->
|
|
|
|
@appendTo($('#jasmine-content')) unless @isOnDom()
|
|
|
|
|
|
|
|
$.fn.simulateDomAttachment = ->
|
|
|
|
$('<html>').append(this)
|
|
|
|
|
|
|
|
$.fn.textInput = (data) ->
|
|
|
|
this.each ->
|
|
|
|
event = document.createEvent('TextEvent')
|
|
|
|
event.initTextEvent('textInput', true, true, window, data)
|
|
|
|
event = $.event.fix(event)
|
|
|
|
$(this).trigger(event)
|