2016-07-12 03:28:37 +08:00
|
|
|
/* eslint quote-props: 0 */
|
|
|
|
import {SignatureStore} from 'nylas-exports'
|
|
|
|
|
|
|
|
let SIGNATURES = {
|
|
|
|
'1': {
|
|
|
|
id: '1',
|
|
|
|
title: 'one',
|
|
|
|
body: 'first test signature!',
|
|
|
|
},
|
|
|
|
'2': {
|
|
|
|
id: '2',
|
|
|
|
title: 'two',
|
|
|
|
body: 'Here is my second sig!',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const DEFAULTS = {
|
2016-07-22 02:18:21 +08:00
|
|
|
'one@nylas.com': '2',
|
|
|
|
'two@nylas.com': '2',
|
|
|
|
'three@nylas.com': null,
|
2016-07-12 03:28:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('SignatureStore', function signatureStore() {
|
|
|
|
beforeEach(() => {
|
2016-07-29 05:54:37 +08:00
|
|
|
spyOn(NylasEnv.config, 'get').andCallFake((key) => (key === 'nylas.signatures' ? SIGNATURES : null))
|
2016-07-12 03:28:37 +08:00
|
|
|
|
|
|
|
spyOn(SignatureStore, '_saveSignatures').andCallFake(() => {
|
|
|
|
NylasEnv.config.set(`nylas.signatures`, SignatureStore.signatures)
|
|
|
|
})
|
2016-07-22 02:18:21 +08:00
|
|
|
spyOn(SignatureStore, 'signatureForEmail').andCallFake((email) => SIGNATURES[DEFAULTS[email]])
|
2016-07-12 03:28:37 +08:00
|
|
|
spyOn(SignatureStore, 'selectedSignature').andCallFake(() => SIGNATURES['1'])
|
|
|
|
SignatureStore.activate()
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
describe('signatureForAccountId', () => {
|
|
|
|
it('should return the default signature for that account', () => {
|
2016-07-22 02:18:21 +08:00
|
|
|
const titleForAccount1 = SignatureStore.signatureForEmail('one@nylas.com').title
|
|
|
|
expect(titleForAccount1).toEqual(SIGNATURES['2'].title)
|
|
|
|
const account2Def = SignatureStore.signatureForEmail('three@nylas.com')
|
|
|
|
expect(account2Def).toEqual(undefined)
|
2016-07-12 03:28:37 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('removeSignature', () => {
|
|
|
|
beforeEach(() => {
|
2016-07-29 05:54:37 +08:00
|
|
|
spyOn(NylasEnv.config, 'set').andCallFake((key, newObject) => {
|
|
|
|
if (key === 'nylas.signatures') {
|
|
|
|
SIGNATURES = newObject;
|
|
|
|
}
|
2016-07-12 03:28:37 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
it('should remove the signature from our list of signatures', () => {
|
|
|
|
const toRemove = SIGNATURES[SignatureStore.selectedSignatureId]
|
|
|
|
SignatureStore._onRemoveSignature(toRemove)
|
|
|
|
expect(SIGNATURES['1']).toEqual(undefined)
|
|
|
|
})
|
|
|
|
it('should reset selectedSignatureId to a different signature', () => {
|
|
|
|
const toRemove = SIGNATURES[SignatureStore.selectedSignatureId]
|
|
|
|
SignatureStore._onRemoveSignature(toRemove)
|
|
|
|
expect(SignatureStore.selectedSignatureId).toNotEqual('1')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|