Files
threshold-ui/addons/core/tests/integration/helpers/relative-datetime-live-test.js
T
hashicorp-copywrite[bot]andCameron Perera 3d610427d0 [COMPLIANCE] Add Copyright and License Headers (#1617)
* [COMPLIANCE] Add Copyright and License Headers

* chore: 🤖 update Copyright headers to satisfy our lint rules

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
2023-03-01 09:39:41 -06:00

70 lines
2.3 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupIntl } from 'ember-intl/test-support';
module('Integration | Helper | relative-datetime-live', function (hooks) {
setupRenderingTest(hooks);
setupIntl(hooks);
let now;
test('it renders relative date in "time" ago format', async function (assert) {
assert.expect(8);
now = Date.now();
this.date = now - 100 - 30 * 1000;
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;
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;
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;
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;
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;
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;
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;
await render(hbs`{{relative-datetime-live this.date}}`);
assert.dom(this.element).hasText('in 22 years');
});
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('');
});
});