Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions addon/models/inspection-form.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Model, { attr, belongsTo } from '@ember-data/model';
import { computed } from '@ember/object';
import { format as formatDate, isValid as isValidDate } from 'date-fns';

export default class InspectionFormModel extends Model {
@attr('string') uuid;
Expand All @@ -10,7 +12,6 @@ export default class InspectionFormModel extends Model {
@attr('string') description;
@attr('string') type;
@attr('string') status;
@attr('string') frequency;
@belongsTo('maintenance-subject', { polymorphic: true, async: false }) subject;
@attr('raw') items;
@attr('raw') settings;
Expand All @@ -25,15 +26,32 @@ export default class InspectionFormModel extends Model {
return this.name || this.public_id;
}

get createdAt() {
return this.created_at;
/**
* The display dates a table or a details panel reads. They returned the
* raw `Date`, which rendered as a full datetime instance string in a
* column; every other model in this package formats them here.
*/
@computed('created_at') get createdAt() {
if (!isValidDate(this.created_at)) {
return null;
}

return formatDate(this.created_at, 'yyyy-MM-dd HH:mm');
}

get updatedAt() {
return this.updated_at;
@computed('updated_at') get updatedAt() {
if (!isValidDate(this.updated_at)) {
return null;
}

return formatDate(this.updated_at, 'yyyy-MM-dd HH:mm');
}

get publishedAt() {
return this.published_at;
@computed('published_at') get publishedAt() {
if (!isValidDate(this.published_at)) {
return null;
}

return formatDate(this.published_at, 'yyyy-MM-dd HH:mm');
}
}
39 changes: 31 additions & 8 deletions addon/models/inspection-submission.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Model, { attr, belongsTo } from '@ember-data/model';
import { computed } from '@ember/object';
import { format as formatDate, isValid as isValidDate } from 'date-fns';

export default class InspectionSubmissionModel extends Model {
@attr('string') uuid;
Expand Down Expand Up @@ -43,19 +45,40 @@ export default class InspectionSubmissionModel extends Model {
return this.public_id || this.form_name || 'Inspection';
}

get createdAt() {
return this.created_at;
/**
* The display dates a table or a details panel reads — formatted here, as
* in every other model in this package, rather than handed out as a raw
* `Date` that renders as a full datetime instance string.
*/
@computed('created_at') get createdAt() {
if (!isValidDate(this.created_at)) {
return null;
}

return formatDate(this.created_at, 'yyyy-MM-dd HH:mm');
}

get updatedAt() {
return this.updated_at;
@computed('updated_at') get updatedAt() {
if (!isValidDate(this.updated_at)) {
return null;
}

return formatDate(this.updated_at, 'yyyy-MM-dd HH:mm');
}

get submittedAt() {
return this.submitted_at;
@computed('submitted_at') get submittedAt() {
if (!isValidDate(this.submitted_at)) {
return null;
}

return formatDate(this.submitted_at, 'yyyy-MM-dd HH:mm');
}

get resolvedAt() {
return this.resolved_at;
@computed('resolved_at') get resolvedAt() {
if (!isValidDate(this.resolved_at)) {
return null;
}

return formatDate(this.resolved_at, 'yyyy-MM-dd HH:mm');
}
}
29 changes: 20 additions & 9 deletions tests/unit/models/inspection-form-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { module, test } from 'qunit';
import { setupTest } from 'dummy/tests/helpers';
import { assertAttributeTypes, assertRelationships } from 'dummy/tests/helpers/model-contract';
import { FIXED_DATE_LONG, assertAttributeTypes, assertDateGetters, assertRelationships } from 'dummy/tests/helpers/model-contract';

module('Unit | Model | inspection-form', function (hooks) {
setupTest(hooks);
Expand Down Expand Up @@ -37,14 +37,25 @@ module('Unit | Model | inspection-form', function (hooks) {
assert.strictEqual(form.displayName, 'Pre-trip');
});

test('the camelCase date getters expose the raw dates', function (assert) {
const published = new Date(2026, 8, 1);
const created = new Date(2026, 7, 1);
const updated = new Date(2026, 7, 2);
const form = this.store.createRecord('inspection-form', { published_at: published, created_at: created, updated_at: updated });
test('it no longer declares a frequency attribute', function (assert) {
assert.notOk(this.store.modelFor('inspection-form').attributes.has('frequency'), 'inspection-form does not declare `frequency`');
});

test('published_at renders its formatting getter', function (assert) {
assertDateGetters(assert, this.store.createRecord('inspection-form'), 'published_at', {
publishedAt: FIXED_DATE_LONG,
});
});

assert.strictEqual(form.publishedAt, published);
assert.strictEqual(form.createdAt, created);
assert.strictEqual(form.updatedAt, updated);
test('created_at renders its formatting getter', function (assert) {
assertDateGetters(assert, this.store.createRecord('inspection-form'), 'created_at', {
createdAt: FIXED_DATE_LONG,
});
});

test('updated_at renders its formatting getter', function (assert) {
assertDateGetters(assert, this.store.createRecord('inspection-form'), 'updated_at', {
updatedAt: FIXED_DATE_LONG,
});
});
});
33 changes: 22 additions & 11 deletions tests/unit/models/inspection-submission-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { module, test } from 'qunit';
import { setupTest } from 'dummy/tests/helpers';
import { assertAttributeTypes, assertRelationships } from 'dummy/tests/helpers/model-contract';
import { FIXED_DATE_LONG, assertAttributeTypes, assertDateGetters, assertRelationships } from 'dummy/tests/helpers/model-contract';

module('Unit | Model | inspection-submission', function (hooks) {
setupTest(hooks);
Expand Down Expand Up @@ -50,16 +50,27 @@ module('Unit | Model | inspection-submission', function (hooks) {
assert.strictEqual(submission.displayName, 'submission_1');
});

test('the camelCase date getters expose the raw dates', function (assert) {
const submitted = new Date(2026, 8, 1);
const resolved = new Date(2026, 8, 2);
const created = new Date(2026, 7, 1);
const updated = new Date(2026, 7, 2);
const submission = this.store.createRecord('inspection-submission', { submitted_at: submitted, resolved_at: resolved, created_at: created, updated_at: updated });
test('submitted_at renders its formatting getter', function (assert) {
assertDateGetters(assert, this.store.createRecord('inspection-submission'), 'submitted_at', {
submittedAt: FIXED_DATE_LONG,
});
});

test('resolved_at renders its formatting getter', function (assert) {
assertDateGetters(assert, this.store.createRecord('inspection-submission'), 'resolved_at', {
resolvedAt: FIXED_DATE_LONG,
});
});

assert.strictEqual(submission.submittedAt, submitted);
assert.strictEqual(submission.resolvedAt, resolved);
assert.strictEqual(submission.createdAt, created);
assert.strictEqual(submission.updatedAt, updated);
test('created_at renders its formatting getter', function (assert) {
assertDateGetters(assert, this.store.createRecord('inspection-submission'), 'created_at', {
createdAt: FIXED_DATE_LONG,
});
});

test('updated_at renders its formatting getter', function (assert) {
assertDateGetters(assert, this.store.createRecord('inspection-submission'), 'updated_at', {
updatedAt: FIXED_DATE_LONG,
});
});
});
Loading