Mailspring/internal_packages/composer-signature/spec/preferences-signatures-spec.jsx

91 lines
3.5 KiB
React
Raw Normal View History

refactor(signatures): Removed old signature imgs and made static empty signatures page Summary: Refactored signature preferences page to allow more signatures than the previous 1-1 mapping for signatures and accounts. Created a multi select dropdown of the accounts for which a certain signature is set as default for. Added a button into the draft header From field to toggle between saved signatures. refactor(signatures): Add basic add/remove capabilities to static refactor(signatures): Hooked up signature actions and signature store for basic functionality fix(signatures): Cleaned up signature store and started on multiselectdropdown fix(signatures): Add multi signature toggle select to multiselect dropdown build(signatures): Built framework for multiselect dropdown build(signatures): Toggle button functionality for dropdown build(signatures): Build multi select from components and add debounce refactor(signatures): Move signature actions and signature store into flux fix(signatures): Styled composer signatures button/dropdown and fixed preferences checkmarks build(signatures): Finish main functionality, about to refactor composer signature button into injected component fix(signatures): Changed position styles fix(signatures): Fixed background color for dropdown button when blurred build(signatures): Began to write tests for signatures store, preferences and dropdown Test Plan: Wrote tests for preferences signatures, signature store, signature composer dropdown and refactored tests for signature composer extension. For signature composer extension I removed applyTransformsToDraft and unapplyTransformsToDraft and tested by sending emails with signatures to different providers to make sure the <signature> tag caused problems. Reviewers: bengotow, juan Reviewed By: juan Differential Revision: https://phab.nylas.com/D3073
2016-07-12 03:28:37 +08:00
/* eslint quote-props: 0 */
import PreferencesSignatures from '../lib/preferences-signatures.jsx';
import ReactTestUtils from 'react-addons-test-utils';
import React from 'react';
import {SignatureStore, Actions} from 'nylas-exports';
const SIGNATURES = {
'1': {
id: '1',
title: 'one',
body: 'first test signature!',
},
'2': {
id: '2',
title: 'two',
body: 'Here is my second sig!',
},
}
const DEFAULTS = {
11: '1',
22: '2',
}
const makeComponent = (props = {}) => {
return ReactTestUtils.renderIntoDocument(<PreferencesSignatures {...props} />)
}
describe('PreferencesSignatures', function preferencesSignatures() {
this.component = null
describe('when there are no signatures', () => {
it('should add a signature when you click the button', () => {
spyOn(SignatureStore, 'getSignatures').andReturn({})
spyOn(SignatureStore, 'selectedSignature')
spyOn(SignatureStore, 'getDefaults').andReturn({})
this.component = makeComponent()
spyOn(Actions, 'addSignature')
this.button = ReactTestUtils.findRenderedDOMComponentWithClass(this.component, 'btn-create-signature')
ReactTestUtils.Simulate.mouseDown(this.button)
expect(Actions.addSignature).toHaveBeenCalled()
})
})
describe('when there are signatures', () => {
beforeEach(() => {
spyOn(SignatureStore, 'getSignatures').andReturn(SIGNATURES)
spyOn(SignatureStore, 'selectedSignature').andReturn(SIGNATURES['1'])
spyOn(SignatureStore, 'getDefaults').andReturn(DEFAULTS)
this.component = makeComponent()
})
it('should add a signature when you click the plus button', () => {
spyOn(Actions, 'addSignature')
this.plus = ReactTestUtils.scryRenderedDOMComponentsWithClass(this.component, 'btn-editable-list')[0]
ReactTestUtils.Simulate.click(this.plus)
expect(Actions.addSignature).toHaveBeenCalled()
})
it('should delete a signature when you click the minus button', () => {
spyOn(Actions, 'removeSignature')
this.minus = ReactTestUtils.scryRenderedDOMComponentsWithClass(this.component, 'btn-editable-list')[1]
ReactTestUtils.Simulate.click(this.minus)
expect(Actions.removeSignature).toHaveBeenCalledWith(SIGNATURES['1'])
})
it('should toggle default status when you click an email on the dropdown', () => {
spyOn(Actions, 'toggleAccount')
this.account = ReactTestUtils.scryRenderedDOMComponentsWithClass(this.component, 'item')[0]
ReactTestUtils.Simulate.mouseDown(this.account)
expect(Actions.toggleAccount).toHaveBeenCalledWith('test-account-server-id')
})
it('should set the selected signature when you click on one that is not currently selected', () => {
spyOn(Actions, 'selectSignature')
this.item = ReactTestUtils.scryRenderedDOMComponentsWithClass(this.component, 'list-item')[1]
ReactTestUtils.Simulate.click(this.item)
expect(Actions.selectSignature).toHaveBeenCalledWith('2')
})
it('should modify the signature body when edited', () => {
spyOn(Actions, 'updateSignature')
const newText = 'Changed <strong>NEW 1 HTML</strong><br>'
this.component._onEditSignature({target: {value: newText}});
expect(Actions.updateSignature).toHaveBeenCalled()
})
it('should modify the signature title when edited', () => {
spyOn(Actions, 'updateSignature')
const newTitle = 'Changed'
this.component._onEditSignature(newTitle)
expect(Actions.updateSignature).toHaveBeenCalled()
})
})
})