Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken browser tests #1396

Merged
merged 4 commits into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions spec/buttons.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 + '=""', '');
}
5 changes: 5 additions & 0 deletions spec/content.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<p>lorem ipsum</p><ul><li></li><li>lorem ipsum</li></ul>');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you use a matches test here instead of toBe? that will let you use a regex and not have to modify the actual element for the comparison. I've use the regex thing in a bunch of tests in the repo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, i meant toMatch, put too much trust in my memory. Here's an example

});
});
Expand Down Expand Up @@ -811,3 +812,7 @@ describe('Content TestCase', function () {
});
});
});

function stripLinebreak(element) {
return element.innerHTML.replace('<br>', '');
}