From 9436f1942fc9f7ec8fb9c856bf8489fccf5dfd98 Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Thu, 10 Sep 2026 16:15:53 +0800 Subject: [PATCH 1/2] Format the inspection models' display dates The inspection form and submission models handed out `createdAt` and its siblings as the raw `Date` from the attribute. A table column bound to `createdAt` therefore rendered a full datetime instance string instead of a date, which is what the inspection forms index shows today. Every other model in this package formats these getters, guarding an unparseable value with `isValidDate` first, so do the same here. The form model also carried a `frequency` attribute. Nothing schedules an inspection from it, and FleetOps has dropped it from the API resource and the console, so it is removed here too. --- addon/models/inspection-form.js | 32 +++++++++++++++++----- addon/models/inspection-submission.js | 39 +++++++++++++++++++++------ 2 files changed, 56 insertions(+), 15 deletions(-) diff --git a/addon/models/inspection-form.js b/addon/models/inspection-form.js index 96a362e..6ac4d58 100644 --- a/addon/models/inspection-form.js +++ b/addon/models/inspection-form.js @@ -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; @@ -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; @@ -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'); } } diff --git a/addon/models/inspection-submission.js b/addon/models/inspection-submission.js index 0c03e97..f4e5088 100644 --- a/addon/models/inspection-submission.js +++ b/addon/models/inspection-submission.js @@ -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; @@ -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'); } } From cf162ced0ca4638ce201c01b828c1cdee529b9b9 Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Fri, 11 Sep 2026 19:09:49 +0800 Subject: [PATCH 2/2] Test the inspection models' formatted display dates The inspection form and submission tests still asserted that the camelCase date getters return the raw Date, so they failed once the getters began formatting it, and the null branch of each isValidDate guard was never run, which held coverage below the 100% gate. Assert each getter through assertDateGetters, like the other models: the yyyy-MM-dd HH:mm rendering of a real date, and null for null, undefined and an unparseable Date. Also assert that the form no longer declares frequency. --- tests/unit/models/inspection-form-test.js | 29 +++++++++++----- .../unit/models/inspection-submission-test.js | 33 ++++++++++++------- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/tests/unit/models/inspection-form-test.js b/tests/unit/models/inspection-form-test.js index 448efc9..1521ce8 100644 --- a/tests/unit/models/inspection-form-test.js +++ b/tests/unit/models/inspection-form-test.js @@ -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); @@ -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, + }); }); }); diff --git a/tests/unit/models/inspection-submission-test.js b/tests/unit/models/inspection-submission-test.js index 59544fe..19db47e 100644 --- a/tests/unit/models/inspection-submission-test.js +++ b/tests/unit/models/inspection-submission-test.js @@ -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); @@ -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, + }); }); });