-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(decorator): remove need for magic getter to access localized…
… object of a field BREAKING CHANGE: - Remove previously deprecated `getUnlocalizedField`. - Access the localized object of an attribute via `localizedObjects.myField` instead of the magic key `myFieldObject`.
- Loading branch information
Showing
7 changed files
with
112 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { setupTest } from "ember-localized-model/tests/helpers/index"; | ||
import { setupIntl, setLocale } from "ember-intl/test-support"; | ||
import { module, test } from "qunit"; | ||
|
||
module("Unit | Model | localized", function (hooks) { | ||
setupTest(hooks); | ||
setupIntl(hooks, "en"); | ||
|
||
test("it sets value under correct locale", function (assert) { | ||
const store = this.owner.lookup("service:store"); | ||
const model = store.createRecord("book"); | ||
model.name = "test-en"; | ||
setLocale("de"); | ||
model.name = "test-de"; | ||
setLocale("fr"); | ||
model.name = "test-fr"; | ||
|
||
assert.deepEqual(model.localizedObjects.name, { | ||
de: "test-de", | ||
en: "test-en", | ||
fr: "test-fr", | ||
}); | ||
|
||
setLocale("en"); | ||
assert.strictEqual(model.name, "test-en"); | ||
setLocale("de"); | ||
assert.strictEqual(model.name, "test-de"); | ||
setLocale("fr"); | ||
assert.strictEqual(model.name, "test-fr"); | ||
}); | ||
|
||
test("it respects localizedFieldLocale", function (assert) { | ||
const store = this.owner.lookup("service:store"); | ||
const model = store.createRecord("book"); | ||
model.localizedObjects.name = { | ||
en: "test-en", | ||
de: "test-de", | ||
fr: "test-fr", | ||
}; | ||
|
||
assert.strictEqual(model.name, "test-en"); | ||
|
||
model.localizedFieldLocale = "de"; | ||
assert.strictEqual(model.name, "test-de"); | ||
|
||
model.localizedFieldLocale = "fr"; | ||
assert.strictEqual(model.name, "test-fr"); | ||
}); | ||
|
||
test("it has localizedObjects", function (assert) { | ||
const store = this.owner.lookup("service:store"); | ||
const model = store.createRecord("book"); | ||
|
||
assert.deepEqual(model.localizedObjects.name, {}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { setupTest } from "ember-localized-model/tests/helpers/index"; | ||
import { setupIntl } from "ember-intl/test-support"; | ||
import { module, test } from "qunit"; | ||
|
||
module("Unit | Serializer | localized", function (hooks) { | ||
setupTest(hooks); | ||
setupIntl(hooks, "en"); | ||
|
||
test("it serializes records", function (assert) { | ||
const store = this.owner.lookup("service:store"); | ||
const record = store.createRecord("book"); | ||
record.name = "test"; | ||
|
||
const serializedRecord = record.serialize(); | ||
|
||
assert.deepEqual(serializedRecord, { | ||
data: { | ||
attributes: { | ||
name: { | ||
en: "test", | ||
}, | ||
}, | ||
type: "books", | ||
}, | ||
}); | ||
}); | ||
}); |