Skip to content

Commit

Permalink
fix!: make document title and description not localized
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This turns the document's title and description into
regular CharFields/TextFields, instead of localized ones, because
localized fields do not make sense for user-generated data.
  • Loading branch information
czosel committed Aug 30, 2024
1 parent efbcf8d commit 3ffcfbd
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
9 changes: 4 additions & 5 deletions addon/models/document.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { inject as service } from "@ember/service";
import { belongsTo, hasMany, attr } from "@ember-data/model";
import { LocalizedModel, localizedAttr } from "ember-localized-model";
import Model, { attr, belongsTo, hasMany } from "@ember-data/model";
import { trackedFunction } from "reactiveweb/function";

export default class DocumentModel extends LocalizedModel {
@localizedAttr title;
@localizedAttr description;
export default class DocumentModel extends Model {
@attr title;
@attr description;
@attr metainfo;

@attr createdAt;
Expand Down
14 changes: 7 additions & 7 deletions tests/acceptance/documents-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ module("Acceptance | documents", function (hooks) {
assert.dom("[data-test-document]").exists({ count: 5 });
assert
.dom("[data-test-document-container]:first-child [data-test-title]")
.hasText(documents[0].title.en);
.hasText(documents[0].title);
assert
.dom("[data-test-document-container]:first-child [data-test-thumbnail]")
.doesNotExist();

assert
.dom("[data-test-document-container]:nth-child(2) [data-test-title]")
.hasText(documents[1].title.en);
.hasText(documents[1].title);
assert
.dom("[data-test-document-container]:nth-child(2) [data-test-thumbnail]")
.hasAttribute("data-src", "test-thumbnail");
Expand Down Expand Up @@ -87,7 +87,7 @@ module("Acceptance | documents", function (hooks) {

assert
.dom("[data-test-single-doc-details] [data-test-title]")
.hasText(document.title.en);
.hasText(document.title);

await click("[data-test-close]");
assert.dom("[data-test-document-side-panel]").hasClass("closed");
Expand All @@ -105,12 +105,12 @@ module("Acceptance | documents", function (hooks) {

assert
.dom("[data-test-single-doc-details] [data-test-title]")
.hasText(document.title.en);
.hasText(document.title);

assert.dom("[data-test-title-input]").doesNotExist();

await click("[data-test-single-doc-details] [data-test-edit-title]");
assert.dom("[data-test-title-input]").hasValue(document.title.en);
assert.dom("[data-test-title-input]").hasValue(document.title);

await fillIn("[data-test-title-input]", "new title");
this.assertRequest("PATCH", "/api/v1/documents/:id", (request) => {
Expand All @@ -120,7 +120,7 @@ module("Acceptance | documents", function (hooks) {
"patching the correct document",
);
assert.strictEqual(
JSON.parse(request.requestBody).data.attributes.title.en,
JSON.parse(request.requestBody).data.attributes.title,
"new title",
"new title is set",
);
Expand Down Expand Up @@ -163,7 +163,7 @@ module("Acceptance | documents", function (hooks) {
.text()
.then((data) => {
assert.strictEqual(
JSON.parse(data).title.en,
JSON.parse(data).title,
"test-file.txt",
"correct title is set",
);
Expand Down
6 changes: 2 additions & 4 deletions tests/dummy/mirage/factories/document.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { faker } from "@faker-js/faker";
import { Factory, trait } from "miragejs";

import { setAllLocales } from "./helpers";

export default Factory.extend({
title: () => setAllLocales(faker.system.commonFileName()),
description: () => setAllLocales(faker.company.catchPhrase()),
title: () => faker.system.commonFileName(),
description: () => faker.company.catchPhrase(),
createdByUser: () => faker.person.fullName(),
createdByGroup: () => faker.company.name(),
createdAt: () => faker.date.past(),
Expand Down
8 changes: 3 additions & 5 deletions tests/unit/serializers/document-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module("Unit | Serializer | document", function (hooks) {
test("it serializes records", function (assert) {
const store = this.owner.lookup("service:store");
const record = store.createRecord("document", {
title: { en: "Foo" },
title: "Foo",
content: "test",
});

Expand All @@ -21,14 +21,12 @@ module("Unit | Serializer | document", function (hooks) {
"created-by-group": undefined,
"created-by-user": undefined,
date: undefined,
description: {},
description: undefined,
metainfo: undefined,
"modified-at": undefined,
"modified-by-group": undefined,
"modified-by-user": undefined,
title: {
en: "Foo",
},
title: "Foo",
},
type: "documents",
},
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/services/alexandria-documents-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module("Unit | Service | alexandria-documents", function (hooks) {
const document = this.server.create("document");
const file = this.server.create("file", {
document,
name: document.title.en,
name: document.title,
variant: "original",
downloadUrl: "http://earth.planet?expires=123456",
});
Expand Down

0 comments on commit 3ffcfbd

Please sign in to comment.