Skip to content

Commit 3ffcfbd

Browse files
committed
fix!: make document title and description not localized
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.
1 parent efbcf8d commit 3ffcfbd

File tree

5 files changed

+17
-22
lines changed

5 files changed

+17
-22
lines changed

addon/models/document.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { inject as service } from "@ember/service";
2-
import { belongsTo, hasMany, attr } from "@ember-data/model";
3-
import { LocalizedModel, localizedAttr } from "ember-localized-model";
2+
import Model, { attr, belongsTo, hasMany } from "@ember-data/model";
43
import { trackedFunction } from "reactiveweb/function";
54

6-
export default class DocumentModel extends LocalizedModel {
7-
@localizedAttr title;
8-
@localizedAttr description;
5+
export default class DocumentModel extends Model {
6+
@attr title;
7+
@attr description;
98
@attr metainfo;
109

1110
@attr createdAt;

tests/acceptance/documents-test.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ module("Acceptance | documents", function (hooks) {
4444
assert.dom("[data-test-document]").exists({ count: 5 });
4545
assert
4646
.dom("[data-test-document-container]:first-child [data-test-title]")
47-
.hasText(documents[0].title.en);
47+
.hasText(documents[0].title);
4848
assert
4949
.dom("[data-test-document-container]:first-child [data-test-thumbnail]")
5050
.doesNotExist();
5151

5252
assert
5353
.dom("[data-test-document-container]:nth-child(2) [data-test-title]")
54-
.hasText(documents[1].title.en);
54+
.hasText(documents[1].title);
5555
assert
5656
.dom("[data-test-document-container]:nth-child(2) [data-test-thumbnail]")
5757
.hasAttribute("data-src", "test-thumbnail");
@@ -87,7 +87,7 @@ module("Acceptance | documents", function (hooks) {
8787

8888
assert
8989
.dom("[data-test-single-doc-details] [data-test-title]")
90-
.hasText(document.title.en);
90+
.hasText(document.title);
9191

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

106106
assert
107107
.dom("[data-test-single-doc-details] [data-test-title]")
108-
.hasText(document.title.en);
108+
.hasText(document.title);
109109

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

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

115115
await fillIn("[data-test-title-input]", "new title");
116116
this.assertRequest("PATCH", "/api/v1/documents/:id", (request) => {
@@ -120,7 +120,7 @@ module("Acceptance | documents", function (hooks) {
120120
"patching the correct document",
121121
);
122122
assert.strictEqual(
123-
JSON.parse(request.requestBody).data.attributes.title.en,
123+
JSON.parse(request.requestBody).data.attributes.title,
124124
"new title",
125125
"new title is set",
126126
);
@@ -163,7 +163,7 @@ module("Acceptance | documents", function (hooks) {
163163
.text()
164164
.then((data) => {
165165
assert.strictEqual(
166-
JSON.parse(data).title.en,
166+
JSON.parse(data).title,
167167
"test-file.txt",
168168
"correct title is set",
169169
);

tests/dummy/mirage/factories/document.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { faker } from "@faker-js/faker";
22
import { Factory, trait } from "miragejs";
33

4-
import { setAllLocales } from "./helpers";
5-
64
export default Factory.extend({
7-
title: () => setAllLocales(faker.system.commonFileName()),
8-
description: () => setAllLocales(faker.company.catchPhrase()),
5+
title: () => faker.system.commonFileName(),
6+
description: () => faker.company.catchPhrase(),
97
createdByUser: () => faker.person.fullName(),
108
createdByGroup: () => faker.company.name(),
119
createdAt: () => faker.date.past(),

tests/unit/serializers/document-test.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module("Unit | Serializer | document", function (hooks) {
77
test("it serializes records", function (assert) {
88
const store = this.owner.lookup("service:store");
99
const record = store.createRecord("document", {
10-
title: { en: "Foo" },
10+
title: "Foo",
1111
content: "test",
1212
});
1313

@@ -21,14 +21,12 @@ module("Unit | Serializer | document", function (hooks) {
2121
"created-by-group": undefined,
2222
"created-by-user": undefined,
2323
date: undefined,
24-
description: {},
24+
description: undefined,
2525
metainfo: undefined,
2626
"modified-at": undefined,
2727
"modified-by-group": undefined,
2828
"modified-by-user": undefined,
29-
title: {
30-
en: "Foo",
31-
},
29+
title: "Foo",
3230
},
3331
type: "documents",
3432
},

tests/unit/services/alexandria-documents-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ module("Unit | Service | alexandria-documents", function (hooks) {
9191
const document = this.server.create("document");
9292
const file = this.server.create("file", {
9393
document,
94-
name: document.title.en,
94+
name: document.title,
9595
variant: "original",
9696
downloadUrl: "http://earth.planet?expires=123456",
9797
});

0 commit comments

Comments
 (0)