-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from microbiomedata/issue-176-slot-any-of-range
Check `any_of` on slot definition when determining input type
- Loading branch information
Showing
2 changed files
with
126 additions
and
11 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
src/components/SampleSlotEditModal/SampleSlotEditModal.test.ts
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,90 @@ | ||
import { getSelectState } from "./SampleSlotEditModal"; | ||
import { SchemaDefinition } from "../../linkml-metamodel"; | ||
import { GoldEcosystemTreeNode, SampleDataValue } from "../../api"; | ||
|
||
const MOCK_SCHEMA: SchemaDefinition = { | ||
id: "http://example.org/test", | ||
name: "test", | ||
slots: { | ||
a_string: { | ||
name: "a_string", | ||
range: "string", | ||
}, | ||
a_choice: { | ||
name: "a_choice", | ||
range: "Choice", | ||
}, | ||
a_choice_or_string: { | ||
name: "a_choice_or_string", | ||
any_of: [{ range: "string" }, { range: "Choice" }], | ||
}, | ||
}, | ||
enums: { | ||
Choice: { | ||
name: "Choice", | ||
permissible_values: { | ||
a: { text: "a" }, | ||
b: { text: "b" }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const MOCK_GOLD_TREE: GoldEcosystemTreeNode = { | ||
name: "test", | ||
children: [], | ||
}; | ||
|
||
const MOCK_SAMPLE_DATA: Record<string, SampleDataValue> = {}; | ||
|
||
const MOCK_SAMPLE_DATA_GETTER = (name: string) => MOCK_SAMPLE_DATA[name]; | ||
|
||
describe("getSelectState", () => { | ||
it("should return isSelectable = false when slot is null", () => { | ||
const state = getSelectState( | ||
MOCK_SCHEMA, | ||
null, | ||
MOCK_SAMPLE_DATA_GETTER, | ||
MOCK_GOLD_TREE, | ||
); | ||
expect(state.isSelectable).toBe(false); | ||
}); | ||
|
||
it("should return isSelectable = false when the slot range is string", () => { | ||
const state = getSelectState( | ||
MOCK_SCHEMA, | ||
MOCK_SCHEMA.slots!["a_string"], | ||
MOCK_SAMPLE_DATA_GETTER, | ||
MOCK_GOLD_TREE, | ||
); | ||
expect(state.isSelectable).toBe(false); | ||
}); | ||
|
||
it("should return isSelectable = true when the slot range is string", () => { | ||
const state = getSelectState( | ||
MOCK_SCHEMA, | ||
MOCK_SCHEMA.slots!["a_choice"], | ||
MOCK_SAMPLE_DATA_GETTER, | ||
MOCK_GOLD_TREE, | ||
); | ||
expect(state.isSelectable).toBe(true); | ||
expect(state.permissibleValues).toEqual({ | ||
a: { text: "a" }, | ||
b: { text: "b" }, | ||
}); | ||
}); | ||
|
||
it("should return isSelectable = true when the slot range is any_of", () => { | ||
const state = getSelectState( | ||
MOCK_SCHEMA, | ||
MOCK_SCHEMA.slots!["a_choice_or_string"], | ||
MOCK_SAMPLE_DATA_GETTER, | ||
MOCK_GOLD_TREE, | ||
); | ||
expect(state.isSelectable).toBe(true); | ||
expect(state.permissibleValues).toEqual({ | ||
a: { text: "a" }, | ||
b: { text: "b" }, | ||
}); | ||
}); | ||
}); |
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