2022-03-08 14:32:01 +03:00
|
|
|
import {Response} from 'miragejs';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {authenticateSession, invalidateSession} from 'ember-simple-auth/test-support';
|
|
|
|
import {beforeEach, describe, it} from 'mocha';
|
2022-03-08 20:30:46 +03:00
|
|
|
import {click, currentURL, fillIn, find, findAll} from '@ember/test-helpers';
|
2022-02-01 20:32:38 +03:00
|
|
|
import {enableLabsFlag} from '../helpers/labs-flag';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {expect} from 'chai';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {setupApplicationTest} from 'ember-mocha';
|
2019-05-27 11:37:05 +03:00
|
|
|
import {setupMirage} from 'ember-cli-mirage/test-support';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {visit} from '../helpers/visit';
|
2015-11-26 13:39:37 +03:00
|
|
|
|
|
|
|
describe('Acceptance: Setup', function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
let hooks = setupApplicationTest();
|
|
|
|
setupMirage(hooks);
|
2015-11-26 13:39:37 +03:00
|
|
|
|
2022-02-01 21:20:19 +03:00
|
|
|
beforeEach(function () {
|
|
|
|
enableLabsFlag(this.server, 'improvedOnboarding');
|
|
|
|
});
|
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
it('redirects if already authenticated', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
let role = this.server.create('role', {name: 'Author'});
|
|
|
|
this.server.create('user', {roles: [role], slug: 'test-user'});
|
2015-11-26 13:39:37 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await authenticateSession();
|
2015-11-26 13:39:37 +03:00
|
|
|
|
2022-03-08 20:30:46 +03:00
|
|
|
await visit('/setup');
|
2021-02-24 18:56:18 +03:00
|
|
|
expect(currentURL()).to.equal('/site');
|
2015-11-26 13:39:37 +03:00
|
|
|
});
|
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
it('redirects to signin if already set up', async function () {
|
2015-11-26 13:39:37 +03:00
|
|
|
// mimick an already setup blog
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.get('/authentication/setup/', function () {
|
2015-11-26 13:39:37 +03:00
|
|
|
return {
|
|
|
|
setup: [
|
|
|
|
{status: true}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await invalidateSession();
|
2015-11-26 13:39:37 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
await visit('/setup');
|
|
|
|
expect(currentURL()).to.equal('/signin');
|
2015-11-26 13:39:37 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('with a new blog', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
// mimick a new blog
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.get('/authentication/setup/', function () {
|
2015-11-26 13:39:37 +03:00
|
|
|
return {
|
|
|
|
setup: [
|
|
|
|
{status: false}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
it('has a successful happy path', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
await invalidateSession();
|
|
|
|
this.server.loadFixtures('roles');
|
2015-11-26 13:39:37 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
await visit('/setup');
|
2015-11-26 13:39:37 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
// email field is focused by default
|
|
|
|
// NOTE: $('x').is(':focus') doesn't work in phantomjs CLI runner
|
|
|
|
// https://github.com/ariya/phantomjs/issues/10427
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(findAll('[data-test-blog-title-input]')[0] === document.activeElement, 'blog title has focus')
|
2017-04-24 15:29:48 +03:00
|
|
|
.to.be.true;
|
2015-11-26 13:39:37 +03:00
|
|
|
|
2022-03-08 20:30:46 +03:00
|
|
|
await click('[data-test-button="setup"]');
|
2015-11-26 13:39:37 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
// it marks fields as invalid
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(findAll('.form-group.error').length, 'number of invalid fields')
|
2017-04-24 15:29:48 +03:00
|
|
|
.to.equal(4);
|
2015-11-26 13:39:37 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
// it displays error messages
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(findAll('.error .response').length, 'number of in-line validation messages')
|
2017-04-24 15:29:48 +03:00
|
|
|
.to.equal(4);
|
2015-11-26 13:39:37 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
// it displays main error
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(findAll('.main-error').length, 'main error is displayed')
|
2017-04-24 15:29:48 +03:00
|
|
|
.to.equal(1);
|
2015-11-26 13:39:37 +03:00
|
|
|
|
|
|
|
// enter valid details and submit
|
2017-08-11 18:28:05 +03:00
|
|
|
await fillIn('[data-test-email-input]', 'test@example.com');
|
|
|
|
await fillIn('[data-test-name-input]', 'Test User');
|
2017-10-26 13:02:17 +03:00
|
|
|
await fillIn('[data-test-password-input]', 'thisissupersafe');
|
2017-08-11 18:28:05 +03:00
|
|
|
await fillIn('[data-test-blog-title-input]', 'Blog Title');
|
2022-03-08 20:30:46 +03:00
|
|
|
await click('[data-test-button="setup"]');
|
2017-04-24 15:29:48 +03:00
|
|
|
|
2022-03-08 20:30:46 +03:00
|
|
|
// it redirects to the dashboard
|
|
|
|
expect(currentURL(), 'url after submitting account details')
|
2022-03-11 15:52:30 +03:00
|
|
|
.to.equal('/setup/done');
|
2015-11-26 13:39:37 +03:00
|
|
|
});
|
|
|
|
|
2022-03-08 20:30:46 +03:00
|
|
|
it('handles validation errors in setup', async function () {
|
2016-01-05 20:01:42 +03:00
|
|
|
let postCount = 0;
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await invalidateSession();
|
|
|
|
this.server.loadFixtures('roles');
|
2016-01-05 20:01:42 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.post('/authentication/setup', function () {
|
2018-01-05 18:38:23 +03:00
|
|
|
postCount += 1;
|
2016-01-05 20:01:42 +03:00
|
|
|
|
|
|
|
// validation error
|
|
|
|
if (postCount === 1) {
|
2017-01-02 21:50:36 +03:00
|
|
|
return new Response(422, {}, {
|
2016-01-05 20:01:42 +03:00
|
|
|
errors: [
|
|
|
|
{
|
2019-03-25 14:29:14 +03:00
|
|
|
type: 'ValidationError',
|
2016-01-05 20:01:42 +03:00
|
|
|
message: 'Server response message'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// server error
|
|
|
|
if (postCount === 2) {
|
2017-01-02 21:50:36 +03:00
|
|
|
return new Response(500, {}, null);
|
2016-01-05 20:01:42 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-03-08 20:30:46 +03:00
|
|
|
await visit('/setup');
|
|
|
|
await click('[data-test-button="setup"]');
|
2016-01-05 20:01:42 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
// non-server validation
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(find('.main-error').textContent.trim(), 'error text')
|
2018-03-26 13:41:45 +03:00
|
|
|
.to.not.be.empty;
|
2016-01-05 20:01:42 +03:00
|
|
|
|
2017-08-11 18:28:05 +03:00
|
|
|
await fillIn('[data-test-email-input]', 'test@example.com');
|
|
|
|
await fillIn('[data-test-name-input]', 'Test User');
|
2017-10-26 13:02:17 +03:00
|
|
|
await fillIn('[data-test-password-input]', 'thisissupersafe');
|
2017-08-11 18:28:05 +03:00
|
|
|
await fillIn('[data-test-blog-title-input]', 'Blog Title');
|
2016-01-05 20:01:42 +03:00
|
|
|
|
|
|
|
// first post - simulated validation error
|
2022-03-08 20:30:46 +03:00
|
|
|
await click('[data-test-button="setup"]');
|
2016-01-05 20:01:42 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(find('.main-error').textContent.trim(), 'error text')
|
2017-04-24 15:29:48 +03:00
|
|
|
.to.equal('Server response message');
|
2016-01-05 20:01:42 +03:00
|
|
|
|
|
|
|
// second post - simulated server error
|
2022-03-08 20:30:46 +03:00
|
|
|
await click('[data-test-button="setup"]');
|
2016-01-05 20:01:42 +03:00
|
|
|
|
2022-03-08 20:30:46 +03:00
|
|
|
expect(findAll('.main-error').length, 'main error is not displayed')
|
|
|
|
.to.equal(0);
|
2016-01-05 20:01:42 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(findAll('.gh-alert-red').length, 'number of alerts')
|
2017-04-24 15:29:48 +03:00
|
|
|
.to.equal(1);
|
2016-01-05 20:01:42 +03:00
|
|
|
});
|
2015-11-26 13:39:37 +03:00
|
|
|
|
2022-03-08 20:30:46 +03:00
|
|
|
it('handles invalid origin error on setup', async function () {
|
2015-11-26 13:39:37 +03:00
|
|
|
// mimick the API response for an invalid origin
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.post('/session', function () {
|
2017-01-02 21:50:36 +03:00
|
|
|
return new Response(401, {}, {
|
2015-11-26 13:39:37 +03:00
|
|
|
errors: [
|
|
|
|
{
|
2019-03-25 14:29:14 +03:00
|
|
|
type: 'UnauthorizedError',
|
2015-11-26 13:39:37 +03:00
|
|
|
message: 'Access Denied from url: unknown.com. Please use the url configured in config.js.'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await invalidateSession();
|
|
|
|
this.server.loadFixtures('roles');
|
2015-11-26 13:39:37 +03:00
|
|
|
|
2022-03-08 20:30:46 +03:00
|
|
|
await visit('/setup');
|
2017-08-11 18:28:05 +03:00
|
|
|
await fillIn('[data-test-email-input]', 'test@example.com');
|
|
|
|
await fillIn('[data-test-name-input]', 'Test User');
|
2017-10-26 13:02:17 +03:00
|
|
|
await fillIn('[data-test-password-input]', 'thisissupersafe');
|
2017-08-11 18:28:05 +03:00
|
|
|
await fillIn('[data-test-blog-title-input]', 'Blog Title');
|
2022-03-08 20:30:46 +03:00
|
|
|
await click('[data-test-button="setup"]');
|
2017-04-24 15:29:48 +03:00
|
|
|
|
|
|
|
// button should not be spinning
|
2022-03-08 20:30:46 +03:00
|
|
|
expect(findAll('.gh-btn-signup .spinner').length, 'button has spinner')
|
2017-04-24 15:29:48 +03:00
|
|
|
.to.equal(0);
|
|
|
|
// we should show an error message
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(find('.main-error').textContent, 'error text')
|
2018-02-07 12:30:04 +03:00
|
|
|
.to.have.string('Access Denied from url: unknown.com. Please use the url configured in config.js.');
|
2015-11-26 13:39:37 +03:00
|
|
|
});
|
|
|
|
});
|
2022-02-01 20:32:38 +03:00
|
|
|
|
|
|
|
describe('?firstStart=true', function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
let role = this.server.create('role', {name: 'Owner'});
|
|
|
|
this.server.create('user', {roles: [role], slug: 'owner'});
|
|
|
|
|
|
|
|
await authenticateSession();
|
|
|
|
});
|
|
|
|
|
2022-03-02 15:44:11 +03:00
|
|
|
it('transitions to done screen', async function () {
|
2022-02-01 20:32:38 +03:00
|
|
|
await visit('/?firstStart=true');
|
2022-03-02 15:44:11 +03:00
|
|
|
expect(currentURL()).to.equal('/setup/done');
|
2022-02-01 20:32:38 +03:00
|
|
|
});
|
|
|
|
});
|
2015-11-26 13:39:37 +03:00
|
|
|
});
|