|
| 1 | +import { render } from '@1024pix/ember-testing-library'; |
| 2 | +import { t } from 'ember-intl/test-support'; |
| 3 | +import PlacesLotsAlert from 'pix-orga/components/places/places-lot-alert'; |
| 4 | +import { STATUSES } from 'pix-orga/models/organization-places-lot'; |
| 5 | +import { module, test } from 'qunit'; |
| 6 | +import sinon from 'sinon'; |
| 7 | + |
| 8 | +import setupIntlRenderingTest from '../../../helpers/setup-intl-rendering'; |
| 9 | + |
| 10 | +module('Integration | Component | Places | PlacesLotsAlert', function (hooks) { |
| 11 | + setupIntlRenderingTest(hooks); |
| 12 | + let store, clock; |
| 13 | + const now = new Date('2021-11-03'); |
| 14 | + |
| 15 | + hooks.beforeEach(function () { |
| 16 | + store = this.owner.lookup('service:store'); |
| 17 | + clock = sinon.useFakeTimers({ now }); |
| 18 | + }); |
| 19 | + |
| 20 | + hooks.afterEach(function () { |
| 21 | + clock.restore(); |
| 22 | + }); |
| 23 | + |
| 24 | + test('it should show an alert with remaining days before places lot expires', async function (assert) { |
| 25 | + // given |
| 26 | + const placesLots = [ |
| 27 | + store.createRecord('organization-places-lot', { |
| 28 | + count: 123, |
| 29 | + activationDate: new Date('2021-11-01'), |
| 30 | + expirationDate: new Date('2021-11-30'), |
| 31 | + status: STATUSES.ACTIVE, |
| 32 | + }), |
| 33 | + ]; |
| 34 | + // when |
| 35 | + const screen = await render(<template><PlacesLotsAlert @placesLots={{placesLots}} /></template>); |
| 36 | + const banner = screen.getByRole('alert', { value: t('banners.last-places-lot-available.message') }); |
| 37 | + // then |
| 38 | + assert.strictEqual(banner.outerText, t('banners.last-places-lot-available.message', { days: 27 })); |
| 39 | + }); |
| 40 | + test('it should not show an alert if there is one active lot that has an expiration date in more than 1 month', async function (assert) { |
| 41 | + // given |
| 42 | + const placesLots = [ |
| 43 | + store.createRecord('organization-places-lot', { |
| 44 | + count: 123, |
| 45 | + activationDate: new Date('2021-11-01'), |
| 46 | + expirationDate: new Date('2021-11-07'), |
| 47 | + status: STATUSES.ACTIVE, |
| 48 | + }), |
| 49 | + store.createRecord('organization-places-lot', { |
| 50 | + count: 123, |
| 51 | + activationDate: new Date('2021-11-01'), |
| 52 | + expirationDate: new Date('2021-12-03'), |
| 53 | + status: STATUSES.ACTIVE, |
| 54 | + }), |
| 55 | + ]; |
| 56 | + // when |
| 57 | + const screen = await render(<template><PlacesLotsAlert @placesLots={{placesLots}} /></template>); |
| 58 | + |
| 59 | + // then |
| 60 | + assert.notOk(screen.queryByRole('alert', { value: t('banners.last-places-lot-available.message') })); |
| 61 | + }); |
| 62 | + test('it should not show an alert if remaining days before places lot expires in more than 30 days', async function (assert) { |
| 63 | + // given |
| 64 | + const placesLots = [ |
| 65 | + store.createRecord('organization-places-lot', { |
| 66 | + count: 123, |
| 67 | + activationDate: new Date('2021-11-01'), |
| 68 | + expirationDate: new Date('2021-12-03'), |
| 69 | + status: STATUSES.ACTIVE, |
| 70 | + }), |
| 71 | + ]; |
| 72 | + // when |
| 73 | + const screen = await render(<template><PlacesLotsAlert @placesLots={{placesLots}} /></template>); |
| 74 | + |
| 75 | + // then |
| 76 | + assert.notOk(screen.queryByRole('alert', { value: t('banners.last-places-lot-available.message') })); |
| 77 | + }); |
| 78 | + test('it should not show alert if there is `PENDING` placesLots', async function (assert) { |
| 79 | + // given |
| 80 | + const placesLots = [ |
| 81 | + store.createRecord('organization-places-lot', { |
| 82 | + count: 123, |
| 83 | + activationDate: new Date('2021-11-01'), |
| 84 | + expirationDate: new Date('2021-11-30'), |
| 85 | + status: STATUSES.ACTIVE, |
| 86 | + }), |
| 87 | + store.createRecord('organization-places-lot', { |
| 88 | + count: 123, |
| 89 | + activationDate: new Date('2021-12-01'), |
| 90 | + expirationDate: new Date('2021-12-30'), |
| 91 | + status: STATUSES.PENDING, |
| 92 | + }), |
| 93 | + ]; |
| 94 | + // when |
| 95 | + const screen = await render(<template><PlacesLotsAlert @placesLots={{placesLots}} /></template>); |
| 96 | + |
| 97 | + // then |
| 98 | + assert.notOk(screen.queryByRole('alert', { value: t('banners.last-places-lot-available.message') })); |
| 99 | + }); |
| 100 | + test('it should not show alert if there is no ACTIVE placesLots', async function (assert) { |
| 101 | + // given |
| 102 | + const placesLots = [ |
| 103 | + store.createRecord('organization-places-lot', { |
| 104 | + count: 123, |
| 105 | + activationDate: new Date('2020-12-01'), |
| 106 | + expirationDate: new Date('2020-12-30'), |
| 107 | + status: STATUSES.EXPIRED, |
| 108 | + }), |
| 109 | + ]; |
| 110 | + // when |
| 111 | + const screen = await render(<template><PlacesLotsAlert @placesLots={{placesLots}} /></template>); |
| 112 | + |
| 113 | + // then |
| 114 | + assert.notOk(screen.queryByRole('alert', { value: t('banners.last-places-lot-available.message') })); |
| 115 | + }); |
| 116 | + test('it should not show alert if there is no placesLots', async function (assert) { |
| 117 | + // given |
| 118 | + const placesLots = []; |
| 119 | + // when |
| 120 | + const screen = await render(<template><PlacesLotsAlert @placesLots={{placesLots}} /></template>); |
| 121 | + |
| 122 | + // then |
| 123 | + assert.notOk(screen.queryByRole('alert', { value: t('banners.last-places-lot-available.message') })); |
| 124 | + }); |
| 125 | +}); |
0 commit comments