-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* studio - action inputs * studio - user input * studio - db width * studio - unit tests
- Loading branch information
1 parent
80cddc0
commit 36e0e79
Showing
23 changed files
with
591 additions
and
54 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
92 changes: 92 additions & 0 deletions
92
agdb_studio/src/components/base/content/AgdbContent.spec.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,92 @@ | ||
import { describe, beforeEach, vi, it, expect } from "vitest"; | ||
import AgdbContent from "./AgdbContent.vue"; | ||
import { mount } from "@vue/test-utils"; | ||
import { useContentInputs } from "@/composables/content/inputs"; | ||
import { ref } from "vue"; | ||
|
||
const { addInput, getInputValue, clearAllInputs } = useContentInputs(); | ||
|
||
describe("AgdbContent", () => { | ||
const testKey = Symbol("test"); | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
clearAllInputs(); | ||
}); | ||
|
||
it("renders the content", () => { | ||
const wrapper = mount(AgdbContent, { | ||
props: { | ||
content: [ | ||
{ | ||
paragraph: [ | ||
{ | ||
text: "Test Body", | ||
}, | ||
], | ||
}, | ||
{ | ||
component: "my-component", | ||
}, | ||
{ | ||
input: { | ||
key: "test", | ||
type: "text", | ||
label: "Test input", | ||
}, | ||
}, | ||
], | ||
contentKey: testKey, | ||
}, | ||
}); | ||
expect(wrapper.html()).toContain("Test Body"); | ||
expect(wrapper.html()).toContain("my-component"); | ||
expect(wrapper.html()).toContain("Test input"); | ||
}); | ||
it("change the input value on user input", async () => { | ||
const inputValue = ref(""); | ||
addInput(testKey, "test", inputValue); | ||
const wrapper = mount(AgdbContent, { | ||
props: { | ||
content: [ | ||
{ | ||
input: { | ||
key: "test", | ||
type: "text", | ||
label: "Test input", | ||
}, | ||
}, | ||
], | ||
contentKey: testKey, | ||
}, | ||
}); | ||
const input = wrapper.find("input"); | ||
expect(getInputValue(testKey, "test")).toBe(""); | ||
expect(input.element.value).toBe(""); | ||
input.element.value = "test value"; | ||
await input.trigger("input"); | ||
expect(getInputValue(testKey, "test")).toBe("test value"); | ||
}); | ||
it("sets focus on the input with autofocus", async () => { | ||
const inputValue = ref(""); | ||
addInput(testKey, "test", inputValue); | ||
const wrapper = mount(AgdbContent, { | ||
props: { | ||
content: [ | ||
{ | ||
input: { | ||
key: "test", | ||
type: "text", | ||
label: "Test input", | ||
autofocus: true, | ||
}, | ||
}, | ||
], | ||
contentKey: testKey, | ||
}, | ||
attachTo: document.body, | ||
}); | ||
await wrapper.vm.$nextTick(); | ||
const input = wrapper.find("input"); | ||
expect(input.element.matches(":focus")).toBe(true); | ||
}); | ||
}); |
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,71 @@ | ||
<script lang="ts" setup> | ||
import { onMounted, ref, type PropType } from "vue"; | ||
import { useContentInputs } from "@/composables/content/inputs"; | ||
const props = defineProps({ | ||
content: { type: Array as PropType<Content[]>, required: true }, | ||
contentKey: { type: Symbol, required: true }, | ||
}); | ||
const { getContentInputs, setInputValue } = useContentInputs(); | ||
const inputs = getContentInputs(props.contentKey) ?? new Map(); | ||
const autofocusElement = ref(); | ||
onMounted(() => { | ||
autofocusElement.value?.focus(); | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div class="agdb-content"> | ||
<div v-for="(part, index) in content" :key="index"> | ||
<p v-if="part.paragraph?.length"> | ||
<span | ||
v-for="(text, index2) in part.paragraph" | ||
:key="index2" | ||
:style="text.style" | ||
:class="text.className" | ||
> | ||
{{ text.text }} | ||
</span> | ||
</p> | ||
<div v-if="part.component"> | ||
<component :is="part.component" /> | ||
</div> | ||
<div v-if="part.input" class="input-row"> | ||
<label>{{ part.input.label }}</label> | ||
<input | ||
v-if="inputs.get(part.input.key) !== undefined" | ||
:type="part.input.type" | ||
:ref=" | ||
(el) => { | ||
if (part.input?.autofocus) autofocusElement = el; | ||
} | ||
" | ||
@input=" | ||
(event: Event) => { | ||
setInputValue( | ||
props.contentKey, | ||
part.input?.key, | ||
(event.target as HTMLInputElement).value, | ||
); | ||
} | ||
" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<style lang="less" scoped> | ||
.agdb-content { | ||
p { | ||
margin-bottom: 1rem; | ||
} | ||
} | ||
.input-row { | ||
display: flex; | ||
gap: 1rem; | ||
} | ||
</style> |
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
Oops, something went wrong.