2022-03-31 13:06:21 +03:00
|
|
|
import {authenticateSession} from 'ember-simple-auth/test-support';
|
2022-04-28 11:50:27 +03:00
|
|
|
import {click, currentURL, fillIn, find, findAll} from '@ember/test-helpers';
|
2022-03-31 13:06:21 +03:00
|
|
|
import {expect} from 'chai';
|
|
|
|
import {setupApplicationTest} from 'ember-mocha';
|
|
|
|
import {setupMirage} from 'ember-cli-mirage/test-support';
|
|
|
|
import {visit} from '../../helpers/visit';
|
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
async function checkValidationError(errors) {
|
|
|
|
// Create the newsletter
|
|
|
|
await click('[data-test-button="save-newsletter"]');
|
|
|
|
|
|
|
|
// @todo: at the moment, the tabs don't open on error automatically
|
|
|
|
// we need to remove these lines when this is fixed
|
|
|
|
// and replace it with something like ± checkTabOpen('genexral')
|
|
|
|
// await openTab('general.name');
|
|
|
|
|
|
|
|
for (const selector of Object.keys(errors)) {
|
|
|
|
expect(findAll(selector).length, 'field ' + selector + ' is not visible').to.equal(1);
|
|
|
|
expect(findAll(selector + ' + .response').length, 'error message is displayed').to.equal(1);
|
|
|
|
expect(find(selector + ' + .response').textContent).to.match(errors[selector]);
|
|
|
|
}
|
2022-03-31 13:06:21 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
// Check button is in error state
|
|
|
|
expect(find('[data-test-button="save-newsletter"] > [data-test-task-button-state="failure"]')).to.exist;
|
|
|
|
}
|
2022-03-31 13:06:21 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
async function checkSave(options) {
|
|
|
|
const name = options.edit ? 'edit' : 'create';
|
2022-03-31 13:06:21 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
// Create the newsletter
|
|
|
|
await click('[data-test-button="save-newsletter"]');
|
2022-03-31 13:06:21 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
// No errors
|
|
|
|
expect(findAll('.error > .response').length, 'error message is displayed').to.equal(0);
|
2022-03-31 13:06:21 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
if (options.verifyEmail) {
|
|
|
|
expect(find('[data-test-modal="confirm-newsletter-email"]'), 'Confirm email modal').to.exist;
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
// Check message
|
|
|
|
if (typeof verifyEmail !== 'boolean') {
|
|
|
|
const t = find('[data-test-modal="confirm-newsletter-email"] p').textContent.trim().replace(/\s+/g, ' ');
|
|
|
|
expect(t).to.match(options.verifyEmail, t);
|
|
|
|
}
|
|
|
|
await click('[data-test-button="confirm-newsletter-email"]');
|
|
|
|
}
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
// Check if modal closes on save
|
|
|
|
expect(find(`[data-test-modal="${name}-newsletter"]`), 'Newsletter modal should disappear after saving').to.not.exist;
|
|
|
|
}
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
async function checkCancel(options) {
|
|
|
|
const name = options.edit ? 'edit' : 'create';
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
// Create the newsletter
|
|
|
|
await click('[data-test-button="cancel-newsletter"]');
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
if (options.shouldConfirm) {
|
|
|
|
expect(find('[data-test-modal="unsaved-settings"]'), 'Confirm unsaved settings modal should be visible').to.exist;
|
|
|
|
await click('[data-test-leave-button]');
|
2022-04-28 11:50:27 +03:00
|
|
|
}
|
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
// Check if modal closes on save
|
|
|
|
expect(find(`[data-test-modal="${name}-newsletter"]`), 'Newsletter modal should disappear after canceling').to.not.exist;
|
|
|
|
}
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
async function openTab(name, optional = true) {
|
|
|
|
const generalToggleSelector = '[data-test-nav-toggle="' + name + '"]';
|
|
|
|
const generalToggle = find(generalToggleSelector);
|
|
|
|
const doesExist = !!generalToggle;
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
if (!doesExist && !optional) {
|
|
|
|
throw new Error('Expected tab ' + name + ' to exist');
|
|
|
|
}
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
if (doesExist && !generalToggle.classList.contains('active')) {
|
|
|
|
await click(generalToggleSelector);
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
if (!generalToggle.classList.contains('active')) {
|
|
|
|
throw new Error('Could not open ' + name + ' tab');
|
2022-04-28 11:50:27 +03:00
|
|
|
}
|
|
|
|
}
|
2022-06-02 12:21:29 +03:00
|
|
|
}
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
async function closeTab(name, optional = true) {
|
|
|
|
const generalToggleSelector = '[data-test-nav-toggle="' + name + '"]';
|
|
|
|
const generalToggle = find(generalToggleSelector);
|
|
|
|
const doesExist = !!generalToggle;
|
2022-05-18 16:57:02 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
if (!doesExist && !optional) {
|
|
|
|
throw new Error('Expected tab ' + name + ' to exist');
|
|
|
|
}
|
2022-05-18 16:57:02 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
if (doesExist && generalToggle.classList.contains('active')) {
|
|
|
|
await click(generalToggleSelector);
|
2022-05-18 16:57:02 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
if (generalToggle.classList.contains('active')) {
|
|
|
|
throw new Error('Could not close ' + name + ' tab');
|
|
|
|
}
|
2022-05-18 16:57:02 +03:00
|
|
|
}
|
2022-06-02 12:21:29 +03:00
|
|
|
}
|
2022-05-18 16:57:02 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
async function fillName(name) {
|
|
|
|
await openTab('general.name');
|
|
|
|
await fillIn('input#newsletter-title', name);
|
|
|
|
}
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
describe('Acceptance: Settings - Newsletters', function () {
|
|
|
|
const hooks = setupApplicationTest();
|
|
|
|
setupMirage(hooks);
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
beforeEach(async function () {
|
|
|
|
this.server.loadFixtures('configs', 'newsletters');
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
const role = this.server.create('role', {name: 'Owner'});
|
|
|
|
this.server.create('user', {roles: [role]});
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
return await authenticateSession();
|
|
|
|
});
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
it('redirects old path', async function () {
|
|
|
|
await visit('/settings/members-email');
|
|
|
|
expect(currentURL()).to.equal('/settings/newsletters');
|
|
|
|
});
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
it('can manage open rate tracking', async function () {
|
|
|
|
this.server.db.settings.update({key: 'email_track_opens'}, {value: 'true'});
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
await visit('/settings/newsletters');
|
|
|
|
expect(find('[data-test-checkbox="email-track-opens"]')).to.be.checked;
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 12:21:29 +03:00
|
|
|
await click('[data-test-label="email-track-opens"]');
|
|
|
|
expect(find('[data-test-checkbox="email-track-opens"]')).to.not.be.checked;
|
|
|
|
|
|
|
|
await click('[data-test-button="save-members-settings"]');
|
|
|
|
|
|
|
|
expect(this.server.db.settings.findBy({key: 'email_track_opens'}).value).to.equal(false);
|
|
|
|
});
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
describe('Creating newsletters', function () {
|
|
|
|
it('can create new newsletter', async function () {
|
|
|
|
await visit('/settings/newsletters');
|
|
|
|
await click('[data-test-button="add-newsletter"]');
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Check if modal opens
|
|
|
|
expect(find('[data-test-modal="create-newsletter"]'), 'Create newsletter modal').to.exist;
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Fill in the newsletter name
|
|
|
|
await fillName('My new newsletter');
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Fill in the newsletter description
|
|
|
|
await fillIn('textarea#newsletter-description', 'My newsletter description');
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
await checkSave({});
|
|
|
|
});
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
it('validates create newsletter before saving', async function () {
|
|
|
|
await visit('/settings/newsletters');
|
|
|
|
await click('[data-test-button="add-newsletter"]');
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Check if modal opens
|
|
|
|
expect(find('[data-test-modal="create-newsletter"]'), 'Create newsletter modal').to.exist;
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Invalid name error when you try to save
|
|
|
|
await checkValidationError({'input#newsletter-title': /Please enter a name./});
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Fill in the newsletter name
|
|
|
|
await fillName('My new newsletter');
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Everything should be valid
|
|
|
|
await checkSave({});
|
|
|
|
});
|
2022-06-02 12:21:29 +03:00
|
|
|
|
|
|
|
it('checks limits when creating a newsletter', async function () {
|
|
|
|
const config = this.server.db.configs.find(1);
|
|
|
|
config.hostSettings = {
|
|
|
|
limits: {
|
|
|
|
newsletters: {
|
|
|
|
max: 1,
|
|
|
|
error: 'Your plan supports up to {{max}} newsletters. Please upgrade to add more.'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.server.db.configs.update(1, config);
|
|
|
|
|
|
|
|
await visit('/settings/newsletters');
|
|
|
|
await click('[data-test-button="add-newsletter"]');
|
|
|
|
|
|
|
|
// Check if modal doesn't open
|
|
|
|
expect(find('[data-test-modal="create-newsletter"]'), 'Create newsletter modal').not.to.exist;
|
|
|
|
|
|
|
|
// Check limits modal is shown
|
|
|
|
expect(find('[data-test-modal="limits/multiple-newsletters"]'), 'Limits modal').to.exist;
|
|
|
|
|
|
|
|
// Check can close modal
|
|
|
|
await click('[data-test-button="cancel-upgrade"]');
|
|
|
|
|
|
|
|
// Check modal is closed
|
|
|
|
expect(find('[data-test-modal="limits/multiple-newsletters"]'), 'Limits modal').not.to.exist;
|
|
|
|
});
|
2022-04-28 11:50:27 +03:00
|
|
|
});
|
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
describe('Editing newsletters', function () {
|
|
|
|
it('can edit via menu if multiple newsletters', async function () {
|
|
|
|
// Create an extra newsletter
|
|
|
|
this.server.create('newsletter', {status: 'active', name: 'test newsletter', slug: 'test-newsletter'});
|
|
|
|
await visit('/settings/newsletters');
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
await click('[data-test-newsletter-menu-trigger]');
|
|
|
|
await click('[data-test-button="customize-newsletter"]');
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Check if modal opens
|
|
|
|
expect(find('[data-test-modal="edit-newsletter"]'), 'Edit newsletter modal').to.exist;
|
|
|
|
});
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
it('validates edit fields before saving', async function () {
|
|
|
|
await visit('/settings/newsletters');
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// When we only have a single newsletter, the customize button is shown instead of the menu button
|
|
|
|
await click('[data-test-button="customize-newsletter"]');
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Check if modal opens
|
|
|
|
expect(find('[data-test-modal="edit-newsletter"]'), 'Edit newsletter modal').to.exist;
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Clear newsletter name
|
|
|
|
await fillName('');
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Invalid name error when you try to save
|
|
|
|
await checkValidationError({'input#newsletter-title': /Please enter a name./});
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Fill in the newsletter name
|
|
|
|
await fillName('My new newsletter');
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Enter an invalid email
|
|
|
|
await openTab('general.email');
|
|
|
|
await fillIn('input#newsletter-sender-email', 'invalid-email');
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Check if it complains about the invalid email
|
|
|
|
await checkValidationError({
|
|
|
|
'input#newsletter-sender-email': /Invalid email./
|
|
|
|
});
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
await fillIn('input#newsletter-sender-email', 'valid-email@email.com');
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Everything should be valid
|
|
|
|
await checkSave({
|
|
|
|
edit: true,
|
|
|
|
verifyEmail: /default email address \(noreply/
|
|
|
|
});
|
2022-05-18 14:12:43 +03:00
|
|
|
});
|
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
it('can open / close all tabs', async function () {
|
|
|
|
await visit('/settings/newsletters');
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// When we only have a single newsletter, the customize button is shown instead of the menu button
|
|
|
|
await click('[data-test-button="customize-newsletter"]');
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Check if modal opens
|
|
|
|
expect(find('[data-test-modal="edit-newsletter"]'), 'Edit newsletter modal').to.exist;
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
await openTab('general.name', false);
|
|
|
|
await closeTab('general.name', false);
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
await openTab('general.email', false);
|
|
|
|
await closeTab('general.email', false);
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
await openTab('general.member', false);
|
|
|
|
await closeTab('general.member', false);
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
await openTab('design.header', false);
|
|
|
|
await closeTab('design.header', false);
|
2022-05-18 14:12:43 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
await openTab('design.body', false);
|
|
|
|
await closeTab('design.body', false);
|
2022-04-28 11:50:27 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
await openTab('design.footer', false);
|
|
|
|
await closeTab('design.footer', false);
|
2022-04-28 11:50:27 +03:00
|
|
|
});
|
2022-05-18 16:57:02 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
it('shows current sender email in verify modal', async function () {
|
|
|
|
this.server.create('newsletter', {status: 'active', name: 'test newsletter', slug: 'test-newsletter', senderEmail: 'test@example.com'});
|
2022-05-18 16:57:02 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
await visit('/settings/newsletters');
|
2022-05-18 16:57:02 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Edit the last newsletter
|
|
|
|
await click('[data-test-newsletter="test-newsletter"] [data-test-newsletter-menu-trigger]');
|
|
|
|
await click('[data-test-button="customize-newsletter"]');
|
2022-05-18 16:57:02 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Check if modal opens
|
|
|
|
expect(find('[data-test-modal="edit-newsletter"]'), 'Edit newsletter modal').to.exist;
|
2022-05-18 16:57:02 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
await openTab('general.email');
|
|
|
|
await fillIn('input#newsletter-sender-email', 'valid-email@email.com');
|
|
|
|
|
|
|
|
// Everything should be valid
|
|
|
|
await checkSave({
|
|
|
|
edit: true,
|
|
|
|
verifyEmail: /previous email address \(test@example\.com\)/
|
|
|
|
});
|
2022-05-18 16:57:02 +03:00
|
|
|
});
|
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
it('does not ask to confirm saved changes', async function () {
|
2022-05-18 16:57:02 +03:00
|
|
|
await visit('/settings/newsletters');
|
|
|
|
|
|
|
|
// When we only have a single newsletter, the customize button is shown instead of the menu button
|
|
|
|
await click('[data-test-button="customize-newsletter"]');
|
|
|
|
|
|
|
|
// Check if modal opens
|
|
|
|
expect(find('[data-test-modal="edit-newsletter"]'), 'Edit newsletter modal').to.exist;
|
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Make no changes
|
2022-05-18 16:57:02 +03:00
|
|
|
|
|
|
|
// Everything should be valid
|
|
|
|
await checkCancel({
|
|
|
|
edit: true,
|
2022-06-02 11:39:17 +03:00
|
|
|
shouldConfirm: false
|
2022-05-18 16:57:02 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
it('asks to confirm unsaved changes', async function () {
|
|
|
|
async function doCheck(tabName, field) {
|
|
|
|
await visit('/settings/newsletters');
|
|
|
|
|
|
|
|
// When we only have a single newsletter, the customize button is shown instead of the menu button
|
|
|
|
await click('[data-test-button="customize-newsletter"]');
|
|
|
|
|
|
|
|
// Check if modal opens
|
|
|
|
expect(find('[data-test-modal="edit-newsletter"]'), 'Edit newsletter modal').to.exist;
|
|
|
|
|
|
|
|
// Make a change
|
|
|
|
await openTab(tabName, false);
|
|
|
|
if (field.input) {
|
|
|
|
await fillIn(field.input, field.value ?? 'my changed value');
|
|
|
|
} else if (field.toggle) {
|
|
|
|
await click(field.toggle);
|
|
|
|
} else if (field.dropdown) {
|
|
|
|
// Open dropdown
|
|
|
|
await click(`${field.dropdown} .ember-basic-dropdown-trigger`);
|
|
|
|
|
|
|
|
// Click first not-selected option
|
|
|
|
await click(`${field.dropdown} li.ember-power-select-option[aria-current="false"]`);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Everything should be valid
|
|
|
|
await checkCancel({
|
|
|
|
edit: true,
|
|
|
|
shouldConfirm: true
|
|
|
|
});
|
|
|
|
}
|
2022-05-18 16:57:02 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// General name
|
|
|
|
await doCheck('general.name', {
|
|
|
|
input: '#newsletter-title'
|
|
|
|
});
|
2022-05-18 16:57:02 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
await doCheck('general.name', {
|
|
|
|
input: '#newsletter-description'
|
|
|
|
});
|
2022-05-18 16:57:02 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// General email
|
|
|
|
await doCheck('general.email', {
|
|
|
|
input: '#newsletter-sender-name'
|
|
|
|
});
|
2022-05-18 16:57:02 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
await doCheck('general.email', {
|
|
|
|
input: '#newsletter-sender-email'
|
|
|
|
});
|
2022-05-18 16:57:02 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
await doCheck('general.email', {
|
|
|
|
input: '#newsletter-reply-to',
|
|
|
|
value: 'support'
|
|
|
|
});
|
2022-05-18 16:57:02 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Member settings
|
|
|
|
await doCheck.call(this, 'general.member', {
|
|
|
|
toggle: '[data-test-toggle="subscribeOnSignup"]'
|
|
|
|
});
|
2022-05-18 16:57:02 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Design header
|
|
|
|
await doCheck.call(this, 'design.header', {
|
|
|
|
toggle: '[data-test-toggle="showHeaderTitle"]'
|
|
|
|
});
|
2022-05-18 16:57:02 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
await doCheck.call(this, 'design.header', {
|
|
|
|
toggle: '[data-test-toggle="showHeaderName"]'
|
|
|
|
});
|
|
|
|
|
|
|
|
// Design body
|
|
|
|
await doCheck.call(this, 'design.body', {
|
|
|
|
dropdown: '[data-test-input="titleFontCategory"]'
|
|
|
|
});
|
|
|
|
|
|
|
|
await doCheck.call(this, 'design.body', {
|
|
|
|
toggle: '#newsletter-title-alignment button:not(.gh-btn-group-selected)'
|
|
|
|
});
|
|
|
|
|
|
|
|
await doCheck.call(this, 'design.body', {
|
|
|
|
dropdown: '[data-test-input="bodyFontCategory"]'
|
|
|
|
});
|
|
|
|
|
|
|
|
await doCheck.call(this, 'design.body', {
|
|
|
|
toggle: '#show-feature-image'
|
|
|
|
});
|
|
|
|
|
|
|
|
// Design footer
|
|
|
|
await doCheck('design.footer', {
|
|
|
|
input: '[contenteditable="true"]'
|
|
|
|
});
|
2022-05-18 16:57:02 +03:00
|
|
|
});
|
2022-06-02 11:39:17 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Archiving newsletters', function () {
|
|
|
|
it('can archive newsletters', async function () {
|
|
|
|
// Create an extra newsletter, because we cannot archive the last one
|
|
|
|
this.server.create('newsletter', {status: 'active', name: 'test newsletter', slug: 'test-newsletter'});
|
|
|
|
await visit('/settings/newsletters');
|
|
|
|
|
|
|
|
// Check total newsletters shown
|
|
|
|
expect(findAll('[data-test-newsletter]').length, 'Total newsletters shown').to.equal(2);
|
2022-05-18 16:57:02 +03:00
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
// Toggle is hidden
|
|
|
|
expect(find('[data-test-dropdown="newsletter-status-filter"] .ember-power-select-trigger')).not.to.exist;
|
|
|
|
|
|
|
|
await click('[data-test-newsletter-menu-trigger]');
|
|
|
|
await click('[data-test-button="archive-newsletter"]');
|
|
|
|
|
|
|
|
// Check if confimation modal opens
|
|
|
|
expect(find('[data-test-modal="confirm-newsletter-archive"]'), 'Archive newsletter modal').to.exist;
|
|
|
|
|
|
|
|
// Confirm archive
|
|
|
|
await click('[data-test-button="confirm-newsletter-archive"]');
|
|
|
|
|
|
|
|
// Check total newsletters equals 1
|
|
|
|
expect(findAll('[data-test-newsletter]').length, 'Total newsletters shown').to.equal(1);
|
|
|
|
|
|
|
|
// Toggle is shown now
|
|
|
|
expect(find('[data-test-dropdown="newsletter-status-filter"] .ember-power-select-trigger')).to.exist;
|
2022-05-18 16:57:02 +03:00
|
|
|
});
|
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
it('can reactivate newsletters if only archived newsletter left', async function () {
|
|
|
|
// Create an extra newsletter, to check counts
|
|
|
|
this.server.create('newsletter', {status: 'active', name: 'test newsletter', slug: 'test-newsletter'});
|
|
|
|
|
|
|
|
// Create an archived newsletter, beacuse the toggle is invisible otherwise
|
|
|
|
this.server.create('newsletter', {status: 'archived', name: 'test newsletter 2', slug: 'test-newsletter2'});
|
|
|
|
await visit('/settings/newsletters');
|
|
|
|
|
|
|
|
// Check total newsletters shown
|
|
|
|
expect(findAll('[data-test-newsletter]').length, 'Total newsletters shown').to.equal(2);
|
|
|
|
|
|
|
|
// Go to archived newsletters
|
|
|
|
await click('[data-test-dropdown="newsletter-status-filter"] .ember-power-select-trigger');
|
|
|
|
await click('.ember-power-select-option[aria-selected="false"]');
|
|
|
|
|
|
|
|
// Check title okay
|
|
|
|
expect(find('.gh-newsletters .gh-expandable-title').textContent.trim(), 'Title').to.equal('Archived newsletters');
|
|
|
|
|
|
|
|
// Check total newsletters shown
|
|
|
|
expect(findAll('[data-test-newsletter]').length, 'Total archived newsletters shown').to.equal(1);
|
|
|
|
|
|
|
|
// Reactivate the newsletter
|
|
|
|
await click('[data-test-newsletter-menu-trigger]');
|
|
|
|
await click('[data-test-button="reactivate-newsletter"]');
|
|
|
|
|
|
|
|
// Check if confimation modal opens
|
|
|
|
expect(find('[data-test-modal="confirm-newsletter-reactivate"]'), 'Reactivate newsletter modal').to.exist;
|
|
|
|
|
|
|
|
// Confirm archive
|
|
|
|
await click('[data-test-button="confirm-newsletter-reactivate"]');
|
|
|
|
|
|
|
|
// Check automatically went back to all (because no newsletters archived)
|
|
|
|
// Check title okay
|
|
|
|
expect(find('.gh-newsletters .gh-expandable-title').textContent.trim(), 'Title').to.equal('Active newsletters');
|
|
|
|
|
|
|
|
// Check total newsletters shown
|
|
|
|
expect(findAll('[data-test-newsletter]').length, 'Total newsletters shown').to.equal(3);
|
2022-05-18 16:57:02 +03:00
|
|
|
});
|
|
|
|
|
2022-06-02 11:39:17 +03:00
|
|
|
it('can reactivate newsletters', async function () {
|
|
|
|
// Create an extra newsletter, to check counts
|
|
|
|
this.server.create('newsletter', {status: 'active', name: 'test newsletter', slug: 'test-newsletter'});
|
|
|
|
|
|
|
|
// Create an archived newsletter, beacuse the toggle is invisible otherwise
|
|
|
|
this.server.create('newsletter', {status: 'archived', name: 'test newsletter 2', slug: 'test-newsletter2'});
|
|
|
|
this.server.create('newsletter', {status: 'archived', name: 'test newsletter 3', slug: 'test-newsletter3'});
|
|
|
|
await visit('/settings/newsletters');
|
|
|
|
|
|
|
|
// Check total newsletters shown
|
|
|
|
expect(findAll('[data-test-newsletter]').length, 'Total newsletters shown').to.equal(2);
|
|
|
|
|
|
|
|
// Go to archived newsletters
|
|
|
|
await click('[data-test-dropdown="newsletter-status-filter"] .ember-power-select-trigger');
|
|
|
|
await click('.ember-power-select-option[aria-selected="false"]');
|
|
|
|
|
|
|
|
// Check title okay
|
|
|
|
expect(find('.gh-newsletters .gh-expandable-title').textContent.trim(), 'Title').to.equal('Archived newsletters');
|
|
|
|
|
|
|
|
// Check total newsletters shown
|
|
|
|
expect(findAll('[data-test-newsletter]').length, 'Total archived newsletters shown').to.equal(2);
|
|
|
|
|
|
|
|
// Reactivate the newsletter
|
|
|
|
await click('[data-test-newsletter-menu-trigger]');
|
|
|
|
await click('[data-test-button="reactivate-newsletter"]');
|
|
|
|
|
|
|
|
// Check if confimation modal opens
|
|
|
|
expect(find('[data-test-modal="confirm-newsletter-reactivate"]'), 'Reactivate newsletter modal').to.exist;
|
|
|
|
|
|
|
|
// Confirm archive
|
|
|
|
await click('[data-test-button="confirm-newsletter-reactivate"]');
|
|
|
|
|
|
|
|
// Check still showing archived newsletters
|
|
|
|
expect(find('.gh-newsletters .gh-expandable-title').textContent.trim(), 'Title').to.equal('Archived newsletters');
|
|
|
|
|
|
|
|
// Go to active newsletters
|
|
|
|
await click('[data-test-dropdown="newsletter-status-filter"] .ember-power-select-trigger');
|
|
|
|
await click('.ember-power-select-option[aria-selected="false"]');
|
|
|
|
|
|
|
|
// Check automatically went back to all (because no newsletters archived)
|
|
|
|
// Check title okay
|
|
|
|
expect(find('.gh-newsletters .gh-expandable-title').textContent.trim(), 'Title').to.equal('Active newsletters');
|
|
|
|
|
|
|
|
// Check total newsletters shown
|
|
|
|
expect(findAll('[data-test-newsletter]').length, 'Total newsletters shown').to.equal(3);
|
2022-05-18 16:57:02 +03:00
|
|
|
});
|
2022-06-02 12:21:29 +03:00
|
|
|
|
|
|
|
it('checks limits when reactivating a newsletter', async function () {
|
|
|
|
const config = this.server.db.configs.find(1);
|
|
|
|
config.hostSettings = {
|
|
|
|
limits: {
|
|
|
|
newsletters: {
|
|
|
|
max: 1,
|
|
|
|
error: 'Your plan supports up to {{max}} newsletters. Please upgrade to add more.'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.server.db.configs.update(1, config);
|
|
|
|
|
|
|
|
// Create an archived newsletter, beacuse the toggle is invisible otherwise
|
|
|
|
this.server.create('newsletter', {status: 'archived', name: 'test newsletter 2', slug: 'test-newsletter2'});
|
|
|
|
await visit('/settings/newsletters');
|
|
|
|
|
|
|
|
// Check total newsletters shown
|
|
|
|
expect(findAll('[data-test-newsletter]').length, 'Total newsletters shown').to.equal(1);
|
|
|
|
|
|
|
|
// Go to archived newsletters
|
|
|
|
await click('[data-test-dropdown="newsletter-status-filter"] .ember-power-select-trigger');
|
|
|
|
await click('.ember-power-select-option[aria-selected="false"]');
|
|
|
|
|
|
|
|
// Check title okay
|
|
|
|
expect(find('.gh-newsletters .gh-expandable-title').textContent.trim(), 'Title').to.equal('Archived newsletters');
|
|
|
|
|
|
|
|
// Check total newsletters shown
|
|
|
|
expect(findAll('[data-test-newsletter]').length, 'Total archived newsletters shown').to.equal(1);
|
|
|
|
|
|
|
|
// Reactivate the newsletter
|
|
|
|
await click('[data-test-newsletter-menu-trigger]');
|
|
|
|
await click('[data-test-button="reactivate-newsletter"]');
|
|
|
|
|
|
|
|
// Check if confimation modal doesn't open
|
|
|
|
expect(find('[data-test-modal="confirm-newsletter-reactivate"]'), 'Reactivate newsletter modal').not.to.exist;
|
|
|
|
|
|
|
|
// Check limits modal is shown
|
|
|
|
expect(find('[data-test-modal="limits/multiple-newsletters"]'), 'Limits modal').to.exist;
|
|
|
|
|
|
|
|
// Check can close modal
|
|
|
|
await click('[data-test-button="cancel-upgrade"]');
|
|
|
|
|
|
|
|
// Check modal is closed
|
|
|
|
expect(find('[data-test-modal="limits/multiple-newsletters"]'), 'Limits modal').not.to.exist;
|
|
|
|
});
|
2022-05-18 16:57:02 +03:00
|
|
|
});
|
2022-04-28 11:50:27 +03:00
|
|
|
});
|