Skip to content

Commit

Permalink
Don't raise errors for missing labels (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored Nov 27, 2024
1 parent 6b5085b commit e325729
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 10 additions & 5 deletions arches_vue_utils/src/arches_vue_utils/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ function asLabel(valuetype_id: string, language_id: string): Label {
}

const systemLanguageCode = "en-ZA"; // arbitrary
const emptyLabel = {
value: "",
language_id: "",
valuetype_id: "",
};

describe("rankLabel() util", () => {
const rank = (
Expand Down Expand Up @@ -59,21 +64,21 @@ describe("rankLabel() util", () => {
});

describe("getItemLabel() util", () => {
it("Errors if no labels", () => {
expect(() =>
it("Returns empty label if no labels to search", () => {
expect(
getItemLabel(
{ labels: [] },
systemLanguageCode,
systemLanguageCode,
),
).toThrow();
expect(() =>
).toEqual(emptyLabel);
expect(
getItemLabel(
{ values: [] },
systemLanguageCode,
systemLanguageCode,
),
).toThrow();
).toEqual(emptyLabel);
});
it("Falls back to system language", () => {
expect(
Expand Down
6 changes: 5 additions & 1 deletion arches_vue_utils/src/arches_vue_utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ export const getItemLabel = (
): Label => {
const labels = (item as WithLabels).labels ?? (item as WithValues).values;
if (!labels.length) {
throw new Error();
return {
value: "",
language_id: "",
valuetype_id: "",
};
}
return labels.sort(
(a, b) =>
Expand Down

0 comments on commit e325729

Please sign in to comment.