Remove use of abstract base class Category in specs

This commit is contained in:
Ben Gotow 2017-06-28 23:48:45 -07:00
parent f7f345baf9
commit 232bff4cbc
11 changed files with 75 additions and 75 deletions

View file

@ -1,10 +1,10 @@
import {Category, Actions} from "nylas-exports"
import {Folder, Actions} from "nylas-exports"
import SidebarItem from "../lib/sidebar-item"
describe("sidebar-item", function sidebarItemSpec() {
it("preserves nested labels on rename", () => {
spyOn(Actions, "queueTask")
const categories = [new Category({displayName: 'a.b/c', accountId: window.TEST_ACCOUNT_ID})]
const categories = [new Folder({displayName: 'a.b/c', accountId: window.TEST_ACCOUNT_ID})]
NylasEnv.savedState.sidebarKeysCollapsed = {}
const item = SidebarItem.forCategories(categories)
item.onEdited(item, 'd')
@ -13,7 +13,7 @@ describe("sidebar-item", function sidebarItemSpec() {
})
it("preserves labels on rename", () => {
spyOn(Actions, "queueTask")
const categories = [new Category({displayName: 'a', accountId: window.TEST_ACCOUNT_ID})]
const categories = [new Folder({displayName: 'a', accountId: window.TEST_ACCOUNT_ID})]
NylasEnv.savedState.sidebarKeysCollapsed = {}
const item = SidebarItem.forCategories(categories)
item.onEdited(item, 'b')

View file

@ -4,7 +4,7 @@ import {
NylasAPIHelpers,
Thread,
Actions,
Category,
Folder,
} from 'nylas-exports'
import SnoozeUtils from '../lib/snooze-utils'
import SnoozeStore from '../lib/snooze-store'
@ -17,12 +17,12 @@ xdescribe('SnoozeStore', function snoozeStore() {
this.accounts = [{id: 123}, {id: 321}]
this.snoozeCatsByAccount = {
123: new Category({accountId: 123, displayName: this.name, id: 'sn-1'}),
321: new Category({accountId: 321, displayName: this.name, id: 'sn-2'}),
123: new Folder({accountId: 123, displayName: this.name, id: 'sn-1'}),
321: new Folder({accountId: 321, displayName: this.name, id: 'sn-2'}),
}
this.inboxCatsByAccount = {
123: new Category({accountId: 123, name: 'inbox', id: 'in-1'}),
321: new Category({accountId: 321, name: 'inbox', id: 'in-2'}),
123: new Folder({accountId: 123, name: 'inbox', id: 'in-1'}),
321: new Folder({accountId: 321, name: 'inbox', id: 'in-2'}),
}
this.threads = [
new Thread({accountId: 123, id: 's-1'}),

View file

@ -4,7 +4,7 @@ import {
TaskQueue,
TaskFactory,
DatabaseStore,
Category,
Folder,
Thread,
CategoryStore,
FolderSyncProgressStore,
@ -60,7 +60,7 @@ xdescribe('Snooze Utils', function snoozeUtils() {
describe('createSnoozeCategory', () => {
beforeEach(() => {
this.category = new Category({
this.category = new Folder({
displayName: this.name,
accountId: this.accId,
id: 321,
@ -122,8 +122,8 @@ xdescribe('Snooze Utils', function snoozeUtils() {
describe('getSnoozeCategory', () => {
it('resolves category if it exists in the category store', () => {
const categories = [
new Category({accountId: this.accId, name: 'inbox'}),
new Category({accountId: this.accId, displayName: this.name}),
new Folder({accountId: this.accId, name: 'inbox'}),
new Folder({accountId: this.accId, displayName: this.name}),
]
spyOn(CategoryStore, 'categories').andReturn(categories)
spyOn(SnoozeUtils, 'createSnoozeCategory')
@ -139,9 +139,9 @@ xdescribe('Snooze Utils', function snoozeUtils() {
it('creates category if it does not exist', () => {
const categories = [
new Category({accountId: this.accId, name: 'inbox'}),
new Folder({accountId: this.accId, name: 'inbox'}),
]
const snoozeCat = new Category({accountId: this.accId, displayName: this.name})
const snoozeCat = new Folder({accountId: this.accId, displayName: this.name})
spyOn(CategoryStore, 'categories').andReturn(categories)
spyOn(SnoozeUtils, 'createSnoozeCategory').andReturn(Promise.resolve(snoozeCat))
@ -159,12 +159,12 @@ xdescribe('Snooze Utils', function snoozeUtils() {
beforeEach(() => {
this.description = 'Snoozin';
this.snoozeCatsByAccount = {
123: new Category({accountId: 123, displayName: this.name, id: 'sr-1'}),
321: new Category({accountId: 321, displayName: this.name, id: 'sr-2'}),
123: new Folder({accountId: 123, displayName: this.name, id: 'sr-1'}),
321: new Folder({accountId: 321, displayName: this.name, id: 'sr-2'}),
}
this.inboxCatsByAccount = {
123: new Category({accountId: 123, name: 'inbox', id: 'sr-3'}),
321: new Category({accountId: 321, name: 'inbox', id: 'sr-4'}),
123: new Folder({accountId: 123, name: 'inbox', id: 'sr-3'}),
321: new Folder({accountId: 321, name: 'inbox', id: 'sr-4'}),
}
this.threads = [
new Thread({accountId: 123}),

View file

@ -1,7 +1,7 @@
import Contact from '../../../src/flux/models/contact'
import Message from '../../../src/flux/models/message'
import Thread from '../../../src/flux/models/thread'
import Category from '../../../src/flux/models/category'
import Folder from '../../../src/flux/models/category'
import CategoryStore from '../../../src/flux/stores/category-store'
import DatabaseStore from '../../../src/flux/stores/database-store'
import AccountStore from '../../../src/flux/stores/account-store'
@ -13,8 +13,8 @@ xdescribe("UnreadNotifications", function UnreadNotifications() {
beforeEach(() => {
this.notifier = new Notifier();
const inbox = new Category({id: "l1", name: "inbox", displayName: "Inbox"})
const archive = new Category({id: "l2", name: "archive", displayName: "Archive"})
const inbox = new Folder({id: "l1", name: "inbox", displayName: "Inbox"})
const archive = new Folder({id: "l2", name: "archive", displayName: "Archive"})
spyOn(CategoryStore, "getCategoryByRole").andReturn(inbox);

View file

@ -2,7 +2,7 @@ import {
AccountStore,
MailboxPerspective,
TaskFactory,
Category,
Label,
CategoryStore,
} from 'nylas-exports'
@ -112,16 +112,16 @@ describe('MailboxPerspective', function mailboxPerspective() {
beforeEach(() => {
this.categories = {
a1: {
archive: new Category({name: 'archive', displayName: 'archive', accountId: 'a1'}),
inbox: new Category({name: 'inbox', displayName: 'inbox1', accountId: 'a1'}),
trash: new Category({name: 'trash', displayName: 'trash1', accountId: 'a1'}),
category: new Category({name: null, displayName: 'folder1', accountId: 'a1'}),
archive: new Label({name: 'archive', displayName: 'archive', accountId: 'a1'}),
inbox: new Label({name: 'inbox', displayName: 'inbox1', accountId: 'a1'}),
trash: new Label({name: 'trash', displayName: 'trash1', accountId: 'a1'}),
category: new Label({name: null, displayName: 'folder1', accountId: 'a1'}),
},
a2: {
archive: new Category({name: 'all', displayName: 'all', accountId: 'a2'}),
inbox: new Category({name: 'inbox', displayName: 'inbox2', accountId: 'a2'}),
trash: new Category({name: 'trash', displayName: 'trash2', accountId: 'a2'}),
category: new Category({name: null, displayName: 'label2', accountId: 'a2'}),
archive: new Label({name: 'all', displayName: 'all', accountId: 'a2'}),
inbox: new Label({name: 'inbox', displayName: 'inbox2', accountId: 'a2'}),
trash: new Label({name: 'trash', displayName: 'trash2', accountId: 'a2'}),
category: new Label({name: null, displayName: 'label2', accountId: 'a2'}),
},
}
this.threads = [
@ -197,8 +197,8 @@ describe('MailboxPerspective', function mailboxPerspective() {
it('does nothing when viewing spam or sent', () => {
['spam', 'sent'].forEach((invalid) => {
const perspective = MailboxPerspective.forCategories([
new Category({name: invalid, accountId: 'a1'}),
new Category({name: invalid, accountId: 'a2'}),
new Label({name: invalid, accountId: 'a1'}),
new Label({name: invalid, accountId: 'a2'}),
])
const tasks = perspective.tasksForRemovingItems(this.threads)
expect(TaskFactory.tasksForApplyingCategories).not.toHaveBeenCalled()
@ -221,9 +221,9 @@ describe('MailboxPerspective', function mailboxPerspective() {
describe('CategoryMailboxPerspective', () => {
beforeEach(() => {
this.categories = [
new Category({displayName: 'c1', accountId: 'a1'}),
new Category({displayName: 'c2', accountId: 'a2'}),
new Category({displayName: 'c3', accountId: 'a2'}),
new Label({displayName: 'c1', accountId: 'a1'}),
new Label({displayName: 'c2', accountId: 'a2'}),
new Label({displayName: 'c3', accountId: 'a2'}),
]
this.perspective = MailboxPerspective.forCategories(this.categories)
});
@ -241,7 +241,7 @@ describe('MailboxPerspective', function mailboxPerspective() {
it('returns false if it is a locked category', () => {
this.perspective._categories.push(
new Category({role: 'sent', path: 'c4', accountId: 'a1'})
new Label({role: 'sent', path: 'c4', accountId: 'a1'})
)
expect(this.perspective.canReceiveThreadsFromAccountIds(['a2'])).toBe(false)
});

View file

@ -1,4 +1,4 @@
{Category, Label} = require 'nylas-exports'
{Folder, Label} = require 'nylas-exports'
describe 'Category', ->
@ -6,8 +6,8 @@ describe 'Category', ->
it 'returns the name if all the categories on the perspective have the same role', ->
expect(Category.categoriesSharedRole([
new Category({path: 'c1', role: 'c1', accountId: 'a1'}),
new Category({path: 'c1', role: 'c1', accountId: 'a2'}),
new Folder({path: 'c1', role: 'c1', accountId: 'a1'}),
new Folder({path: 'c1', role: 'c1', accountId: 'a2'}),
])).toEqual('c1')
it 'returns null if there are no categories', ->
@ -15,15 +15,15 @@ describe 'Category', ->
it 'returns null if the categories have different roles', ->
expect(Category.categoriesSharedRole([
new Category({path: 'c1', role: 'c1', accountId: 'a1'}),
new Category({path: 'c2', role: 'c2', accountId: 'a2'}),
new Folder({path: 'c1', role: 'c1', accountId: 'a1'}),
new Folder({path: 'c2', role: 'c2', accountId: 'a2'}),
])).toEqual(null)
describe 'displayName', ->
it "should strip the INBOX. prefix from FastMail folders", ->
foo = new Category({path: 'INBOX.Foo'})
foo = new Folder({path: 'INBOX.Foo'})
expect(foo.displayName).toEqual('Foo')
foo = new Category({path: 'INBOX'})
foo = new Folder({path: 'INBOX'})
expect(foo.displayName).toEqual('Inbox')
describe 'category types', ->

View file

@ -1,6 +1,6 @@
Message = require('../../src/flux/models/message').default
Thread = require('../../src/flux/models/thread').default
Category = require('../../src/flux/models/category').default
Folder = require('../../src/flux/models/folder').default
{Utils} = require 'nylas-exports'
_ = require 'underscore'
@ -23,7 +23,7 @@ describe 'Thread', ->
describe 'sortedCategories', ->
sortedForCategoryNames = (inputs) ->
categories = inputs.map((i) ->
new Category(path: i, role: i)
new Folder(path: i, role: i)
)
thread = new Thread(labels: categories, folders: [])
return thread.sortedCategories()

View file

@ -1,5 +1,5 @@
/* eslint dot-notation:0 */
import Category from '../../src/flux/models/category';
import Folder from '../../src/flux/models/folder';
import TestModel from '../fixtures/db-test-model';
import DatabaseWriter from '../../src/flux/stores/database-writer';
@ -77,7 +77,7 @@ xdescribe("DatabaseWriter", function DatabaseWriterSpecs() {
});
it("should throw an exception if the models are not the same class, since it cannot be specified by the trigger payload", () =>
expect(() => this.transaction.persistModels([testModelInstanceA, new Category()])).toThrow()
expect(() => this.transaction.persistModels([testModelInstanceA, new Folder()])).toThrow()
);
it("should throw an exception if the models are not a subclass of Model", () =>
@ -217,7 +217,7 @@ xdescribe("DatabaseWriter", function DatabaseWriterSpecs() {
.then(() => {
expect(this.performed.length).toBe(4);
expect(this.performed[0].query).toBe("BEGIN IMMEDIATE TRANSACTION");
expect(this.performed[2].query).toBe("DELETE FROM `TestModelCategory` WHERE `id` = ?");
expect(this.performed[2].query).toBe("DELETE FROM `TestModelFolder` WHERE `id` = ?");
expect(this.performed[2].values[0]).toBe('1234');
expect(this.performed[3].query).toBe("COMMIT");
});
@ -291,16 +291,16 @@ xdescribe("DatabaseWriter", function DatabaseWriterSpecs() {
beforeEach(() => {
TestModel.configureWithCollectionAttribute();
this.m = new TestModel({id: 'local-6806434c-b0cd', other: 'other'});
this.m.categories = [new Category({id: 'a'}), new Category({id: 'b'})];
this.m.categories = [new Folder({id: 'a'}), new Folder({id: 'b'})];
this.transaction._writeModels([this.m]);
});
it("should delete all association records for the model from join tables", () => {
expect(this.performed[1].query).toBe('DELETE FROM `TestModelCategory` WHERE `id` IN (\'local-6806434c-b0cd\')');
expect(this.performed[1].query).toBe('DELETE FROM `TestModelFolder` WHERE `id` IN (\'local-6806434c-b0cd\')');
});
it("should insert new association records into join tables in a single query, and include queryableBy columns", () => {
expect(this.performed[2].query).toBe('INSERT OR IGNORE INTO `TestModelCategory` (`id`,`value`,`other`) VALUES (?,?,?),(?,?,?)');
expect(this.performed[2].query).toBe('INSERT OR IGNORE INTO `TestModelFolder` (`id`,`value`,`other`) VALUES (?,?,?),(?,?,?)');
expect(this.performed[2].values).toEqual(['local-6806434c-b0cd', 'a', 'other', 'local-6806434c-b0cd', 'b', 'other']);
});
});
@ -316,11 +316,11 @@ xdescribe("DatabaseWriter", function DatabaseWriterSpecs() {
const iterable = __range__(0, 199, true);
for (let j = 0; j < iterable.length; j++) {
const i = iterable[j];
this.m.categories.push(new Category({id: `id-${i}`}));
this.m.categories.push(new Folder({id: `id-${i}`}));
}
this.transaction._writeModels([this.m]);
const collectionAttributeQueries = this.performed.filter(i => i.query.indexOf('INSERT OR IGNORE INTO `TestModelCategory`') === 0
const collectionAttributeQueries = this.performed.filter(i => i.query.indexOf('INSERT OR IGNORE INTO `TestModelFolder`') === 0
);
expect(collectionAttributeQueries.length).toBe(1);
@ -331,11 +331,11 @@ xdescribe("DatabaseWriter", function DatabaseWriterSpecs() {
const iterable = __range__(0, 200, true);
for (let j = 0; j < iterable.length; j++) {
const i = iterable[j];
this.m.categories.push(new Category({id: `id-${i}`}));
this.m.categories.push(new Folder({id: `id-${i}`}));
}
this.transaction._writeModels([this.m]);
const collectionAttributeQueries = this.performed.filter(i => i.query.indexOf('INSERT OR IGNORE INTO `TestModelCategory`') === 0
const collectionAttributeQueries = this.performed.filter(i => i.query.indexOf('INSERT OR IGNORE INTO `TestModelFolder`') === 0
);
expect(collectionAttributeQueries.length).toBe(2);
@ -347,11 +347,11 @@ xdescribe("DatabaseWriter", function DatabaseWriterSpecs() {
const iterable = __range__(0, 201, true);
for (let j = 0; j < iterable.length; j++) {
const i = iterable[j];
this.m.categories.push(new Category({id: `id-${i}`}));
this.m.categories.push(new Folder({id: `id-${i}`}));
}
this.transaction._writeModels([this.m]);
const collectionAttributeQueries = this.performed.filter(i => i.query.indexOf('INSERT OR IGNORE INTO `TestModelCategory`') === 0
const collectionAttributeQueries = this.performed.filter(i => i.query.indexOf('INSERT OR IGNORE INTO `TestModelFolder`') === 0
);
expect(collectionAttributeQueries.length).toBe(2);

View file

@ -1,7 +1,7 @@
_ = require 'underscore'
Actions = require('../../src/flux/actions').default
Category = require('../../src/flux/models/category').default
Folder = require('../../src/flux/models/folder').default
MailboxPerspective = require '../../src/mailbox-perspective'
CategoryStore = require '../../src/flux/stores/category-store'
@ -14,9 +14,9 @@ describe "FocusedPerspectiveStore", ->
FocusedPerspectiveStore._current = MailboxPerspective.forNothing()
@account = AccountStore.accounts()[0]
@inboxCategory = new Category(id: 'id-123', name: 'inbox', displayName: "INBOX", accountId: @account.id)
@inboxCategory = new Folder(id: 'id-123', name: 'inbox', displayName: "INBOX", accountId: @account.id)
@inboxPerspective = MailboxPerspective.forCategory(@inboxCategory)
@userCategory = new Category(id: 'id-456', name: null, displayName: "MyCategory", accountId: @account.id)
@userCategory = new Folder(id: 'id-456', name: null, displayName: "MyCategory", accountId: @account.id)
@userPerspective = MailboxPerspective.forCategory(@userCategory)
spyOn(CategoryStore, "getCategoryByRole").andReturn @inboxCategory

View file

@ -1,6 +1,6 @@
_ = require 'underscore'
Thread = require('../../src/flux/models/thread').default
Category = require('../../src/flux/models/category').default
Label = require('../../src/flux/models/label').default
Message = require('../../src/flux/models/message').default
FocusedContentStore = require '../../src/flux/stores/focused-content-store'
FocusedPerspectiveStore = require('../../src/flux/stores/focused-perspective-store').default
@ -59,9 +59,9 @@ describe "MessageStore", ->
beforeEach ->
MessageStore._showingHiddenItems = false
MessageStore._items = [
new Message(categories: [new Category(displayName: 'bla'), new Category(name: 'trash')]),
new Message(categories: [new Category(name: 'inbox')]),
new Message(categories: [new Category(name: 'bla'), new Category(name: 'spam')]),
new Message(categories: [new Label(displayName: 'bla'), new Label(name: 'trash')]),
new Message(categories: [new Label(name: 'inbox')]),
new Message(categories: [new Label(name: 'bla'), new Label(name: 'spam')]),
new Message(categories: []),
new Message(categories: [], draft: true),
]

View file

@ -2,7 +2,7 @@ import {
TaskFactory,
AccountStore,
CategoryStore,
Category,
Label,
Thread,
ChangeFolderTask,
ChangeLabelsTask,
@ -13,14 +13,14 @@ describe('TaskFactory', function taskFactory() {
beforeEach(() => {
this.categories = {
'ac-1': {
archive: new Category({name: 'archive'}),
inbox: new Category({name: 'inbox1'}),
trash: new Category({name: 'trash1'}),
archive: new Label({name: 'archive'}),
inbox: new Label({name: 'inbox1'}),
trash: new Label({name: 'trash1'}),
},
'ac-2': {
archive: new Category({name: 'all'}),
inbox: new Category({name: 'inbox2'}),
trash: new Category({name: 'trash2'}),
archive: new Label({name: 'all'}),
inbox: new Label({name: 'inbox2'}),
trash: new Label({name: 'trash2'}),
},
}
this.accounts = {
@ -59,9 +59,9 @@ describe('TaskFactory', function taskFactory() {
it('creates the correct tasks', () => {
const categoriesToRemove = (accId) => {
if (accId === 'ac-1') {
return [new Category({displayName: 'folder1', accountId: 'ac-1'})]
return [new Label({displayName: 'folder1', accountId: 'ac-1'})]
}
return [new Category({displayName: 'label2', accountId: 'ac-2'})]
return [new Label({displayName: 'label2', accountId: 'ac-2'})]
}
const categoriesToAdd = (accId) => [this.categories[accId].inbox]
const taskDescription = 'dope'
@ -120,9 +120,9 @@ describe('TaskFactory', function taskFactory() {
it('does not create folder tasks if categoriesToAdd not present', () => {
const categoriesToRemove = (accId) => {
if (accId === 'ac-1') {
return [new Category({displayName: 'folder1', accountId: 'ac-1'})]
return [new Label({displayName: 'folder1', accountId: 'ac-1'})]
}
return [new Category({displayName: 'label2', accountId: 'ac-2'})]
return [new Label({displayName: 'label2', accountId: 'ac-2'})]
}
const taskDescription = 'dope'