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';
|
2021-01-28 18:25:21 +03:00
|
|
|
import {blur, click, 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');
|
|
|
|
});
|
|
|
|
|
2021-02-24 18:56:18 +03:00
|
|
|
it('redirects non-admins to site', async function () {
|
2019-01-22 19:23:26 +03:00
|
|
|
let role = this.server.create('role', {name: 'Editor'});
|
|
|
|
this.server.create('user', {roles: [role]});
|
|
|
|
|
|
|
|
await authenticateSession();
|
|
|
|
await visit('/members');
|
|
|
|
|
2021-02-24 18:56:18 +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();
|
|
|
|
});
|
|
|
|
|
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
|
2021-10-01 13:04:56 +03:00
|
|
|
expect(findAll('[data-test-list="members-list-item"]').length, 'members list count')
|
2019-11-28 14:30:21 +03:00
|
|
|
.to.equal(2);
|
|
|
|
|
2021-10-01 13:04:56 +03:00
|
|
|
let member = find('[data-test-list="members-list-item"]');
|
2019-11-28 14:30:21 +03:00
|
|
|
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
|
2020-12-16 12:04:33 +03:00
|
|
|
expect(find('[data-test-input="member-name"]').value, 'loads correct member into form')
|
2019-11-28 14:30:21 +03:00
|
|
|
.to.equal(member1.name);
|
|
|
|
|
2020-12-16 12:04:33 +03:00
|
|
|
expect(find('[data-test-input="member-email"]').value, 'loads correct email into form')
|
2020-02-21 11:12:35 +03:00
|
|
|
.to.equal(member1.email);
|
2019-11-28 14:30:21 +03:00
|
|
|
|
|
|
|
// trigger save
|
2020-12-16 12:04:33 +03:00
|
|
|
await fillIn('[data-test-input="member-name"]', 'New Name');
|
|
|
|
await blur('[data-test-input="member-name"]');
|
2019-11-28 14:30:21 +03:00
|
|
|
|
|
|
|
await click('[data-test-button="save"]');
|
|
|
|
|
2020-05-22 12:50:12 +03:00
|
|
|
// extra timeout needed for Travis - sometimes it doesn't update
|
|
|
|
// quick enough and an extra wait() call doesn't help
|
2019-11-28 14:30:21 +03:00
|
|
|
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
|
2021-10-01 13:04:56 +03:00
|
|
|
expect(findAll('[data-test-list="members-list-item"]').length, 'members list count')
|
2019-11-28 14:30:21 +03:00
|
|
|
.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
|
2020-02-27 06:50:15 +03:00
|
|
|
expect(find('.gh-canvas-header h2').textContent, 'settings pane title')
|
2019-11-28 14:30:21 +03:00
|
|
|
.to.contain('New member');
|
|
|
|
|
2020-06-19 20:14:14 +03:00
|
|
|
// all fields start blank
|
2020-02-14 14:07:25 +03:00
|
|
|
findAll('.gh-member-settings-primary .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;
|
|
|
|
});
|
|
|
|
|
|
|
|
// save new member
|
2020-12-16 12:04:33 +03:00
|
|
|
await fillIn('[data-test-input="member-name"]', 'New Name');
|
|
|
|
await blur('[data-test-input="member-name"]');
|
2019-11-28 14:30:21 +03:00
|
|
|
|
2020-12-16 12:04:33 +03:00
|
|
|
await fillIn('[data-test-input="member-email"]', 'example@domain.com');
|
|
|
|
await blur('[data-test-input="member-email"]');
|
2019-11-28 14:30:21 +03:00
|
|
|
|
|
|
|
await click('[data-test-button="save"]');
|
|
|
|
|
2019-12-03 12:05:56 +03:00
|
|
|
await wait();
|
2019-11-28 14:30:21 +03:00
|
|
|
|
2020-12-16 12:04:33 +03:00
|
|
|
expect(find('[data-test-input="member-name"]').value, 'name has been preserved')
|
2019-12-03 07:24:16 +03:00
|
|
|
.to.equal('New Name');
|
2020-02-21 11:12:35 +03:00
|
|
|
|
2020-12-16 12:04:33 +03:00
|
|
|
expect(find('[data-test-input="member-email"]').value, 'email has been preserved')
|
2020-02-21 11:12:35 +03:00
|
|
|
.to.equal('example@domain.com');
|
2019-11-28 14:30:21 +03:00
|
|
|
});
|
2021-04-08 14:06:27 +03:00
|
|
|
|
2021-10-01 16:57:31 +03:00
|
|
|
it('can bulk delete members', async function () {
|
|
|
|
// members to be kept
|
|
|
|
this.server.createList('member', 6);
|
2021-04-08 14:06:27 +03:00
|
|
|
|
2021-10-01 16:57:31 +03:00
|
|
|
// imported members to be deleted
|
|
|
|
const label = this.server.create('label');
|
|
|
|
this.server.createList('member', 5, {labels: [label]});
|
2021-04-08 14:06:27 +03:00
|
|
|
|
2021-10-01 16:57:31 +03:00
|
|
|
await visit('/members');
|
|
|
|
|
|
|
|
expect(findAll('[data-test-member]').length).to.equal(11);
|
2021-04-08 14:06:27 +03:00
|
|
|
|
2021-10-01 16:57:31 +03:00
|
|
|
await click('[data-test-button="members-actions"]');
|
2021-04-08 14:06:27 +03:00
|
|
|
|
2021-10-01 16:57:31 +03:00
|
|
|
expect(find('[data-test-button="delete-selected"]')).to.not.exist;
|
2021-04-08 14:06:27 +03:00
|
|
|
|
2021-10-01 16:57:31 +03:00
|
|
|
// a filter is needed for the delete-selected button to show
|
|
|
|
await click('[data-test-button="members-filter-actions"]');
|
|
|
|
await click('.gh-member-label-input-labs input');
|
|
|
|
await click(`[data-test-label-filter="${label.name}"]`);
|
|
|
|
await click(`[data-test-button="members-apply-filter"]`);
|
2021-04-08 14:06:27 +03:00
|
|
|
|
2021-10-01 16:57:31 +03:00
|
|
|
expect(findAll('[data-test-member]').length).to.equal(5);
|
|
|
|
expect(currentURL()).to.equal('/members?filter=label%3A%5Blabel-0%5D');
|
2021-04-08 14:06:27 +03:00
|
|
|
|
2021-10-01 16:57:31 +03:00
|
|
|
await click('[data-test-button="members-actions"]');
|
2021-04-08 14:06:27 +03:00
|
|
|
|
2021-10-01 16:57:31 +03:00
|
|
|
expect(find('[data-test-button="delete-selected"]')).to.exist;
|
2021-04-08 14:06:27 +03:00
|
|
|
|
2021-10-01 16:57:31 +03:00
|
|
|
await click('[data-test-button="delete-selected"]');
|
2021-04-08 14:06:27 +03:00
|
|
|
|
2021-10-01 16:57:31 +03:00
|
|
|
expect(find('[data-test-modal="delete-members"]')).to.exist;
|
|
|
|
expect(find('[data-test-text="delete-count"]')).to.have.text('5 members');
|
2021-04-08 14:06:27 +03:00
|
|
|
|
2022-01-05 15:21:52 +03:00
|
|
|
// ensure export endpoint gets hit with correct query params when deleting
|
|
|
|
let exportQueryParams;
|
|
|
|
this.server.get('/members/upload', (schema, request) => {
|
|
|
|
exportQueryParams = request.queryParams;
|
|
|
|
});
|
|
|
|
|
2021-10-01 16:57:31 +03:00
|
|
|
await click('[data-test-button="confirm"]');
|
2021-04-08 14:06:27 +03:00
|
|
|
|
2022-01-05 15:21:52 +03:00
|
|
|
expect(exportQueryParams).to.deep.equal({filter: 'label:[label-0]', limit: 'all'});
|
|
|
|
|
2021-10-01 16:57:31 +03:00
|
|
|
expect(find('[data-test-text="deleted-count"]')).to.have.text('5 members');
|
|
|
|
expect(find('[data-test-button="confirm"]')).to.not.exist;
|
2022-01-05 15:21:52 +03:00
|
|
|
|
2021-10-01 16:57:31 +03:00
|
|
|
// members filter is reset
|
2022-01-05 15:52:00 +03:00
|
|
|
expect(currentURL()).to.equal('/members');
|
2021-10-01 16:57:31 +03:00
|
|
|
expect(findAll('[data-test-member]').length).to.equal(6);
|
2021-04-08 14:06:27 +03:00
|
|
|
|
2021-10-01 16:57:31 +03:00
|
|
|
await click('[data-test-button="close-modal"]');
|
2021-04-08 14:06:27 +03:00
|
|
|
|
2021-10-01 16:57:31 +03:00
|
|
|
expect(find('[data-test-modal="delete-members"]')).to.not.exist;
|
|
|
|
});
|
2019-01-22 19:23:26 +03:00
|
|
|
});
|
|
|
|
});
|