2023-12-04 09:13:32 -08:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2024-05-31 11:29:24 -07:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-12-04 09:13:32 -08:00
|
|
|
*/
|
|
|
|
|
|
2023-11-28 17:42:22 -05:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
|
import { render } from '@ember/test-helpers';
|
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
|
import { setupIntl } from 'ember-intl/test-support';
|
|
|
|
|
|
|
|
|
|
module('Integration | Helper | time-remaining', function (hooks) {
|
|
|
|
|
setupRenderingTest(hooks);
|
2024-09-06 10:32:30 -07:00
|
|
|
setupIntl(hooks, 'en-us');
|
2023-11-28 17:42:22 -05:00
|
|
|
|
2024-09-13 09:43:08 -05:00
|
|
|
test('it calculates the correct time remainin with less than 24 hours', async function (assert) {
|
2023-11-28 17:42:22 -05:00
|
|
|
this.set('expirationTime', new Date(Date.now() + 1000 * 60 * 60 * 24));
|
|
|
|
|
|
|
|
|
|
await render(hbs`{{time-remaining this.expirationTime}}`);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(this.element.textContent.trim(), '23:59:59 remaining');
|
|
|
|
|
});
|
|
|
|
|
|
2024-09-13 09:43:08 -05:00
|
|
|
test('it calculates the correct time remaining with more than 24 hours', async function (assert) {
|
|
|
|
|
this.set('expirationTime', new Date(Date.now() + 1001 * 60 * 60 * 24));
|
|
|
|
|
|
|
|
|
|
await render(hbs`{{time-remaining this.expirationTime}}`);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
|
this.element.textContent.trim(),
|
|
|
|
|
'1 day, 0:01:26 remaining',
|
|
|
|
|
);
|
|
|
|
|
});
|
2023-11-28 17:42:22 -05:00
|
|
|
|
2024-09-13 09:43:08 -05:00
|
|
|
test('it calculates the correct time remaining with more than a week', async function (assert) {
|
|
|
|
|
this.set('expirationTime', new Date(Date.now() + 1001 * 60 * 60 * 24 * 8));
|
|
|
|
|
|
|
|
|
|
await render(hbs`{{time-remaining this.expirationTime}}`);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
|
this.element.textContent.trim(),
|
|
|
|
|
'1 wk, 1 day, 0:11:31 remaining',
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('it handles negative time remaining', async function (assert) {
|
2023-11-28 17:42:22 -05:00
|
|
|
this.set('expirationTime', new Date(Date.now() - 1000 * 60 * 60 * 24));
|
|
|
|
|
|
|
|
|
|
await render(hbs`{{time-remaining this.expirationTime}}`);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(this.element.textContent.trim(), '0:00:00 remaining');
|
|
|
|
|
});
|
|
|
|
|
});
|