DEV: migrate acceptance tests to async await - badges, category, composer, customHTML

This commit is contained in:
Maja Komel
2018-07-19 11:40:42 +02:00
parent e8e9b5cea4
commit e36d1c72f1
10 changed files with 645 additions and 805 deletions

View File

@ -9,152 +9,140 @@ acceptance("Composer topic featured links", {
}
});
QUnit.test("onebox with title", assert => {
visit("/");
click("#create-topic");
fillIn("#reply-title", "http://www.example.com/has-title.html");
andThen(() => {
assert.ok(
find(".d-editor-preview")
.html()
.trim()
.indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"the body is now good"
);
assert.equal(
find(".title-input input").val(),
"An interesting article",
"title is from the oneboxed article"
);
});
QUnit.test("onebox with title", async assert => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "http://www.example.com/has-title.html");
assert.ok(
find(".d-editor-preview")
.html()
.trim()
.indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"the body is now good"
);
assert.equal(
find(".title-input input").val(),
"An interesting article",
"title is from the oneboxed article"
);
});
QUnit.test("onebox result doesn't include a title", assert => {
visit("/");
click("#create-topic");
fillIn("#reply-title", "http://www.example.com/no-title.html");
andThen(() => {
assert.ok(
find(".d-editor-preview")
.html()
.trim()
.indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"the body is now good"
);
assert.equal(
find(".title-input input").val(),
"http://www.example.com/no-title.html",
"title is unchanged"
);
});
QUnit.test("onebox result doesn't include a title", async assert => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "http://www.example.com/no-title.html");
assert.ok(
find(".d-editor-preview")
.html()
.trim()
.indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"the body is now good"
);
assert.equal(
find(".title-input input").val(),
"http://www.example.com/no-title.html",
"title is unchanged"
);
});
QUnit.test("no onebox result", assert => {
visit("/");
click("#create-topic");
fillIn("#reply-title", "http://www.example.com/nope-onebox.html");
andThen(() => {
assert.ok(
find(".d-editor-preview")
.html()
.trim()
.indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"link is pasted into body"
);
assert.equal(
find(".title-input input").val(),
"http://www.example.com/nope-onebox.html",
"title is unchanged"
);
});
QUnit.test("no onebox result", async assert => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "http://www.example.com/nope-onebox.html");
assert.ok(
find(".d-editor-preview")
.html()
.trim()
.indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"link is pasted into body"
);
assert.equal(
find(".title-input input").val(),
"http://www.example.com/nope-onebox.html",
"title is unchanged"
);
});
QUnit.test("ignore internal links", assert => {
visit("/");
click("#create-topic");
QUnit.test("ignore internal links", async assert => {
await visit("/");
await click("#create-topic");
const title = "http://" + window.location.hostname + "/internal-page.html";
fillIn("#reply-title", title);
andThen(() => {
assert.equal(
find(".d-editor-preview")
.html()
.trim()
.indexOf("onebox"),
-1,
"onebox preview doesn't show"
);
assert.equal(
find(".d-editor-input").val().length,
0,
"link isn't put into the post"
);
assert.equal(find(".title-input input").val(), title, "title is unchanged");
});
await fillIn("#reply-title", title);
assert.equal(
find(".d-editor-preview")
.html()
.trim()
.indexOf("onebox"),
-1,
"onebox preview doesn't show"
);
assert.equal(
find(".d-editor-input").val().length,
0,
"link isn't put into the post"
);
assert.equal(find(".title-input input").val(), title, "title is unchanged");
});
QUnit.test("link is longer than max title length", assert => {
visit("/");
click("#create-topic");
fillIn(
QUnit.test("link is longer than max title length", async assert => {
await visit("/");
await click("#create-topic");
await fillIn(
"#reply-title",
"http://www.example.com/has-title-and-a-url-that-is-more-than-80-characters-because-thats-good-for-seo-i-guess.html"
);
andThen(() => {
assert.ok(
find(".d-editor-preview")
.html()
.trim()
.indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"the body is now good"
);
assert.equal(
find(".title-input input").val(),
"An interesting article",
"title is from the oneboxed article"
);
});
assert.ok(
find(".d-editor-preview")
.html()
.trim()
.indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"the body is now good"
);
assert.equal(
find(".title-input input").val(),
"An interesting article",
"title is from the oneboxed article"
);
});
QUnit.test("onebox with title but extra words in title field", assert => {
visit("/");
click("#create-topic");
fillIn("#reply-title", "http://www.example.com/has-title.html test");
andThen(() => {
assert.equal(
find(".d-editor-preview")
.html()
.trim()
.indexOf("onebox"),
-1,
"onebox preview doesn't show"
);
assert.equal(
find(".d-editor-input").val().length,
0,
"link isn't put into the post"
);
assert.equal(
find(".title-input input").val(),
"http://www.example.com/has-title.html test",
"title is unchanged"
);
});
QUnit.test("onebox with title but extra words in title field", async assert => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "http://www.example.com/has-title.html test");
assert.equal(
find(".d-editor-preview")
.html()
.trim()
.indexOf("onebox"),
-1,
"onebox preview doesn't show"
);
assert.equal(
find(".d-editor-input").val().length,
0,
"link isn't put into the post"
);
assert.equal(
find(".title-input input").val(),
"http://www.example.com/has-title.html test",
"title is unchanged"
);
});
acceptance("Composer topic featured links when uncategorized is not allowed", {
@ -167,38 +155,34 @@ acceptance("Composer topic featured links when uncategorized is not allowed", {
}
});
QUnit.test("Pasting a link enables the text input area", assert => {
QUnit.test("Pasting a link enables the text input area", async assert => {
replaceCurrentUser({ admin: false, staff: false, trust_level: 1 });
visit("/");
click("#create-topic");
andThen(() => {
assert.ok(
find(".d-editor-textarea-wrapper.disabled").length,
"textarea is disabled"
);
});
fillIn("#reply-title", "http://www.example.com/has-title.html");
andThen(() => {
assert.ok(
find(".d-editor-preview")
.html()
.trim()
.indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"the body is now good"
);
assert.equal(
find(".title-input input").val(),
"An interesting article",
"title is from the oneboxed article"
);
assert.ok(
find(".d-editor-textarea-wrapper.disabled").length === 0,
"textarea is enabled"
);
});
await visit("/");
await click("#create-topic");
assert.ok(
find(".d-editor-textarea-wrapper.disabled").length,
"textarea is disabled"
);
await fillIn("#reply-title", "http://www.example.com/has-title.html");
assert.ok(
find(".d-editor-preview")
.html()
.trim()
.indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"the body is now good"
);
assert.equal(
find(".title-input input").val(),
"An interesting article",
"title is from the oneboxed article"
);
assert.ok(
find(".d-editor-textarea-wrapper.disabled").length === 0,
"textarea is enabled"
);
});