Files
threshold-ui/addons/core/tests/integration/helpers/relative-datetime-live-test.js
T

69 lines
2.3 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
2022-08-26 12:22:24 -04:00
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
2023-01-09 08:48:49 -08:00
import { setupIntl } from 'ember-intl/test-support';
2022-08-26 12:22:24 -04:00
module('Integration | Helper | relative-datetime-live', function (hooks) {
setupRenderingTest(hooks);
2023-01-09 08:48:49 -08:00
setupIntl(hooks);
2022-08-26 12:22:24 -04:00
let now;
2022-08-26 12:22:24 -04:00
test('it renders relative date in "time" ago format', async function (assert) {
assert.expect(8);
now = Date.now();
this.date = now - 100 - 30 * 1000;
2022-08-26 12:22:24 -04:00
await render(hbs`{{relative-datetime-live this.date}}`);
assert.dom(this.element).hasText('30 seconds ago');
now = Date.now();
this.date = now - 1000 - 30 * 60 * 1000;
2022-08-26 12:22:24 -04:00
await render(hbs`{{relative-datetime-live this.date}}`);
assert.dom(this.element).hasText('30 minutes ago');
now = Date.now();
this.date = now - 1000 - 23 * 60 * 60 * 1000;
2022-08-26 12:22:24 -04:00
await render(hbs`{{relative-datetime-live this.date}}`);
assert.dom(this.element).hasText('23 hours ago');
now = Date.now();
this.date = now - 1000 - 23 * 24 * 60 * 60 * 1000;
2022-08-26 12:22:24 -04:00
await render(hbs`{{relative-datetime-live this.date}}`);
assert.dom(this.element).hasText('23 days ago');
now = Date.now();
this.date = now - 1000 - 8 * 31 * 24 * 60 * 60 * 1000;
2022-08-26 12:22:24 -04:00
await render(hbs`{{relative-datetime-live this.date}}`);
assert.dom(this.element).hasText('8 months ago');
now = Date.now();
this.date = now - 1000 - 23 * 12 * 31 * 24 * 60 * 60 * 1000;
2022-08-26 12:22:24 -04:00
await render(hbs`{{relative-datetime-live this.date}}`);
assert.dom(this.element).hasText('23 years ago');
now = Date.now();
this.date = now + 7 * 31 * 24 * 60 * 60 * 1000;
2022-08-26 12:22:24 -04:00
await render(hbs`{{relative-datetime-live this.date}}`);
assert.dom(this.element).hasText('in 7 months');
now = Date.now();
this.date = now + 1000 + 22 * 12 * 31 * 24 * 60 * 60 * 1000;
2022-08-26 12:22:24 -04:00
await render(hbs`{{relative-datetime-live this.date}}`);
assert.dom(this.element).hasText('in 22 years');
});
2023-02-03 17:53:30 -05:00
test('it renders nothing when there is no date', async function (assert) {
assert.expect(1);
this.date = null;
await render(hbs`{{relative-datetime-live this.date}}`);
assert.dom(this.element).hasText('');
});
2022-08-26 12:22:24 -04:00
});