feat: 🎸 implement live relative datetime component (#1080)
This commit is contained in:
1 parent
de6416efbd
commit
a7b3da2231
9 files changed
+244
-1
No files matched your search
@@ -0,0 +1,12 @@
|
||||
import Controller from '@ember/controller';
|
||||
import { inject as service } from '@ember/service';
|
||||
|
||||
export default class ApplicationController extends Controller {
|
||||
// =services
|
||||
|
||||
@service clockTick;
|
||||
|
||||
// =properties
|
||||
|
||||
now = new Date();
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
<h2 id="title">Welcome to Ember</h2>
|
||||
|
||||
{{t "errors.401.title"}}
|
||||
<RelativeDatetimeLive @date={{this.now}} />
|
||||
@@ -0,0 +1,38 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'ember-qunit';
|
||||
import { render } from '@ember/test-helpers';
|
||||
import { hbs } from 'ember-cli-htmlbars';
|
||||
|
||||
module('Integration | Component | relative-datetime-live', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders a relative datetime', async function (assert) {
|
||||
assert.expect(6);
|
||||
|
||||
const now = Date.now();
|
||||
|
||||
this.date = now - 10 * 1000;
|
||||
await render(hbs`<RelativeDatetimeLive @date={{this.date}} />`);
|
||||
assert.dom(this.element).hasText('10 seconds ago');
|
||||
|
||||
this.date = now - 10 * 60 * 1000;
|
||||
await render(hbs`<RelativeDatetimeLive @date={{this.date}} />`);
|
||||
assert.dom(this.element).hasText('10 minutes ago');
|
||||
|
||||
this.date = now - 10 * 60 * 60 * 1000;
|
||||
await render(hbs`<RelativeDatetimeLive @date={{this.date}} />`);
|
||||
assert.dom(this.element).hasText('10 hours ago');
|
||||
|
||||
this.date = now - 10 * 24 * 60 * 60 * 1000;
|
||||
await render(hbs`<RelativeDatetimeLive @date={{this.date}} />`);
|
||||
assert.dom(this.element).hasText('10 days ago');
|
||||
|
||||
this.date = now - 10 * 31 * 24 * 60 * 60 * 1000;
|
||||
await render(hbs`<RelativeDatetimeLive @date={{this.date}} />`);
|
||||
assert.dom(this.element).hasText('10 months ago');
|
||||
|
||||
this.date = now - 10 * 12 * 31 * 24 * 60 * 60 * 1000;
|
||||
await render(hbs`<RelativeDatetimeLive @date={{this.date}} />`);
|
||||
assert.dom(this.element).hasText('10 years ago');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Service | clock-tick', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// TODO: Replace this with your real tests.
|
||||
test('it exists', function (assert) {
|
||||
let service = this.owner.lookup('service:clock-tick');
|
||||
assert.ok(service);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user