|
1 | 1 | import type { AppData, ProviderDefinition, RunLog } from "./model"; |
2 | 2 |
|
3 | 3 | import { describe, expect, it } from "vitest"; |
4 | | -import { createOverviewSummary, resolveProviderConnectionStatus, sortProviders } from "./model"; |
| 4 | +import { |
| 5 | + createOverviewSummary, |
| 6 | + filterProvidersByCategory, |
| 7 | + providerCategoryCounts, |
| 8 | + resolveProviderConnectionStatus, |
| 9 | + sortProviders, |
| 10 | +} from "./model"; |
5 | 11 |
|
6 | 12 | function provider(service: string, displayName: string): ProviderDefinition { |
7 | 13 | return { |
@@ -101,6 +107,56 @@ describe("sortProviders", () => { |
101 | 107 | }); |
102 | 108 | }); |
103 | 109 |
|
| 110 | +describe("filterProvidersByCategory", () => { |
| 111 | + function categorized(service: string, categories: string[]): ProviderDefinition { |
| 112 | + return { ...provider(service, service), categories }; |
| 113 | + } |
| 114 | + |
| 115 | + it("returns everything for the all filter", () => { |
| 116 | + const providers = [categorized("a", ["Data"]), categorized("b", ["Communication"])]; |
| 117 | + |
| 118 | + expect(filterProvidersByCategory(providers, "all")).toEqual(providers); |
| 119 | + }); |
| 120 | + |
| 121 | + it("keeps only providers in the selected category", () => { |
| 122 | + const providers = [ |
| 123 | + categorized("a", ["Data"]), |
| 124 | + categorized("b", ["Communication"]), |
| 125 | + categorized("c", ["Data", "AI"]), |
| 126 | + ]; |
| 127 | + |
| 128 | + expect(filterProvidersByCategory(providers, "Data").map((item) => item.service)).toEqual(["a", "c"]); |
| 129 | + expect(filterProvidersByCategory(providers, "AI").map((item) => item.service)).toEqual(["c"]); |
| 130 | + }); |
| 131 | + |
| 132 | + it("returns nothing for an unmatched category", () => { |
| 133 | + const providers = [categorized("a", ["Data"])]; |
| 134 | + |
| 135 | + expect(filterProvidersByCategory(providers, "Storage")).toEqual([]); |
| 136 | + }); |
| 137 | +}); |
| 138 | + |
| 139 | +describe("providerCategoryCounts", () => { |
| 140 | + it("counts providers per category, including multi-category providers once per category", () => { |
| 141 | + const providers = [ |
| 142 | + { ...provider("a", "a"), categories: ["Data", "AI"] }, |
| 143 | + { ...provider("b", "b"), categories: ["Data"] }, |
| 144 | + { ...provider("c", "c"), categories: ["Communication"] }, |
| 145 | + ]; |
| 146 | + |
| 147 | + const counts = providerCategoryCounts(providers); |
| 148 | + expect(counts.get("Data")).toBe(2); |
| 149 | + expect(counts.get("AI")).toBe(1); |
| 150 | + expect(counts.get("Communication")).toBe(1); |
| 151 | + expect(counts.get("Storage")).toBeUndefined(); |
| 152 | + }); |
| 153 | + |
| 154 | + it("handles providers without categories", () => { |
| 155 | + const counts = providerCategoryCounts([provider("a", "a"), provider("b", "b")]); |
| 156 | + expect(counts.size).toBe(0); |
| 157 | + }); |
| 158 | +}); |
| 159 | + |
104 | 160 | describe("createOverviewSummary", () => { |
105 | 161 | it("counts locally executable actions", () => { |
106 | 162 | const clock = { |
|
0 commit comments