0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Added basic acceptance tests for offers

refs https://github.com/TryGhost/Team/issues/1084
refs https://github.com/TryGhost/Team/issues/1085
This commit is contained in:
Rishabh 2021-10-08 19:45:48 +05:30
parent 1107465398
commit dd0ecf75b9
4 changed files with 130 additions and 18 deletions

View file

@ -270,24 +270,26 @@ export default class OffersController extends Controller {
@action
updateCadence(cadence) {
const [tierId, tierCadence, currency] = cadence.split('-');
this.offer.tier = {
id: tierId
};
this.offer.cadence = tierCadence;
this.offer.currency = currency;
const offerType = this.offer.type;
this.offertypes = [
{
label: '%',
offertype: 'percent'
},
{
label: currency.toUpperCase(),
offertype: 'fixed'
}
];
this.offer.type = offerType;
if (cadence) {
const [tierId, tierCadence, currency] = cadence.split('-');
this.offer.tier = {
id: tierId
};
this.offer.cadence = tierCadence;
this.offer.currency = currency;
const offerType = this.offer.type;
this.offertypes = [
{
label: '%',
offertype: 'percent'
},
{
label: currency.toUpperCase(),
offertype: 'fixed'
}
];
this.offer.type = offerType;
}
}
@action

View file

@ -7,6 +7,7 @@ import mockIntegrations from './config/integrations';
import mockInvites from './config/invites';
import mockLabels from './config/labels';
import mockMembers from './config/members';
import mockOffers from './config/offers';
import mockPages from './config/pages';
import mockPosts from './config/posts';
import mockProducts from './config/products';
@ -74,6 +75,7 @@ export function testConfig() {
mockUsers(this);
mockWebhooks(this);
mockProducts(this);
mockOffers(this);
/* Notifications -------------------------------------------------------- */

View file

@ -0,0 +1,12 @@
import faker from 'faker';
import moment from 'moment';
import {Factory} from 'ember-cli-mirage';
let randomDate = function randomDate(start = moment().subtract(30, 'days').toDate(), end = new Date()) {
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
};
export default Factory.extend({
name() { return `${faker.name.firstName()} ${faker.name.lastName()}`; },
createdAt() { return randomDate(); }
});

View file

@ -0,0 +1,96 @@
import enableLabsFlag from '../helpers/enable-labs-flag';
import moment from 'moment';
import wait from 'ember-test-helpers/wait';
import {authenticateSession, invalidateSession} from 'ember-simple-auth/test-support';
import {beforeEach, describe, it} from 'mocha';
import {blur, click, currentURL, fillIn, find, findAll} from '@ember/test-helpers';
import {expect} from 'chai';
import {setupApplicationTest} from 'ember-mocha';
import {setupMirage} from 'ember-cli-mirage/test-support';
import {timeout} from 'ember-concurrency';
import {visit} from '../helpers/visit';
describe('Acceptance: Offers', function () {
let hooks = setupApplicationTest();
setupMirage(hooks);
it('redirects to signin when not authenticated', async function () {
await invalidateSession();
await visit('/offers');
expect(currentURL()).to.equal('/signin');
});
it('redirects non-admins to site', async function () {
let role = this.server.create('role', {name: 'Editor'});
this.server.create('user', {roles: [role]});
await authenticateSession();
await visit('/offers');
expect(currentURL()).to.equal('/site');
expect(find('[data-test-nav="offers"]'), 'sidebar link')
.to.not.exist;
});
describe('as owner', function () {
beforeEach(async function () {
enableLabsFlag(this.server, 'offers');
let role = this.server.create('role', {name: 'Owner'});
this.server.create('user', {roles: [role]});
return await authenticateSession();
});
it('it renders, can be navigated, can edit offer', async function () {
let offer1 = this.server.create('offer', {createdAt: moment.utc().subtract(1, 'day').valueOf()});
this.server.create('offer', {createdAt: moment.utc().subtract(2, 'day').valueOf()});
await visit('/offers');
// second wait is needed for the vertical-collection to settle
await wait();
// lands on correct page
expect(currentURL(), 'currentURL').to.equal('/offers');
// it has correct page title
expect(document.title, 'page title').to.equal('Offers - Test Blog');
// it lists all offers
expect(findAll('[data-test-list="offers-list-item"]').length, 'offers list count')
.to.equal(2);
let offer = find('[data-test-list="offers-list-item"]');
expect(offer.querySelector('[data-test-list="offer-name"] h3').textContent, 'offer list item name')
.to.equal(offer1.name);
await visit(`/offers/${offer1.id}`);
// second wait is needed for the offer details to settle
await wait();
// it shows selected offer form
expect(find('[data-test-input="offer-name"]').value, 'loads correct offer into form')
.to.equal(offer1.name);
// trigger save
await fillIn('[data-test-input="offer-name"]', 'New Name');
await blur('[data-test-input="offer-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="offers-back"]');
await wait();
// lands on correct page
expect(currentURL(), 'currentURL').to.equal('/offers');
});
});
});