Ghost/ghost/admin/tests/acceptance/offers-test.js
Kevin Ansfield fa84808048 Dropped ember-cli-moment-shim dependency
no issue

Since `ember-moment@10.0` it's not been necessary to use the `ember-cli-moment-shim` package, with `moment` instead being usable directly via `ember-auto-import`. Getting rid of the shim package is necessary for compatibility with `embroider`, Ember's new build tooling.

- dropped `ember-cli-moment-shim` dependency
- added `moment-timezone` dependency and updated all imports to reflect the different package
- worked around `ember-power-calendar` having `ember-cli-moment-shim` as a sub-dependency
  - added empty in-repo-addon `ember-power-calendar-moment` to avoid `ember-power-calendar` complaining about a missing package
  - added `ember-power-calendar-utils` in-repo-addon that is a copy of `ember-power-calendar-moment` but without the build-time renaming of the tree for better compatibility with embroider
2022-09-24 13:28:23 +02:00

93 lines
3.4 KiB
JavaScript

import moment from 'moment-timezone';
import {authenticateSession, invalidateSession} from 'ember-simple-auth/test-support';
import {beforeEach, describe, it} from 'mocha';
import {blur, click, currentURL, fillIn, find, findAll, settled} 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 () {
this.server.loadFixtures('tiers');
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 () {
const tier = this.server.create('tier');
let offer1 = this.server.create('offer', {tier: {id: tier.id}, createdAt: moment.utc().subtract(1, 'day').valueOf()});
this.server.create('offer', {tier: {id: tier.id}, createdAt: moment.utc().subtract(2, 'day').valueOf()});
await visit('/offers');
await settled();
// 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 settled();
// 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"]');
// lands on correct page
expect(currentURL(), 'currentURL').to.equal('/offers');
});
});
});