Mailspring/app/spec/services/inline-style-transformer-spec.es6

75 lines
2.6 KiB
Text
Raw Normal View History

2017-09-27 02:33:08 +08:00
import { ipcRenderer } from 'electron';
2017-08-27 06:13:34 +08:00
import InlineStyleTransformer from '../../src/services/inline-style-transformer';
2017-09-27 02:33:08 +08:00
describe('InlineStyleTransformer', function specs() {
describe('run', () => {
2017-08-27 06:13:34 +08:00
beforeEach(() => {
2017-09-27 02:33:08 +08:00
spyOn(ipcRenderer, 'send');
spyOn(InlineStyleTransformer, '_injectUserAgentStyles').andCallFake(input => input);
2017-08-27 06:13:34 +08:00
InlineStyleTransformer._inlineStylePromises = {};
});
2017-09-27 02:33:08 +08:00
it('should return a Promise', () => {
expect(InlineStyleTransformer.run('asd') instanceof Promise).toBe(true);
2017-08-27 06:13:34 +08:00
});
2017-09-27 02:33:08 +08:00
it('should resolve immediately if the html is empty', async () => {
const promise = InlineStyleTransformer.run('');
expect(await promise.isResolved()).toBe(true);
2017-08-27 06:13:34 +08:00
});
2017-09-27 02:33:08 +08:00
it('should resolve immediately if there is no <style> tag in the source', async () => {
2017-08-27 06:13:34 +08:00
const promise = InlineStyleTransformer.run(`
This is some tricky HTML but there's no style tag here!
<I wonder if it'll get into trouble < style >. <Ohmgerd.>
2017-09-27 02:33:08 +08:00
`);
expect(await promise.isResolved()).toBe(true);
2017-08-27 06:13:34 +08:00
});
it("should properly remove comment tags used to prevent style tags from being displayed when they're not understood", () => {
InlineStyleTransformer.run(`
<style>
<!--table
{mso-displayed-decimal-separator:".";
mso-displayed-thousand-separator:",";}
-->
</style>
<style><!--table
{mso-displayed-decimal-separator:".";
mso-displayed-thousand-separator:",";}
--></style>
2017-09-27 02:33:08 +08:00
`);
2017-08-27 06:13:34 +08:00
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>
2017-09-27 02:33:08 +08:00
`);
2017-08-27 06:13:34 +08:00
});
2017-09-27 02:33:08 +08:00
it('should add user agent styles', () => {
2017-08-27 06:13:34 +08:00
InlineStyleTransformer.run(`<style>
<!--table
{mso-displayed-decimal-separator:".";
mso-displayed-thousand-separator:",";}
-->
2017-09-27 02:33:08 +08:00
</style>Other content goes here`);
expect(InlineStyleTransformer._injectUserAgentStyles).toHaveBeenCalled();
2017-08-27 06:13:34 +08:00
});
2017-09-27 02:33:08 +08:00
it('should fire inline-style-parse to the main process', () => {
2017-08-27 06:13:34 +08:00
InlineStyleTransformer.run(`<style>
<!--table
{mso-displayed-decimal-separator:".";
mso-displayed-thousand-separator:",";}
-->
2017-09-27 02:33:08 +08:00
</style>Other content goes here`);
expect(ipcRenderer.send).toHaveBeenCalled();
2017-08-27 06:13:34 +08:00
expect(ipcRenderer.send.mostRecentCall.args[0]).toEqual('inline-style-parse');
});
});
});