Mailspring/spec/services/inline-style-transformer-spec.coffee
Ben Gotow b00e5439e5 feat(paste): Paste accepts more HTML, paste and match style now available
Summary:
Related to #320, #494, #515, #553

Ignore newlines and returns in HTML, they can be inside tags

Allow all attributes so that paste from excel looks nice

Never let someone paste a `contenteditable` attribute

Update specs

Test Plan: Run new specs

Reviewers: juan, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D2309
2015-12-07 15:34:03 -08:00

67 lines
2.4 KiB
CoffeeScript

InlineStyleTransformer = require '../../src/services/inline-style-transformer'
{ipcRenderer} = require 'electron'
describe "InlineStyleTransformer", ->
describe "run", ->
beforeEach ->
spyOn(ipcRenderer, 'send')
spyOn(InlineStyleTransformer, '_injectUserAgentStyles').andCallFake (input) =>
return input
InlineStyleTransformer._inlineStylePromises = {}
it "should return a Promise", ->
expect(InlineStyleTransformer.run("asd") instanceof Promise).toBe(true)
it "should resolve immediately if the html is empty", ->
result = InlineStyleTransformer.run("")
expect(result.isResolved()).toBe(true)
it "should resolve immediately if there is no <style> tag in the source", ->
result = InlineStyleTransformer.run("""
This is some tricky HTML but there's no style tag here!
<I wonder if it'll get into trouble < style >. <Ohmgerd.>
""")
expect(result.isResolved()).toBe(true)
it "should properly remove comment tags used to prevent style tags from being displayed when they're not understood", ->
result = InlineStyleTransformer.run("""
<style>
<!--table
{mso-displayed-decimal-separator:"\.";
mso-displayed-thousand-separator:"\,";}
-->
</style>
<style><!--table
{mso-displayed-decimal-separator:"\.";
mso-displayed-thousand-separator:"\,";}
--></style>
""")
expect(ipcRenderer.send.mostRecentCall.args[1].html).toEqual("""
<style>table
{mso-displayed-decimal-separator:".";
mso-displayed-thousand-separator:",";}
</style>
<style>table
{mso-displayed-decimal-separator:".";
mso-displayed-thousand-separator:",";}
</style>
""")
it "should add user agent styles", ->
InlineStyleTransformer.run("""<style>
<!--table
{mso-displayed-decimal-separator:"\.";
mso-displayed-thousand-separator:"\,";}
-->
</style>Other content goes here""")
expect(InlineStyleTransformer._injectUserAgentStyles).toHaveBeenCalled()
it "should fire inline-style-parse to the main process", ->
InlineStyleTransformer.run("""<style>
<!--table
{mso-displayed-decimal-separator:"\.";
mso-displayed-thousand-separator:"\,";}
-->
</style>Other content goes here""")
expect(ipcRenderer.send).toHaveBeenCalled()
expect(ipcRenderer.send.mostRecentCall.args[0]).toEqual('inline-style-parse')