diff --git a/assets/javascripts/discourse/controllers/dinopark-sign-up.js.es6 b/assets/javascripts/discourse/controllers/dinopark-sign-up.js.es6 index fd00eba..1a64d27 100644 --- a/assets/javascripts/discourse/controllers/dinopark-sign-up.js.es6 +++ b/assets/javascripts/discourse/controllers/dinopark-sign-up.js.es6 @@ -25,6 +25,10 @@ export default Ember.Controller.extend(ModalFunctionality, { }); }, + redirect(url) { + window.location = url + }, + actions: { normalSignup() { const options = this.get("options") @@ -57,7 +61,7 @@ export default Ember.Controller.extend(ModalFunctionality, { }).then(result => { if (result.success) { var destination_url = this.get("options.destination_url") - window.location = destination_url ? destination_url : "/" + this.redirect(destination_url ? destination_url : "/") } else { this.set("submitted", false) this.flash(result.message || I18n.t("create_account.failed"), "error") diff --git a/assets/javascripts/discourse/templates/modal/dinopark-sign-up.hbs b/assets/javascripts/discourse/templates/modal/dinopark-sign-up.hbs index 975c2b3..13b5a6f 100644 --- a/assets/javascripts/discourse/templates/modal/dinopark-sign-up.hbs +++ b/assets/javascripts/discourse/templates/modal/dinopark-sign-up.hbs @@ -9,22 +9,22 @@ {{/if}}
{{i18n 'dinopark.fields.username'}}:
-
{{values.username}}
+
{{values.username}}
{{i18n 'dinopark.fields.full_name'}}:
-
{{values.full_name}}
+
{{values.full_name}}
{{i18n 'dinopark.fields.pronouns'}}:
-
{{values.pronouns}}
+
{{values.pronouns}}
{{i18n 'dinopark.fields.fun_title'}}:
-
{{values.fun_title}}
+
{{values.fun_title}}
{{i18n 'dinopark.fields.location'}}:
-
{{values.location}}
+
{{values.location}}
{{i18n 'dinopark.fields.description'}}:
-
{{cook-text values.description}}
+
{{cook-text values.description}}
{{input type="checkbox" id="tos-checkbox" checked=tosChecked}} diff --git a/assets/stylesheets/common/mozilla-iam.scss b/assets/stylesheets/common/mozilla-iam.scss index 2fbda7e..1b607a8 100644 --- a/assets/stylesheets/common/mozilla-iam.scss +++ b/assets/stylesheets/common/mozilla-iam.scss @@ -18,7 +18,7 @@ min-height: 1.4em; } - .bio { + .value-bio { p:first-child { margin-top: 0; } diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index b2dfd3d..2f4fad2 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -7,16 +7,18 @@ describe UsersController do describe '#create' do before do User.any_instance.stubs(:active?).returns(true) - UsersController.any_instance.stubs(:honeypot_value).returns(nil) - UsersController.any_instance.stubs(:challenge_value).returns(nil) end let(:create_params) do + get '/u/hp.json' + json = JSON.parse(response.body) { name: "Jill Bloggs", username: "jillbloggs", password: "supersecret", - email: "jill@example.com" + email: "jill@example.com", + password_confirmation: json["value"], + challenge: json["challenge"].reverse } end diff --git a/test/javascripts/acceptance/dinopark-sign-up-test.js.es6 b/test/javascripts/acceptance/dinopark-sign-up-test.js.es6 new file mode 100644 index 0000000..ae97094 --- /dev/null +++ b/test/javascripts/acceptance/dinopark-sign-up-test.js.es6 @@ -0,0 +1,162 @@ +import { acceptance } from "helpers/qunit-helpers" +import user_fixtures from "fixtures/user_fixtures" +import SignUpController from "discourse/plugins/mozilla-iam/discourse/controllers/dinopark-sign-up" + +acceptance("Mozilla IAM - Sign Up") + +// prevent redirecting out of tests +SignUpController.reopen({ + redirect(url) {} +}) + +const data = { + auth_provider: "auth0", + destination_url: "/", + email: "eviltrout@mozilla.com", + email_valid: true, + name: "Eviltrout", + omit_username: false, + username: "eviltrout" +} + +const dinopark_data = Object.assign( + { + dinopark_profile: { + description: "A rather nasty [fish](example.com)", + full_name: "Evil Trout", + fun_title: "Ember Supremo", + location: "The Ocean", + pronouns: "fi/sh", + username: "evil_trout" + } + }, + data +) + +const assertNormalModal = assert => { + assert.ok( + exists(".modal .create-account"), + "opens normal create account modal" + ) + + assert.equal( + find("#new-account-email").val(), + "eviltrout@mozilla.com", + "email is filled in correctly" + ) + + assert.equal( + find("#new-account-username").val(), + "eviltrout", + "username is filled in correctly" + ) + + assert.equal( + find("#new-account-name").val(), + "Eviltrout", + "name is filled in correctly" + ) +} + +QUnit.test("sign up without dinopark enabled", async assert => { + await visit("/"); + + Discourse.authenticationComplete(data) + await new Promise(r => setTimeout(r, 0)) + + assertNormalModal(assert) +}) + +QUnit.test("sign up with dinopark enabled, clicking not right now", async assert => { + await visit("/"); + + Discourse.authenticationComplete(dinopark_data) + await new Promise(r => setTimeout(r, 0)) + + assert.ok( + exists(".modal .dinopark-sign-up"), + "opens normal create account modal" + ) + + await click(".modal-footer .btn:not(.btn-primary)") + + assertNormalModal(assert) +}) + +QUnit.test("sign up with dinopark enabled", async assert => { + await visit("/"); + + Discourse.authenticationComplete(dinopark_data) + await new Promise(r => setTimeout(r, 0)) + + assert.ok( + exists(".modal .dinopark-sign-up"), + "opens normal create account modal" + ) + + assert.ok( + exists(".modal-footer .btn-primary:disabled"), + "continue button is disabled" + ) + + await click("#tos-checkbox") + + await click(".modal-footer .btn-primary") + + assert.equal( + find(".dinopark-fields .value-username").text(), + "evil_trout", + "dinopark username is filled in" + ) + + assert.equal( + find(".dinopark-fields .value-name").text(), + "Evil Trout", + "dinopark name is filled in" + ) + + assert.equal( + find(".dinopark-fields .value-pronouns").text(), + "fi/sh", + "dinopark pronouns is filled in" + ) + + assert.equal( + find(".dinopark-fields .value-title").text(), + "Ember Supremo", + "dinopark title is filled in" + ) + + assert.equal( + find(".dinopark-fields .value-location").text(), + "The Ocean", + "dinopark location is filled in" + ) + + assert.equal( + find(".dinopark-fields .value-bio").text().trim(), + "A rather nasty fish", + "dinopark bio is filled in" + ) + + await click("#tos-checkbox") + + assert.ok( + exists(".modal-footer .btn-primary:disabled"), + "confirm button is disabled" + ) + + await click("#tos-checkbox") + + await click(".modal-footer .btn-primary") + + assert.notOk( + exists(".modal-footer .btn"), + "buttons are hidden" + ) + + assert.ok( + exists(".modal-footer .spinner"), + "spinner is shown" + ) +})