Open History to see the last commit
1import type { EnvironmentSpeechModel } from "@t3tools/contracts";
2import { expect, it } from "vite-plus/test";
3
4import { filterSpeechModels } from "./speechModelBrowser";
5
6const model: EnvironmentSpeechModel = {
7 id: "active",
8 name: "Active",
9 description: "Local transcription",
10 size: 300,
11 languages: ["en", "fr"],
12 accuracy: 1,
13 speed: 1,
14 recommended: false,
15 supportsStreaming: false,
16 supportsLanguageDetection: false,
17 supportsTranslation: false,
18 active: true,
19 state: "installed",
20};
21const models: readonly EnvironmentSpeechModel[] = [
22 model,
23 {
24 ...model,
25 id: "small",
26 name: "Small",
27 size: 100,
28 active: false,
29 state: "downloadable",
30 recommended: true,
31 benchmark: {
32 accuracy: {
33 en: { grade: "A", errorPercent: 3.8 },
34 fr: { grade: "B", errorPercent: 8 },
35 },
36 secondsPer30s: { cpu: 2, accelerated: 2 },
37 },
38 },
39 {
40 ...model,
41 id: "fast",
42 name: "Fast",
43 size: 200,
44 active: false,
45 benchmark: {
46 accuracy: {
47 en: { grade: "A", errorPercent: 3.2 },
48 fr: { grade: "B", errorPercent: 9 },
49 },
50 secondsPer30s: { cpu: 1, accelerated: 1 },
51 },
52 },
53 {
54 ...model,
55 id: "pending",
56 name: "Pending",
57 size: 400,
58 active: false,
59 state: "verifying",
60 languages: ["en"],
61 benchmark: { accuracy: {}, secondsPer30s: { cpu: null, accelerated: null } },
62 },
63];
64
65it.each([
66 ["recommended", "en", ["active", "fast", "pending", "small"]],
67 ["size", "en", ["small", "fast", "active", "pending"]],
68 ["speed", "en", ["fast", "small", "active", "pending"]],
69 ["accuracy", "en", ["fast", "small", "active", "pending"]],
70 ["accuracy", "fr", ["small", "fast", "active", "pending"]],
71] as const)(
72 "sorts by %s for %s with missing benchmarks last",
73 (sort, accuracyLanguage, expected) => {
74 expect(
75 filterSpeechModels(models, {
76 search: "",
77 languages: [],
78 downloadedOnly: false,
79 sort,
80 accuracyLanguage,
81 benchmarkTier: "accelerated",
82 }).map((entry) => entry.id),
83 ).toEqual(expected);
84 expect(models[0]?.id).toBe("active");
85 },
86);
87
88it("combines text, all selected languages, and completed downloads without retaining the active model", () => {
89 const options = {
90 search: " LOCAL ",
91 languages: ["en", "fr"],
92 downloadedOnly: true,
93 sort: "size",
94 accuracyLanguage: "en",
95 benchmarkTier: "accelerated",
96 } as const;
97 expect(filterSpeechModels(models, options).map((entry) => entry.id)).toEqual(["fast", "active"]);
98 expect(
99 filterSpeechModels(models, { ...options, search: "fast" }).map((entry) => entry.id),
100 ).toEqual(["fast"]);
101 expect(filterSpeechModels(models, { ...options, search: "small" })).toEqual([]);
102});