Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d42b58c4fe | ||
|
|
724ad8e7a1 | ||
|
|
2fe50729a5 | ||
|
|
eb4eee1aef |
@@ -1,5 +1,5 @@
|
||||
// @vitest-environment jsdom
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { mountWithApp } from "./helpers/mountWithApp.js";
|
||||
import ReferenceAutocompletePOS from "@/components/forms/department/pos/input/ReferenceAutocompletePOS.vue";
|
||||
|
||||
@@ -16,72 +16,8 @@ const flushPromises = async () => {
|
||||
await Promise.resolve();
|
||||
};
|
||||
|
||||
// Buefy schedules dropdown viewport checks after activation; stubbing it keeps this focused unit test from
|
||||
// leaking those browser-only timers past jsdom teardown.
|
||||
const AutocompleteStub = {
|
||||
name: "BAutocomplete",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
modelValue: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
data: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
},
|
||||
emits: ["blur", "focus", "keydown", "select", "typing", "update:modelValue"],
|
||||
methods: {
|
||||
emitInput(event) {
|
||||
const value = event.target.value;
|
||||
this.$emit("update:modelValue", value);
|
||||
this.$emit("typing", value);
|
||||
},
|
||||
optionsFor(group) {
|
||||
return Array.isArray(group?.items) ? group.items : [];
|
||||
},
|
||||
optionKey(option) {
|
||||
return `${option.source}-${option.origin_id}-${option.reference}`;
|
||||
},
|
||||
},
|
||||
template: `
|
||||
<div class="b-autocomplete-stub">
|
||||
<input
|
||||
v-bind="$attrs"
|
||||
:value="modelValue"
|
||||
@input="emitInput"
|
||||
@focus="$emit('focus', $event)"
|
||||
@blur="$emit('blur', $event)"
|
||||
@keydown="$emit('keydown', $event)"
|
||||
/>
|
||||
<div class="dropdown-content">
|
||||
<template v-for="(group, index) in data" :key="group.group || index">
|
||||
<slot name="group" :group="group.group" :index="index">
|
||||
<span>{{ group.group }}</span>
|
||||
</slot>
|
||||
<button
|
||||
v-for="option in optionsFor(group)"
|
||||
:key="optionKey(option)"
|
||||
type="button"
|
||||
class="dropdown-item"
|
||||
@click="$emit('select', option, $event)"
|
||||
>
|
||||
<slot :option="option">
|
||||
{{ option.reference }}
|
||||
</slot>
|
||||
</button>
|
||||
</template>
|
||||
<slot v-if="data.length === 0" name="empty" />
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
};
|
||||
|
||||
const mountedWrappers = [];
|
||||
|
||||
function mountAutocomplete(props = {}) {
|
||||
const wrapper = mountWithApp(ReferenceAutocompletePOS, {
|
||||
return mountWithApp(ReferenceAutocompletePOS, {
|
||||
props: {
|
||||
modelValue: "",
|
||||
departmentId: 12,
|
||||
@@ -90,15 +26,7 @@ function mountAutocomplete(props = {}) {
|
||||
debounceMs: 0,
|
||||
...props,
|
||||
},
|
||||
global: {
|
||||
stubs: {
|
||||
BAutocomplete: AutocompleteStub,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
mountedWrappers.push(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
describe("ReferenceAutocompletePOS", () => {
|
||||
@@ -107,12 +35,6 @@ describe("ReferenceAutocompletePOS", () => {
|
||||
requestState.authenticatedRequest.mockResolvedValue({ data: { data: [] } });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
for (const wrapper of mountedWrappers.splice(0)) {
|
||||
wrapper.unmount();
|
||||
}
|
||||
});
|
||||
|
||||
it("fetches async suggestions with the current POS context", async () => {
|
||||
requestState.authenticatedRequest.mockResolvedValue({
|
||||
data: {
|
||||
|
||||
Reference in New Issue
Block a user