From 0f510ab5496ca1248375433111b11abb2db5d612 Mon Sep 17 00:00:00 2001 From: Noah Chase Date: Tue, 19 Dec 2017 11:58:29 -0500 Subject: [PATCH 1/4] fix chrome button tests to fix the broken button tests in chrome, we want to strip empty attributes (especially styles, because the tests create style tags, inject style content, and then remove that style content). some browsers will remove empty attributes automatically, others (Chrome, seemingly) will not. --- spec/buttons.spec.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/buttons.spec.js b/spec/buttons.spec.js index 5132f35e7..25aa208e5 100644 --- a/spec/buttons.spec.js +++ b/spec/buttons.spec.js @@ -431,6 +431,9 @@ describe('Buttons TestCase', function () { expect(button.classList.contains('medium-editor-button-active')).toBe(true); fireEvent(button, 'click'); + + this.el.innerHTML = stripAttrIfEmpty(this.el, 'style'); + // style="font-weight: bold" prevents IE9+10 from doing anything when 'bold' is triggered // but it should work in other browsers expect(!isOldIE() && button.classList.contains('medium-editor-button-active')).toBe(false); @@ -507,6 +510,9 @@ describe('Buttons TestCase', function () { expect(button.classList.contains('medium-editor-button-active')).toBe(true); fireEvent(button, 'click'); + + this.el.innerHTML = stripAttrIfEmpty(this.el, 'style'); + // style="font-style: italic" prevents IE9+10 from doing anything when 'italic' is triggered // but it should work in other browsers expect(!isOldIE() && button.classList.contains('medium-editor-button-active')).toBe(false); @@ -566,6 +572,9 @@ describe('Buttons TestCase', function () { expect(button.classList.contains('medium-editor-button-active')).toBe(true); fireEvent(button, 'click'); + + this.el.innerHTML = stripAttrIfEmpty(this.el, 'style'); + // style="text-decoration: underline" prevents IE9+10 from doing anything when 'underline' is triggered // but it should work in other browsers expect(!isOldIE() && button.classList.contains('medium-editor-button-active')).toBe(false); @@ -625,6 +634,9 @@ describe('Buttons TestCase', function () { expect(button.classList.contains('medium-editor-button-active')).toBe(true); fireEvent(button, 'click'); + + this.el.innerHTML = stripAttrIfEmpty(this.el, 'style'); + // style="text-decoration: line-through" prevents IE9+10 from doing anything when 'strikethrough' is triggered // but it should work in other browsers expect(!isOldIE() && button.classList.contains('medium-editor-button-active')).toBe(false); @@ -1056,3 +1068,14 @@ describe('Buttons TestCase', function () { }); }); }); + +function stripAttrIfEmpty(element, attribute) { + // we want to strip empty attributes (especially styles, + // because the tests create style tags, inject style content, + // and then remove that style content. + // + // some browsers will remove empty attributes automatically. + // + // others (Chrome, seemingly) will not: + return element.innerHTML.replace(attribute + '=""', ''); +} From 318606dabcc9a6fb443488934a51530001fba494 Mon Sep 17 00:00:00 2001 From: Noah Chase Date: Tue, 19 Dec 2017 12:50:23 -0500 Subject: [PATCH 2/4] fix firefox line item test another scenario where browser internal rules change and the generated DOM is slightly different than what we expect. --- spec/content.spec.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/content.spec.js b/spec/content.spec.js index 04d8b27a9..d62e23cf8 100644 --- a/spec/content.spec.js +++ b/spec/content.spec.js @@ -649,6 +649,7 @@ describe('Content TestCase', function () { fireEvent(target, 'keydown', { keyCode: MediumEditor.util.keyCode.BACKSPACE }); + this.el.innerHTML = stripLinebreak(this.el); expect(this.el.innerHTML).toBe('

lorem ipsum

'); }); }); @@ -811,3 +812,7 @@ describe('Content TestCase', function () { }); }); }); + +function stripLinebreak(element) { + return element.innerHTML.replace('
', ''); +} From 358fcd99721708b879bd9d06fd4ad986b2e23dee Mon Sep 17 00:00:00 2001 From: Noah Chase Date: Tue, 19 Dec 2017 14:00:46 -0500 Subject: [PATCH 3/4] use localhost instead of 127.0.0.1 for sauce tests --- Gruntfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index 2ce895c78..8544542de 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -290,7 +290,7 @@ module.exports = function (grunt) { gruntConfig['saucelabs-jasmine'] = { all: { options: { - urls: ['http://127.0.0.1:9999/_SpecRunner.html'], + urls: ['http://localhost:9999/_SpecRunner.html'], tunnelTimeout: 5, build: process.env.TRAVIS_JOB_ID, concurrency: 3, From 52defad7ffeb08519bf08772f8c8d4c4769730c0 Mon Sep 17 00:00:00 2001 From: Noah Chase Date: Tue, 19 Dec 2017 15:47:13 -0500 Subject: [PATCH 4/4] use .toMatch to catch optional linebreak --- spec/content.spec.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/spec/content.spec.js b/spec/content.spec.js index d62e23cf8..56f584c09 100644 --- a/spec/content.spec.js +++ b/spec/content.spec.js @@ -649,8 +649,7 @@ describe('Content TestCase', function () { fireEvent(target, 'keydown', { keyCode: MediumEditor.util.keyCode.BACKSPACE }); - this.el.innerHTML = stripLinebreak(this.el); - expect(this.el.innerHTML).toBe('

lorem ipsum

  • lorem ipsum
'); + expect(this.el.innerHTML).toMatch(/^

lorem ipsum<\/p>

  • (
    )?<\/li>
  • lorem ipsum<\/li><\/ul>$/); }); }); @@ -812,7 +811,3 @@ describe('Content TestCase', function () { }); }); }); - -function stripLinebreak(element) { - return element.innerHTML.replace('
    ', ''); -}