A platform for community discussion. Free, open, simple.
FIX: Invite acceptance tests were broken in Ember CLI (#12367)
Robin Wardc60cdab1fe73
diff --git a/app/assets/javascripts/discourse/tests/acceptance/invite-accept-test.js b/app/assets/javascripts/discourse/tests/acceptance/invite-accept-test.jsindex 7a8f9ea517b..1265053c1cb 100644--- a/app/assets/javascripts/discourse/tests/acceptance/invite-accept-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/invite-accept-test.js@@ -8,6 +8,43 @@ import PreloadStore from "discourse/lib/preload-store";import I18n from "I18n";import { test } from "qunit";+function setAuthenticationData(hooks, json) {+ hooks.beforeEach(() => {+ const node = document.createElement("meta");+ node.dataset.authenticationData = JSON.stringify(json);+ node.id = "data-authentication";+ document.querySelector("head").appendChild(node);+ });+ hooks.afterEach(() => {+ document+ .querySelector("head")+ .removeChild(document.getElementById("data-authentication"));+ });+}++function preloadInvite({ link = false } = {}) {+ const info = {+ invited_by: {+ id: 123,+ username: "foobar",+ avatar_template: "/user_avatar/localhost/neil/{size}/25_1.png",+ name: "foobar",+ title: "team",+ },+ username: "invited",+ };++ if (link) {+ info.email = "null";+ info.is_invite_link = true;+ } else {+ info.email = "[email protected]";+ info.is_invite_link = false;+ }++ PreloadStore.store("invite_info", info);+}+acceptance("Invite accept", function (needs) {needs.settings({ full_name_required: true });@@ -115,52 +152,37 @@ acceptance("Invite accept", function (needs) {acceptance("Invite accept when local login is disabled", function (needs) {needs.settings({ enable_local_logins: false });- const preloadStore = function (isInviteLink) {- const info = {- invited_by: {- id: 123,- username: "foobar",- avatar_template: "/user_avatar/localhost/neil/{size}/25_1.png",- name: "foobar",- title: "team",- },- username: "invited",- };-- if (isInviteLink) {- info.email = "null";- info.is_invite_link = true;- } else {- info.email = "[email protected]";- info.is_invite_link = false;- }+ test("invite link", async function (assert) {+ preloadInvite({ link: true });- PreloadStore.store("invite_info", info);- };+ await visit("/invites/myvalidinvitetoken");- test("invite link", async function (assert) {- preloadStore(true);+ assert.ok(exists(".btn-social.facebook"), "shows Facebook login button");+ assert.ok(!exists("form"), "does not display the form");+ });+ test("email invite link", async function (assert) {+ preloadInvite();await visit("/invites/myvalidinvitetoken");assert.ok(exists(".btn-social.facebook"), "shows Facebook login button");assert.ok(!exists("form"), "does not display the form");});+});- test("invite link with authentication data", async function (assert) {- preloadStore(true);+acceptance("Invite link with authentication data", function (needs) {+ needs.settings({ enable_local_logins: false });- // Simulate authticated with Facebook- const node = document.createElement("meta");- node.dataset.authenticationData = JSON.stringify({- auth_provider: "facebook",- email: "[email protected]",- email_valid: true,- username: "foobar",- name: "barfoo",- });- node.id = "data-authentication";- document.querySelector("head").appendChild(node);+ setAuthenticationData(needs.hooks, {+ auth_provider: "facebook",+ email: "[email protected]",+ email_valid: true,+ username: "foobar",+ name: "barfoo",+ });++ test("form elements and buttons are correct ", async function (assert) {+ preloadInvite({ link: true });await visit("/invites/myvalidinvitetoken");@@ -192,35 +214,22 @@ acceptance("Invite accept when local login is disabled", function (needs) {"barfoo","name is prefilled");-- document- .querySelector("head")- .removeChild(document.getElementById("data-authentication"));});+});- test("email invite link", async function (assert) {- preloadStore(false);-- await visit("/invites/myvalidinvitetoken");+acceptance("Email Invite link with authentication data", function (needs) {+ needs.settings({ enable_local_logins: false });- assert.ok(exists(".btn-social.facebook"), "shows Facebook login button");- assert.ok(!exists("form"), "does not display the form");+ setAuthenticationData(needs.hooks, {+ auth_provider: "facebook",+ email: "[email protected]",+ email_valid: true,+ username: "foobar",+ name: "barfoo",});test("email invite link with authentication data when email does not match", async function (assert) {- preloadStore(false);-- // Simulate authticated with Facebook- const node = document.createElement("meta");- node.dataset.authenticationData = JSON.stringify({- auth_provider: "facebook",- email: "[email protected]",- email_valid: true,- username: "foobar",- name: "barfoo",- });- node.id = "data-authentication";- document.querySelector("head").appendChild(node);+ preloadInvite();await visit("/invites/myvalidinvitetoken");@@ -230,56 +239,54 @@ acceptance("Invite accept when local login is disabled", function (needs) {);assert.ok(!exists("form"), "does not display the form");-- document- .querySelector("head")- .removeChild(document.getElementById("data-authentication"));});+});- test("email invite link with authentication data", async function (assert) {- preloadStore(false);+acceptance(+ "Email Invite link with valid authentication data",+ function (needs) {+ needs.settings({ enable_local_logins: false });- // Simulate authticated with Facebook- const node = document.createElement("meta");- node.dataset.authenticationData = JSON.stringify({+ setAuthenticationData(needs.hooks, {auth_provider: "facebook",email: "[email protected]",email_valid: true,username: "foobar",name: "barfoo",});- node.id = "data-authentication";- document.querySelector("head").appendChild(node);-- await visit("/invites/myvalidinvitetoken");-- assert.ok(- !exists(".btn-social.facebook"),- "does not show Facebook login button"- );- assert.ok(!exists("#new-account-password"), "does not show password field");- assert.ok(!exists("#new-account-email"), "does not show email field");-- assert.equal(- queryAll("#account-email-validation").text().trim(),- I18n.t("user.email.authenticated", { provider: "Facebook" })- );-- assert.equal(- queryAll("#new-account-username").val(),- "foobar",- "username is prefilled"- );-- assert.equal(- queryAll("#new-account-name").val(),- "barfoo",- "name is prefilled"- );-- document- .querySelector("head")- .removeChild(document.getElementById("data-authentication"));- });-});+ test("confirm form and buttons", async function (assert) {+ preloadInvite();++ await visit("/invites/myvalidinvitetoken");++ assert.ok(+ !exists(".btn-social.facebook"),+ "does not show Facebook login button"+ );++ assert.ok(+ !exists("#new-account-password"),+ "does not show password field"+ );+ assert.ok(!exists("#new-account-email"), "does not show email field");++ assert.equal(+ queryAll("#account-email-validation").text().trim(),+ I18n.t("user.email.authenticated", { provider: "Facebook" })+ );++ assert.equal(+ queryAll("#new-account-username").val(),+ "foobar",+ "username is prefilled"+ );++ assert.equal(+ queryAll("#new-account-name").val(),+ "barfoo",+ "name is prefilled"+ );+ });+ }+);