mirror of
https://github.com/Foundry376/Mailspring.git
synced 2026-02-28 03:26:08 +08:00
fix(specs): attribute conversion fixed bugs, broke specs
This commit is contained in:
parent
c6d8bde6fd
commit
ec5092c2f5
7 changed files with 24 additions and 19 deletions
|
|
@ -103,7 +103,6 @@ class ThemeOption extends React.Component {
|
|||
frameBorder="0"
|
||||
width="115px"
|
||||
height="70px"
|
||||
flex="1"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -69,11 +69,11 @@ describe "DatabaseStore", ->
|
|||
# Actually returns correct sets for queries, since matchers can evaluate
|
||||
# themselves against models in memory
|
||||
spyOn(DatabaseStore, 'run').andCallFake (query) =>
|
||||
results = []
|
||||
for model in @models
|
||||
found = _.every query._matchers, (matcher) ->
|
||||
results = @models.filter((model) ->
|
||||
query._matchers.every((matcher) ->
|
||||
matcher.evaluate(model)
|
||||
results.push(model) if found
|
||||
)
|
||||
)
|
||||
Promise.resolve(results)
|
||||
|
||||
describe "when given an array or input that is not an array", ->
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ CategoryStore = require '../../src/flux/stores/category-store'
|
|||
AccountStore = require '../../src/flux/stores/account-store'
|
||||
FocusedPerspectiveStore = require '../../src/flux/stores/focused-perspective-store'
|
||||
|
||||
fdescribe "FocusedPerspectiveStore", ->
|
||||
describe "FocusedPerspectiveStore", ->
|
||||
beforeEach ->
|
||||
spyOn(FocusedPerspectiveStore, 'trigger')
|
||||
FocusedPerspectiveStore._perspective = null
|
||||
|
|
|
|||
|
|
@ -76,10 +76,10 @@ describe('SendDraftTask', function sendDraftTask() {
|
|||
from: [new Contact({email: TEST_ACCOUNT_EMAIL})],
|
||||
subject: 'New Draft',
|
||||
body: 'hello world',
|
||||
to: {
|
||||
to: [new Contact({
|
||||
name: 'Dummy',
|
||||
email: 'dummythis.nylas.com',
|
||||
},
|
||||
})],
|
||||
};
|
||||
|
||||
spyOn(NylasAPI, 'makeRequest').andCallFake((options) => {
|
||||
|
|
@ -489,10 +489,10 @@ describe('SendDraftTask', function sendDraftTask() {
|
|||
subject: 'New Draft',
|
||||
draft: true,
|
||||
body: 'hello world',
|
||||
to: {
|
||||
to: [new Contact({
|
||||
name: 'Dummy',
|
||||
email: 'dummythis.nylas.com',
|
||||
},
|
||||
})],
|
||||
uploads: [],
|
||||
});
|
||||
|
||||
|
|
@ -543,10 +543,10 @@ describe('SendDraftTask', function sendDraftTask() {
|
|||
subject: 'New Draft',
|
||||
draft: true,
|
||||
body: 'hello world',
|
||||
to: {
|
||||
to: [new Contact({
|
||||
name: 'Dummy',
|
||||
email: 'dummythis.nylas.com',
|
||||
},
|
||||
})],
|
||||
uploads: [],
|
||||
});
|
||||
this.task.draft.applyPluginMetadata('open-tracking', true);
|
||||
|
|
|
|||
|
|
@ -38,9 +38,9 @@ describe 'Utils', ->
|
|||
expect(revived).toEqual([@testThread])
|
||||
|
||||
it "should re-inflate Models in places they're not explicitly declared types", ->
|
||||
b = new JSONBlob({id: "local-ThreadsToProcess", json: [@testThread]})
|
||||
b = new JSONBlob({id: "ThreadsToProcess", json: [@testThread]})
|
||||
jsonString = JSON.stringify(b, Utils.registeredObjectReplacer)
|
||||
expectedString = '{"client_id":"local-ThreadsToProcess","server_id":"local-ThreadsToProcess","json":[{"client_id":"local-1","account_id":"1","metadata":[],"subject":"Test 1234","participants":[{"client_id":"local-a","account_id":"1","name":"Juan","email":"juan@nylas.com","thirdPartyData":{},"id":"local-a"},{"client_id":"local-b","account_id":"1","name":"Ben","email":"ben@nylas.com","thirdPartyData":{},"id":"local-b"}],"in_all_mail":true,"id":"local-1","__constructorName":"Thread"}],"id":"local-ThreadsToProcess","__constructorName":"JSONBlob"}'
|
||||
expectedString = '{"client_id":"ThreadsToProcess","server_id":"ThreadsToProcess","json":[{"client_id":"local-1","account_id":"1","metadata":[],"subject":"Test 1234","participants":[{"client_id":"local-a","account_id":"1","name":"Juan","email":"juan@nylas.com","thirdPartyData":{},"id":"local-a"},{"client_id":"local-b","account_id":"1","name":"Ben","email":"ben@nylas.com","thirdPartyData":{},"id":"local-b"}],"in_all_mail":true,"id":"local-1","__constructorName":"Thread"}],"id":"ThreadsToProcess","__constructorName":"JSONBlob"}'
|
||||
|
||||
expect(jsonString).toEqual(expectedString)
|
||||
revived = JSON.parse(jsonString, Utils.registeredObjectReviver)
|
||||
|
|
|
|||
|
|
@ -38,14 +38,20 @@ export default class AttributeCollection extends Attribute {
|
|||
}
|
||||
|
||||
toJSON(vals) {
|
||||
if (!vals) { return []; }
|
||||
if (!vals) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!(vals instanceof Array)) {
|
||||
throw new Error(`AttributeCollection::toJSON: ${this.modelKey} is not an array.`);
|
||||
}
|
||||
|
||||
const json = []
|
||||
for (const val of vals) {
|
||||
if (!(val instanceof this.ItemClass)) {
|
||||
throw new Error(`AttributeCollection::toJSON: Value \`${val}\` in ${this.modelKey} is not an ${this.ItemClass.name}`);
|
||||
}
|
||||
if (val.toJSON) {
|
||||
if (val.toJSON !== undefined) {
|
||||
json.push(val.toJSON());
|
||||
} else {
|
||||
json.push(val);
|
||||
|
|
@ -58,7 +64,7 @@ export default class AttributeCollection extends Attribute {
|
|||
if (!json || !(json instanceof Array)) {
|
||||
return [];
|
||||
}
|
||||
const objs = []
|
||||
const objs = [];
|
||||
|
||||
for (const objJSON of json) {
|
||||
// Note: It's possible for a malformed API request to return an array
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ class Matcher {
|
|||
case '>=':
|
||||
return modelValue >= matcherValue
|
||||
case 'in':
|
||||
return modelValue in matcherValue
|
||||
return matcherValue.includes(modelValue)
|
||||
case 'contains':
|
||||
return modelArrayContainsValue(modelValue, matcherValue)
|
||||
case 'containsAny':
|
||||
|
|
@ -98,7 +98,7 @@ class Matcher {
|
|||
case 'startsWith':
|
||||
return modelValue.startsWith(matcherValue)
|
||||
case 'like':
|
||||
return modelValue.search(new RegExp(".*${matcherValue}.*", "gi")) >= 0
|
||||
return modelValue.search(new RegExp(`.*${matcherValue}.*`, "gi")) >= 0
|
||||
default:
|
||||
throw new Error(`Matcher.evaulate() not sure how to evaluate ${this.attr.modelKey} with comparator ${this.comparator}`)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue