-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: fix test setup + add WordSuggestHint
- Loading branch information
1 parent
8d35c0e
commit 96e6d32
Showing
8 changed files
with
243 additions
and
11 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,64 @@ | ||
import { describe, it, expect, vi } from "vitest"; | ||
import { mount } from "@vue/test-utils"; | ||
import WordSuggestHint from "/home/felix/workspace/berliner-schnauze/src/components/WordSuggestHint.vue"; | ||
|
||
vi.mock("@nanostores/vue", () => ({ | ||
useStore: () => ({ | ||
wordSearch: { | ||
letterGroups: [], | ||
activeLetterFilter: "", | ||
wordTypes: [], | ||
activeWordTypeFilter: "", | ||
wordList: [], | ||
search: "", | ||
alphabeticalOrder: "asc", | ||
dateOrder: "asc", | ||
modifiedDateOrder: "asc", | ||
activeOrderCategory: "alphabetical", | ||
berolinismus: false, | ||
}, | ||
}), | ||
})); | ||
|
||
vi.mock("@stores/index.ts", () => ({ | ||
$wordSearch: vi.fn(), | ||
})); | ||
|
||
vi.mock("@components/Modal.vue", async (importOriginal) => { | ||
const originalModule = await importOriginal<typeof import("@components/Modal.vue")>(); | ||
return { | ||
__esModule: true, // This line is important for Vitest to understand it's an ES module mock | ||
__isTeleport: true, // Add the missing export | ||
default: { | ||
name: "Modal", | ||
template: "<div></div>", | ||
// You can spread other properties from the original module if needed | ||
...originalModule, | ||
}, | ||
}; | ||
}); | ||
|
||
vi.mock("@components/SuggestWordForm.vue", () => ({ | ||
name: "SuggestWordForm", | ||
template: "<div></div>", | ||
})); | ||
|
||
describe("WordSuggestHint.vue", {}, () => { | ||
it("renders without errors", () => { | ||
const wrapper = mount(WordSuggestHint); | ||
expect(wrapper.exists()).toBe(true); | ||
}); | ||
|
||
it("initially does not show the modal", () => { | ||
const wrapper = mount(WordSuggestHint); | ||
expect(wrapper.vm.showModal).toBe(false); | ||
}); | ||
|
||
it("attempts to load and show the modal when button is clicked", async () => { | ||
const wrapper = mount(WordSuggestHint); | ||
await wrapper.find("button").trigger("click"); | ||
// Since modal loading is asynchronous and involves retries, you might need to mock or wait | ||
expect(wrapper.vm.loadModal).toBe(true); | ||
// Further assertions can be made depending on the mock implementation of the modal loading logic | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { describe, it, expect } from "vitest"; | ||
import "@vitest/web-worker"; | ||
import filterWorker from "../../../services/filterWorker.ts?worker"; | ||
|
||
let worker = new filterWorker(); | ||
worker = new Worker(new URL("../../../services/filterWorker.ts?worker", import.meta.url)); | ||
|
||
describe("filterWorker", () => { | ||
it("should filter words by activeLetterFilter", () => { | ||
worker.postMessage({ | ||
letterGroups: [ | ||
"A", | ||
"B", | ||
"C", | ||
"D", | ||
"E", | ||
"F", | ||
"G", | ||
"H", | ||
"I", | ||
"J", | ||
"K", | ||
"L", | ||
"M", | ||
"N", | ||
"O", | ||
"P", | ||
"Q", | ||
"R", | ||
"S", | ||
"T", | ||
"U", | ||
"V", | ||
"W", | ||
"Z", | ||
"Ä", | ||
"Ö", | ||
"ü", | ||
], | ||
wordList: [ | ||
{ | ||
id: "cG9zdDo0MjUz", | ||
slug: "aas", | ||
wordGroup: "A", | ||
dateGmt: "2022-01-22T17:28:48", | ||
modifiedGmt: "2024-01-25T17:31:51", | ||
berlinerWordId: 4253, | ||
wordProperties: { | ||
article: null, | ||
berlinerisch: "Aas", | ||
berlinerischAudio: null, | ||
learnMore: null, | ||
berolinismus: false, | ||
examples: [ | ||
{ example: "Dir Aas kenn ick!", exampleExplanation: null, exampleAudio: null }, | ||
{ example: "Keen Aas hier!", exampleExplanation: "keiner da", exampleAudio: null }, | ||
], | ||
translations: [ | ||
{ translation: "unbeliebter" }, | ||
{ translation: "hinterhältiger Mensch" }, | ||
], | ||
alternativeWords: null, | ||
relatedWords: { | ||
nodes: [ | ||
{ id: "cG9zdDo0MjUz", wordProperties: { berlinerisch: "Aas" }, slug: "aas" }, | ||
{ | ||
id: "cG9zdDo0MjU0", | ||
wordProperties: { berlinerisch: "Abeetadenkmal" }, | ||
slug: "abeetadenkmal", | ||
}, | ||
{ | ||
id: "cG9zdDo0Njkx", | ||
wordProperties: { berlinerisch: "abfahren " }, | ||
slug: "abfahren", | ||
}, | ||
], | ||
}, | ||
wikimediaFiles: null, | ||
images: null, | ||
}, | ||
berlinerischWordTypes: { nodes: [{ name: "Substantiv" }] }, | ||
}, | ||
{ | ||
id: "cG9zdDo0MjU0", | ||
slug: "abeetadenkmal", | ||
wordGroup: "A", | ||
dateGmt: "2022-01-22T17:39:21", | ||
modifiedGmt: "2022-06-03T11:20:04", | ||
berlinerWordId: 4254, | ||
wordProperties: { | ||
article: null, | ||
berlinerisch: "Abeetadenkmal", | ||
berlinerischAudio: null, | ||
learnMore: null, | ||
berolinismus: false, | ||
examples: [ | ||
{ | ||
example: "Der steht da mit seine Schaufel wie ‘n Abeetadenkmal.", | ||
exampleExplanation: null, | ||
exampleAudio: null, | ||
}, | ||
], | ||
translations: [{ translation: "Arbeiterdenkmal" }, { translation: "fauler Arbeiter" }], | ||
alternativeWords: null, | ||
relatedWords: null, | ||
wikimediaFiles: null, | ||
images: null, | ||
}, | ||
berlinerischWordTypes: { nodes: [{ name: "Substantiv" }] }, | ||
}, | ||
], | ||
activeLetterFilter: "A", | ||
}); | ||
|
||
worker.onmessage = (e) => { | ||
expect(e.data).toEqual([{ wordGroup: "a" }]); | ||
}; | ||
}); | ||
}); |
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