mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-01 10:33:14 +08:00
feat(babel6): Yay all the tests pass
This commit is contained in:
parent
2e906d4e16
commit
e054a6ac91
2 changed files with 20 additions and 33 deletions
|
@ -1,20 +1,15 @@
|
||||||
import _ from 'underscore';
|
import _ from 'underscore';
|
||||||
import {Actions, NylasAPI, AccountStore, CategoryStore} from 'nylas-exports';
|
import {Actions, NylasAPI, AccountStore, CategoryStore} from 'nylas-exports';
|
||||||
import {
|
import SnoozeUtils from './snooze-utils'
|
||||||
moveThreadsToSnooze,
|
|
||||||
moveThreadsFromSnooze,
|
|
||||||
getSnoozeCategoriesByAccount,
|
|
||||||
} from './snooze-utils';
|
|
||||||
import {PLUGIN_ID, PLUGIN_NAME} from './snooze-constants';
|
import {PLUGIN_ID, PLUGIN_NAME} from './snooze-constants';
|
||||||
import SnoozeActions from './snooze-actions';
|
import SnoozeActions from './snooze-actions';
|
||||||
|
|
||||||
|
|
||||||
class SnoozeStore {
|
class SnoozeStore {
|
||||||
|
|
||||||
constructor(pluginId = PLUGIN_ID, pluginName = PLUGIN_NAME) {
|
constructor(pluginId = PLUGIN_ID, pluginName = PLUGIN_NAME) {
|
||||||
this.pluginId = pluginId
|
this.pluginId = pluginId
|
||||||
this.pluginName = pluginName
|
this.pluginName = pluginName
|
||||||
this.snoozeCategoriesPromise = getSnoozeCategoriesByAccount(AccountStore.accounts())
|
this.snoozeCategoriesPromise = SnoozeUtils.getSnoozeCategoriesByAccount(AccountStore.accounts())
|
||||||
}
|
}
|
||||||
|
|
||||||
activate() {
|
activate() {
|
||||||
|
@ -58,7 +53,7 @@ class SnoozeStore {
|
||||||
};
|
};
|
||||||
|
|
||||||
onAccountsChanged = ()=> {
|
onAccountsChanged = ()=> {
|
||||||
this.snoozeCategoriesPromise = getSnoozeCategoriesByAccount(AccountStore.accounts())
|
this.snoozeCategoriesPromise = SnoozeUtils.getSnoozeCategoriesByAccount(AccountStore.accounts())
|
||||||
};
|
};
|
||||||
|
|
||||||
onSnoozeThreads = (threads, snoozeDate, label) => {
|
onSnoozeThreads = (threads, snoozeDate, label) => {
|
||||||
|
@ -70,7 +65,7 @@ class SnoozeStore {
|
||||||
})
|
})
|
||||||
return Promise.all(promises)
|
return Promise.all(promises)
|
||||||
.then(()=> {
|
.then(()=> {
|
||||||
return moveThreadsToSnooze(threads, this.snoozeCategoriesPromise, snoozeDate)
|
return SnoozeUtils.moveThreadsToSnooze(threads, this.snoozeCategoriesPromise, snoozeDate)
|
||||||
})
|
})
|
||||||
.then((updatedThreads)=> {
|
.then((updatedThreads)=> {
|
||||||
return this.snoozeCategoriesPromise
|
return this.snoozeCategoriesPromise
|
||||||
|
@ -83,7 +78,7 @@ class SnoozeStore {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch((error)=> {
|
.catch((error)=> {
|
||||||
moveThreadsFromSnooze(threads, this.snoozeCategoriesPromise)
|
SnoozeUtils.moveThreadsFromSnooze(threads, this.snoozeCategoriesPromise)
|
||||||
Actions.closePopover();
|
Actions.closePopover();
|
||||||
NylasEnv.reportError(error);
|
NylasEnv.reportError(error);
|
||||||
NylasEnv.showErrorDialog(`Sorry, we were unable to save your snooze settings. ${error.message}`);
|
NylasEnv.showErrorDialog(`Sorry, we were unable to save your snooze settings. ${error.message}`);
|
||||||
|
|
|
@ -10,14 +10,6 @@ import {
|
||||||
} from 'nylas-exports'
|
} from 'nylas-exports'
|
||||||
import SnoozeUtils from '../lib/snooze-utils'
|
import SnoozeUtils from '../lib/snooze-utils'
|
||||||
|
|
||||||
const {
|
|
||||||
snoozedUntilMessage,
|
|
||||||
createSnoozeCategory,
|
|
||||||
getSnoozeCategory,
|
|
||||||
moveThreads,
|
|
||||||
} = SnoozeUtils
|
|
||||||
|
|
||||||
|
|
||||||
describe('Snooze Utils', function snoozeUtils() {
|
describe('Snooze Utils', function snoozeUtils() {
|
||||||
beforeEach(()=> {
|
beforeEach(()=> {
|
||||||
this.name = 'Snoozed Folder'
|
this.name = 'Snoozed Folder'
|
||||||
|
@ -27,21 +19,21 @@ describe('Snooze Utils', function snoozeUtils() {
|
||||||
|
|
||||||
describe('snoozedUntilMessage', ()=> {
|
describe('snoozedUntilMessage', ()=> {
|
||||||
it('returns correct message if no snooze date provided', ()=> {
|
it('returns correct message if no snooze date provided', ()=> {
|
||||||
expect(snoozedUntilMessage()).toEqual('Snoozed')
|
expect(SnoozeUtils.snoozedUntilMessage()).toEqual('Snoozed')
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when less than 24 hours from now', ()=> {
|
describe('when less than 24 hours from now', ()=> {
|
||||||
it('returns correct message if snoozeDate is on the hour of the clock', ()=> {
|
it('returns correct message if snoozeDate is on the hour of the clock', ()=> {
|
||||||
const now9AM = moment().hour(9).minute(0)
|
const now9AM = moment().hour(9).minute(0)
|
||||||
const tomorrowAt8 = moment(now9AM).add(1, 'day').hour(8)
|
const tomorrowAt8 = moment(now9AM).add(1, 'day').hour(8)
|
||||||
const result = snoozedUntilMessage(tomorrowAt8, now9AM)
|
const result = SnoozeUtils.snoozedUntilMessage(tomorrowAt8, now9AM)
|
||||||
expect(result).toEqual('Snoozed until 8 AM')
|
expect(result).toEqual('Snoozed until 8 AM')
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns correct message if snoozeDate otherwise', ()=> {
|
it('returns correct message if snoozeDate otherwise', ()=> {
|
||||||
const now9AM = moment().hour(9).minute(0)
|
const now9AM = moment().hour(9).minute(0)
|
||||||
const snooze10AM = moment(now9AM).hour(10).minute(5)
|
const snooze10AM = moment(now9AM).hour(10).minute(5)
|
||||||
const result = snoozedUntilMessage(snooze10AM, now9AM)
|
const result = SnoozeUtils.snoozedUntilMessage(snooze10AM, now9AM)
|
||||||
expect(result).toEqual('Snoozed until 10:05 AM')
|
expect(result).toEqual('Snoozed until 10:05 AM')
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -51,7 +43,7 @@ describe('Snooze Utils', function snoozeUtils() {
|
||||||
// Jan 1
|
// Jan 1
|
||||||
const now9AM = moment().month(0).date(1).hour(9).minute(0)
|
const now9AM = moment().month(0).date(1).hour(9).minute(0)
|
||||||
const tomorrowAt10 = moment(now9AM).add(1, 'day').hour(10)
|
const tomorrowAt10 = moment(now9AM).add(1, 'day').hour(10)
|
||||||
const result = snoozedUntilMessage(tomorrowAt10, now9AM)
|
const result = SnoozeUtils.snoozedUntilMessage(tomorrowAt10, now9AM)
|
||||||
expect(result).toEqual('Snoozed until Jan 2, 10 AM')
|
expect(result).toEqual('Snoozed until Jan 2, 10 AM')
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -59,7 +51,7 @@ describe('Snooze Utils', function snoozeUtils() {
|
||||||
// Jan 1
|
// Jan 1
|
||||||
const now9AM = moment().month(0).date(1).hour(9).minute(0)
|
const now9AM = moment().month(0).date(1).hour(9).minute(0)
|
||||||
const tomorrowAt930 = moment(now9AM).add(1, 'day').minute(30)
|
const tomorrowAt930 = moment(now9AM).add(1, 'day').minute(30)
|
||||||
const result = snoozedUntilMessage(tomorrowAt930, now9AM)
|
const result = SnoozeUtils.snoozedUntilMessage(tomorrowAt930, now9AM)
|
||||||
expect(result).toEqual('Snoozed until Jan 2, 9:30 AM')
|
expect(result).toEqual('Snoozed until Jan 2, 9:30 AM')
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -79,7 +71,7 @@ describe('Snooze Utils', function snoozeUtils() {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('creates category with correct snooze name', ()=> {
|
it('creates category with correct snooze name', ()=> {
|
||||||
createSnoozeCategory(this.accId, this.name)
|
SnoozeUtils.createSnoozeCategory(this.accId, this.name)
|
||||||
expect(Actions.queueTask).toHaveBeenCalled()
|
expect(Actions.queueTask).toHaveBeenCalled()
|
||||||
const task = Actions.queueTask.calls[0].args[0]
|
const task = Actions.queueTask.calls[0].args[0]
|
||||||
expect(task.category.displayName).toEqual(this.name)
|
expect(task.category.displayName).toEqual(this.name)
|
||||||
|
@ -88,7 +80,7 @@ describe('Snooze Utils', function snoozeUtils() {
|
||||||
|
|
||||||
it('resolves with the updated category that has been saved to the server', ()=> {
|
it('resolves with the updated category that has been saved to the server', ()=> {
|
||||||
waitsForPromise(()=> {
|
waitsForPromise(()=> {
|
||||||
return createSnoozeCategory(this.accId, this.name).then((result)=> {
|
return SnoozeUtils.createSnoozeCategory(this.accId, this.name).then((result)=> {
|
||||||
expect(DatabaseStore.findBy).toHaveBeenCalled()
|
expect(DatabaseStore.findBy).toHaveBeenCalled()
|
||||||
expect(result).toBe(this.category)
|
expect(result).toBe(this.category)
|
||||||
})
|
})
|
||||||
|
@ -100,9 +92,9 @@ describe('Snooze Utils', function snoozeUtils() {
|
||||||
jasmine.unspy(DatabaseStore, 'findBy')
|
jasmine.unspy(DatabaseStore, 'findBy')
|
||||||
spyOn(DatabaseStore, 'findBy').andReturn(Promise.resolve(this.category))
|
spyOn(DatabaseStore, 'findBy').andReturn(Promise.resolve(this.category))
|
||||||
waitsForPromise(()=> {
|
waitsForPromise(()=> {
|
||||||
return createSnoozeCategory(this.accId, this.name)
|
return SnoozeUtils.createSnoozeCategory(this.accId, this.name)
|
||||||
.then(()=> {
|
.then(()=> {
|
||||||
throw new Error('createSnoozeCategory should not resolve in this case!')
|
throw new Error('SnoozeUtils.createSnoozeCategory should not resolve in this case!')
|
||||||
})
|
})
|
||||||
.catch((error)=> {
|
.catch((error)=> {
|
||||||
expect(DatabaseStore.findBy).toHaveBeenCalled()
|
expect(DatabaseStore.findBy).toHaveBeenCalled()
|
||||||
|
@ -115,9 +107,9 @@ describe('Snooze Utils', function snoozeUtils() {
|
||||||
jasmine.unspy(DatabaseStore, 'findBy')
|
jasmine.unspy(DatabaseStore, 'findBy')
|
||||||
spyOn(DatabaseStore, 'findBy').andReturn(Promise.resolve(undefined))
|
spyOn(DatabaseStore, 'findBy').andReturn(Promise.resolve(undefined))
|
||||||
waitsForPromise(()=> {
|
waitsForPromise(()=> {
|
||||||
return createSnoozeCategory(this.accId, this.name)
|
return SnoozeUtils.createSnoozeCategory(this.accId, this.name)
|
||||||
.then(()=> {
|
.then(()=> {
|
||||||
throw new Error('createSnoozeCategory should not resolve in this case!')
|
throw new Error('SnoozeUtils.createSnoozeCategory should not resolve in this case!')
|
||||||
})
|
})
|
||||||
.catch((error)=> {
|
.catch((error)=> {
|
||||||
expect(DatabaseStore.findBy).toHaveBeenCalled()
|
expect(DatabaseStore.findBy).toHaveBeenCalled()
|
||||||
|
@ -137,7 +129,7 @@ describe('Snooze Utils', function snoozeUtils() {
|
||||||
spyOn(SnoozeUtils, 'createSnoozeCategory')
|
spyOn(SnoozeUtils, 'createSnoozeCategory')
|
||||||
|
|
||||||
waitsForPromise(()=> {
|
waitsForPromise(()=> {
|
||||||
return getSnoozeCategory(this.accountId, this.name)
|
return SnoozeUtils.getSnoozeCategory(this.accountId, this.name)
|
||||||
.then((result)=> {
|
.then((result)=> {
|
||||||
expect(SnoozeUtils.createSnoozeCategory).not.toHaveBeenCalled()
|
expect(SnoozeUtils.createSnoozeCategory).not.toHaveBeenCalled()
|
||||||
expect(result).toBe(categories[1])
|
expect(result).toBe(categories[1])
|
||||||
|
@ -154,7 +146,7 @@ describe('Snooze Utils', function snoozeUtils() {
|
||||||
spyOn(SnoozeUtils, 'createSnoozeCategory').andReturn(Promise.resolve(snoozeCat))
|
spyOn(SnoozeUtils, 'createSnoozeCategory').andReturn(Promise.resolve(snoozeCat))
|
||||||
|
|
||||||
waitsForPromise(()=> {
|
waitsForPromise(()=> {
|
||||||
return getSnoozeCategory(this.accId, this.name)
|
return SnoozeUtils.getSnoozeCategory(this.accId, this.name)
|
||||||
.then((result)=> {
|
.then((result)=> {
|
||||||
expect(SnoozeUtils.createSnoozeCategory).toHaveBeenCalledWith(this.accId, this.name)
|
expect(SnoozeUtils.createSnoozeCategory).toHaveBeenCalledWith(this.accId, this.name)
|
||||||
expect(result).toBe(snoozeCat)
|
expect(result).toBe(snoozeCat)
|
||||||
|
@ -193,7 +185,7 @@ describe('Snooze Utils', function snoozeUtils() {
|
||||||
const description = this.description
|
const description = this.description
|
||||||
|
|
||||||
waitsForPromise(()=> {
|
waitsForPromise(()=> {
|
||||||
return moveThreads(this.threads, {snooze, description, getInboxCategory: this.getInboxCat, getSnoozeCategory: this.getSnoozeCat})
|
return SnoozeUtils.moveThreads(this.threads, {snooze, description, getInboxCategory: this.getInboxCat, getSnoozeCategory: this.getSnoozeCat})
|
||||||
.then(()=> {
|
.then(()=> {
|
||||||
expect(TaskFactory.tasksForApplyingCategories).toHaveBeenCalled()
|
expect(TaskFactory.tasksForApplyingCategories).toHaveBeenCalled()
|
||||||
expect(Actions.queueTasks).toHaveBeenCalled()
|
expect(Actions.queueTasks).toHaveBeenCalled()
|
||||||
|
@ -213,7 +205,7 @@ describe('Snooze Utils', function snoozeUtils() {
|
||||||
const description = this.description
|
const description = this.description
|
||||||
|
|
||||||
waitsForPromise(()=> {
|
waitsForPromise(()=> {
|
||||||
return moveThreads(this.threads, {snooze, description, getInboxCategory: this.getInboxCat, getSnoozeCategory: this.getSnoozeCat})
|
return SnoozeUtils.moveThreads(this.threads, {snooze, description, getInboxCategory: this.getInboxCat, getSnoozeCategory: this.getSnoozeCat})
|
||||||
.then(()=> {
|
.then(()=> {
|
||||||
expect(TaskFactory.tasksForApplyingCategories).toHaveBeenCalled()
|
expect(TaskFactory.tasksForApplyingCategories).toHaveBeenCalled()
|
||||||
expect(Actions.queueTasks).toHaveBeenCalled()
|
expect(Actions.queueTasks).toHaveBeenCalled()
|
||||||
|
|
Loading…
Reference in a new issue