/**
* エラー一覧の「詳細」の列に出すエラー内容(指示書BE §3 / §12)。JP / EN。
*/
import { describe, expect, it } from "vitest";
import { errorContentView, errorContentViewFromItem } from "@/lib/errors/error-content-label";
import type { ErrorListItem } from "@/lib/types";
function item(partial: Partial<ErrorListItem> & Pick<ErrorListItem, "id">): ErrorListItem {
return {
error_category_main_en: "ROBOT ERROR",
error_category_main_ja: "清掃ロボットエラー",
error_category_sub_en: "Safety",
error_category_sub_ja: "安全",
error_detail_en: "Emergency stop switch was triggered",
error_detail_ja: "非常停止スイッチが作動しました",
note_required: false,
...partial,
};
}
const stop = item({ id: 40 });
const other = item({
id: 131,
error_category_main_en: "OTHER ERROR",
error_category_main_ja: "その他(該当なし)",
error_category_sub_en: "Other",
error_category_sub_ja: "その他",
error_detail_en: "There are no errors.",
error_detail_ja: "該当するエラーはありません",
note_required: true,
});
describe("errorContentView(指示書BE §3)", () => {
it("選べない行は dash(JP / EN とも。error_type は見ない)", () => {
const view = errorContentView({
lang: "ja",
selectable: false,
savedId: 40,
savedList: stop,
draftId: undefined,
catalog: [stop],
});
expect(view).toEqual({ kind: "dash" });
expect(
errorContentView({
lang: "en",
selectable: false,
savedId: null,
savedList: null,
draftId: undefined,
catalog: [],
})
).toEqual({ kind: "dash" });
});
it("未選択は unselected", () => {
expect(
errorContentView({
lang: "en",
selectable: true,
savedId: null,
savedList: null,
draftId: undefined,
catalog: [stop],
}).kind
).toBe("unselected");
});
it("id はあるが名前が無いと unknown(id を持つ)", () => {
expect(
errorContentView({
lang: "ja",
selectable: true,
savedId: 9999,
savedList: null,
draftId: undefined,
catalog: [stop],
})
).toEqual({ kind: "unknown", id: 9999 });
});
it("note_required は大分類名。詳細「該当するエラーはありません」は出さない(JP / EN)", () => {
expect(errorContentViewFromItem("ja", other)).toEqual({
kind: "category",
text: "その他(該当なし)",
title: "その他(該当なし) / その他",
});
expect(errorContentViewFromItem("en", other)).toEqual({
kind: "category",
text: "OTHER ERROR",
title: "OTHER ERROR / Other",
});
expect(errorContentViewFromItem("ja", other)).not.toMatchObject({
text: "該当するエラーはありません",
});
});
it("通常の選択肢は詳細。title は大分類 / 小分類 / 詳細(JP / EN)", () => {
expect(errorContentViewFromItem("ja", stop)).toEqual({
kind: "detail",
text: "非常停止スイッチが作動しました",
title: "清掃ロボットエラー / 安全 / 非常停止スイッチが作動しました",
});
expect(errorContentViewFromItem("en", stop)).toEqual({
kind: "detail",
text: "Emergency stop switch was triggered",
title: "ROBOT ERROR / Safety / Emergency stop switch was triggered",
});
});
it("下書きの id は選択肢から引く", () => {
const view = errorContentView({
lang: "ja",
selectable: true,
savedId: null,
savedList: null,
draftId: 40,
catalog: [stop, other],
});
expect(view).toMatchObject({ kind: "detail", text: "非常停止スイッチが作動しました" });
});
it("未選択は unselected(JP)", () => {
expect(
errorContentView({
lang: "ja",
selectable: true,
savedId: null,
savedList: null,
draftId: undefined,
catalog: [stop],
})
).toEqual({ kind: "unselected" });
});
it("下書きの id が選択肢に無ければ unknown(保存済みの名前があっても使わない。JP / EN)", () => {
for (const lang of ["ja", "en"] as const) {
expect(
errorContentView({
lang,
selectable: true,
savedId: 40,
savedList: stop,
draftId: 9999,
catalog: [stop, other],
})
).toEqual({ kind: "unknown", id: 9999 });
}
});
});