2018-11-14 00:55:07 +00:00
|
|
|
import { module, test } from 'qunit';
|
2021-02-08 20:13:00 +00:00
|
|
|
import { subMinutes } from 'date-fns';
|
2018-11-14 00:55:07 +00:00
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
import { dateFromNow } from '../../../helpers/date-from-now';
|
2021-02-08 20:13:00 +00:00
|
|
|
import { render } from '@ember/test-helpers';
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2018-11-14 00:55:07 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Integration | Helper | date-from-now', function (hooks) {
|
2018-11-14 00:55:07 +00:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it works', function (assert) {
|
2018-11-14 00:55:07 +00:00
|
|
|
let result = dateFromNow([1481022124443]);
|
|
|
|
assert.ok(typeof result === 'string', 'it is a string');
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('you can include a suffix', function (assert) {
|
2018-11-14 00:55:07 +00:00
|
|
|
let result = dateFromNow([1481022124443], { addSuffix: true });
|
|
|
|
assert.ok(result.includes(' ago'));
|
|
|
|
});
|
2021-02-08 20:13:00 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('you can pass in UTC timestamp', function (assert) {
|
2021-02-08 20:13:00 +00:00
|
|
|
let result = dateFromNow(['Fri, 11 Oct 2019 18:56:08 GMT'], { addSuffix: true });
|
|
|
|
assert.ok(result.includes(' ago'));
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('you can pass in ISO timestamp', function (assert) {
|
2021-02-08 20:13:00 +00:00
|
|
|
let result = dateFromNow(['2019-10-11T18:56:08.984Z'], { addSuffix: true });
|
|
|
|
assert.ok(result.includes(' ago'));
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('you can include a suffix using date class', function (assert) {
|
2021-02-08 20:13:00 +00:00
|
|
|
let now = Date.now();
|
|
|
|
let pastDate = subMinutes(now, 30);
|
|
|
|
let result = dateFromNow([pastDate], { addSuffix: true });
|
|
|
|
assert.ok(result.includes(' ago'));
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('you can include a suffix using ISO 8601 format', function (assert) {
|
2021-02-08 20:13:00 +00:00
|
|
|
let result = dateFromNow(['2021-02-05T20:43:09+00:00'], { addSuffix: true });
|
|
|
|
assert.ok(result.includes(' ago'));
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('you can include a suffix in the helper', async function (assert) {
|
2021-02-08 20:13:00 +00:00
|
|
|
await render(hbs`<p data-test-date-from-now>Date: {{date-from-now 1481022124443 addSuffix=true}}</p>`);
|
|
|
|
assert.dom('[data-test-date-from-now]').includesText(' years ago');
|
|
|
|
});
|
2018-11-14 00:55:07 +00:00
|
|
|
});
|