Mailspring/internal_packages/composer-signature/spec/signature-composer-dropdown-spec.jsx

59 lines
2.6 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 React from 'react';
import ReactTestUtils from 'react-addons-test-utils'
import {SignatureStore} from 'nylas-exports';
2016-10-18 08:59:33 +08:00
import SignatureComposerDropdown from '../lib/signature-composer-dropdown'
import {renderIntoDocument} from '../../../spec/nylas-test-utils'
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
const SIGNATURES = {
'1': {
id: '1',
title: 'one',
body: 'first test signature!',
},
'2': {
id: '2',
title: 'two',
body: 'Here is my second sig!',
},
}
describe('SignatureComposerDropdown', function signatureComposerDropdown() {
beforeEach(() => {
spyOn(SignatureStore, 'getSignatures').andReturn(SIGNATURES)
spyOn(SignatureStore, 'selectedSignature')
this.session = {
changes: {
add: jasmine.createSpy('add'),
},
}
this.draft = {
body: "draft body",
}
this.button = renderIntoDocument(<SignatureComposerDropdown draft={this.draft} session={this.session} />)
})
describe('the button dropdown', () => {
it('calls add signature with the correct signature', () => {
const sigToAdd = SIGNATURES['2']
ReactTestUtils.Simulate.click(ReactTestUtils.findRenderedDOMComponentWithClass(this.button, 'only-item'))
this.signature = ReactTestUtils.findRenderedDOMComponentWithClass(this.button, `signature-title-${sigToAdd.title}`)
ReactTestUtils.Simulate.mouseDown(this.signature)
expect(this.button.props.session.changes.add).toHaveBeenCalledWith({body: `${this.button.props.draft.body}<br><br><signature>${sigToAdd.body}</signature>`})
})
it('calls add signature with nothing when no signature is clicked and there is no current signature', () => {
ReactTestUtils.Simulate.click(ReactTestUtils.findRenderedDOMComponentWithClass(this.button, 'only-item'))
this.noSignature = ReactTestUtils.findRenderedDOMComponentWithClass(this.button, 'item-none')
ReactTestUtils.Simulate.mouseDown(this.noSignature)
expect(this.button.props.session.changes.add).toHaveBeenCalledWith({body: `${this.button.props.draft.body}<br><br><signature></signature>`})
})
it('finds and removes the signature when no signature is clicked and there is a current signature', () => {
this.draft = 'draft body<signature>Remove me</signature>'
ReactTestUtils.Simulate.click(ReactTestUtils.findRenderedDOMComponentWithClass(this.button, 'only-item'))
this.noSignature = ReactTestUtils.findRenderedDOMComponentWithClass(this.button, 'item-none')
ReactTestUtils.Simulate.mouseDown(this.noSignature)
expect(this.button.props.session.changes.add).toHaveBeenCalledWith({body: `${this.button.props.draft.body}<br><br><signature></signature>`})
})
})
})