2019-11-28 14:30:21 +03:00
|
|
|
import moment from 'moment';
|
|
|
|
import wait from 'ember-test-helpers/wait';
|
2019-01-22 19:23:26 +03:00
|
|
|
import {authenticateSession, invalidateSession} from 'ember-simple-auth/test-support';
|
|
|
|
import {beforeEach, describe, it} from 'mocha';
|
2019-11-28 14:30:21 +03:00
|
|
|
import {click, currentRouteName, currentURL, fillIn, find, findAll} from '@ember/test-helpers';
|
2019-01-22 19:23:26 +03:00
|
|
|
import {expect} from 'chai';
|
|
|
|
import {setupApplicationTest} from 'ember-mocha';
|
2019-05-27 11:37:05 +03:00
|
|
|
import {setupMirage} from 'ember-cli-mirage/test-support';
|
2019-11-28 14:30:21 +03:00
|
|
|
import {timeout} from 'ember-concurrency';
|
2019-01-22 19:23:26 +03:00
|
|
|
import {visit} from '../helpers/visit';
|
|
|
|
|
|
|
|
describe('Acceptance: Members', function () {
|
|
|
|
let hooks = setupApplicationTest();
|
|
|
|
setupMirage(hooks);
|
|
|
|
|
|
|
|
it('redirects to signin when not authenticated', async function () {
|
|
|
|
await invalidateSession();
|
|
|
|
await visit('/members');
|
|
|
|
|
|
|
|
expect(currentURL()).to.equal('/signin');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects non-admins to posts', async function () {
|
|
|
|
let role = this.server.create('role', {name: 'Editor'});
|
|
|
|
this.server.create('user', {roles: [role]});
|
|
|
|
|
|
|
|
await authenticateSession();
|
|
|
|
await visit('/members');
|
|
|
|
|
2019-03-21 12:33:14 +03:00
|
|
|
expect(currentURL()).to.equal('/site');
|
2019-01-22 19:23:26 +03:00
|
|
|
expect(find('[data-test-nav="members"]'), 'sidebar link')
|
|
|
|
.to.not.exist;
|
|
|
|
});
|
|
|
|
|
2019-10-14 06:10:32 +03:00
|
|
|
describe('as owner', function () {
|
2019-01-22 19:23:26 +03:00
|
|
|
beforeEach(async function () {
|
2019-02-25 17:47:17 +03:00
|
|
|
this.server.loadFixtures('configs');
|
2019-01-22 19:23:26 +03:00
|
|
|
|
2019-10-14 06:10:32 +03:00
|
|
|
let role = this.server.create('role', {name: 'Owner'});
|
2019-01-22 19:23:26 +03:00
|
|
|
this.server.create('user', {roles: [role]});
|
|
|
|
|
|
|
|
return await authenticateSession();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows sidebar link which navigates to members list', async function () {
|
2019-03-11 10:43:55 +03:00
|
|
|
await visit('/settings/labs');
|
|
|
|
await click('#labs-members');
|
2019-01-22 19:23:26 +03:00
|
|
|
await visit('/');
|
|
|
|
|
|
|
|
expect(find('[data-test-nav="members"]'), 'sidebar link')
|
|
|
|
.to.exist;
|
|
|
|
|
|
|
|
await click('[data-test-nav="members"]');
|
|
|
|
|
|
|
|
expect(currentURL()).to.equal('/members');
|
2019-10-07 13:17:16 +03:00
|
|
|
expect(currentRouteName()).to.equal('members.index');
|
2019-01-22 19:23:26 +03:00
|
|
|
expect(find('[data-test-screen-title]')).to.have.text('Members');
|
|
|
|
});
|
2019-11-28 14:30:21 +03:00
|
|
|
|
|
|
|
it('it renders, can be navigated, can edit member', async function () {
|
|
|
|
let member1 = this.server.create('member', {createdAt: moment.utc().subtract(1, 'day').valueOf()});
|
|
|
|
this.server.create('member', {createdAt: moment.utc().subtract(2, 'day').valueOf()});
|
|
|
|
|
|
|
|
await visit('/members');
|
|
|
|
|
|
|
|
// second wait is needed for the vertical-collection to settle
|
|
|
|
await wait();
|
|
|
|
|
|
|
|
// lands on correct page
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/members');
|
|
|
|
|
|
|
|
// it has correct page title
|
|
|
|
expect(document.title, 'page title').to.equal('Members - Test Blog');
|
|
|
|
|
|
|
|
// it lists all members
|
|
|
|
expect(findAll('.members-list .gh-members-list-item').length, 'members list count')
|
|
|
|
.to.equal(2);
|
|
|
|
|
|
|
|
let member = find('.members-list .gh-members-list-item');
|
|
|
|
expect(member.querySelector('.gh-members-list-name').textContent, 'member list item title')
|
|
|
|
.to.equal(member1.name);
|
|
|
|
|
|
|
|
await visit(`/members/${member1.id}`);
|
|
|
|
|
|
|
|
// // second wait is needed for the member details to settle
|
|
|
|
await wait();
|
|
|
|
|
|
|
|
// it shows selected member form
|
|
|
|
expect(find('.gh-member-basic-settings-form input[name="name"]').value, 'loads correct member into form')
|
|
|
|
.to.equal(member1.name);
|
|
|
|
|
|
|
|
expect(find('.gh-member-basic-settings-form input[name="email-disabled"]').disabled, 'makes sure email is disabled')
|
|
|
|
.to.equal(true);
|
|
|
|
|
|
|
|
// trigger save
|
|
|
|
await fillIn('.gh-member-basic-settings-form input[name="name"]', 'New Name');
|
|
|
|
await blur('.gh-member-basic-settings-form input[name="name"]');
|
|
|
|
|
|
|
|
await click('[data-test-button="save"]');
|
|
|
|
|
|
|
|
// // extra timeout needed for Travis - sometimes it doesn't update
|
|
|
|
// // quick enough and an extra wait() call doesn't help
|
|
|
|
await timeout(100);
|
|
|
|
|
|
|
|
await click('[data-test-link="members-back"]');
|
|
|
|
|
|
|
|
await wait();
|
|
|
|
|
|
|
|
// lands on correct page
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/members');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can create a new member', async function () {
|
|
|
|
this.server.create('member', {createdAt: moment.utc().subtract(1, 'day').valueOf()});
|
|
|
|
|
|
|
|
await visit('/members');
|
|
|
|
|
|
|
|
// second wait is needed for the vertical-collection to settle
|
|
|
|
await wait();
|
|
|
|
|
|
|
|
// lands on correct page
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/members');
|
|
|
|
|
|
|
|
// it has correct page title
|
|
|
|
expect(document.title, 'page title').to.equal('Members - Test Blog');
|
|
|
|
|
|
|
|
// it lists all members
|
|
|
|
expect(findAll('.members-list .gh-members-list-item').length, 'members list count')
|
|
|
|
.to.equal(1);
|
|
|
|
|
|
|
|
// start new member
|
|
|
|
await click('[data-test-new-member-button="true"]');
|
|
|
|
|
|
|
|
// it navigates to the new member route
|
|
|
|
expect(currentURL(), 'new member URL').to.equal('/members/new');
|
|
|
|
// it displays the new member form
|
|
|
|
expect(find('.member-basic-info-form .gh-canvas-header h2').textContent, 'settings pane title')
|
|
|
|
.to.contain('New member');
|
|
|
|
|
|
|
|
// // all fields start blank
|
2019-12-03 07:24:16 +03:00
|
|
|
findAll('.gh-member-basic-settings-form .gh-input').forEach(function (elem) {
|
2019-11-28 14:30:21 +03:00
|
|
|
expect(elem.value, `input field for ${elem.getAttribute('name')}`)
|
|
|
|
.to.be.empty;
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(find('.gh-member-basic-settings-form input[name="email"]').disabled, 'makes sure email is disabled')
|
|
|
|
.to.equal(false);
|
|
|
|
|
|
|
|
// save new member
|
|
|
|
await fillIn('.gh-member-basic-settings-form input[name="name"]', 'New Name');
|
|
|
|
await blur('.gh-member-basic-settings-form input[name="name"]');
|
|
|
|
|
|
|
|
await fillIn('.gh-member-basic-settings-form input[name="email"]', 'example@domain.com');
|
|
|
|
await blur('.gh-member-basic-settings-form input[name="email"]');
|
|
|
|
|
|
|
|
await click('[data-test-button="save"]');
|
|
|
|
|
2019-12-03 12:05:56 +03:00
|
|
|
await wait();
|
2019-11-28 14:30:21 +03:00
|
|
|
|
2019-12-03 07:24:16 +03:00
|
|
|
expect(find('.gh-member-basic-settings-form input[name="name"]').value, 'name has been preserved')
|
|
|
|
.to.equal('New Name');
|
2019-12-03 12:05:56 +03:00
|
|
|
expect(find('.gh-member-basic-settings-form input[name="email-disabled"]').disabled, 'makes sure email is disabled')
|
|
|
|
.to.equal(true);
|
2019-11-28 14:30:21 +03:00
|
|
|
});
|
2019-01-22 19:23:26 +03:00
|
|
|
});
|
|
|
|
});
|