Skip to content

Commit

Permalink
Make sidebarEntryFactory type safe
Browse files Browse the repository at this point in the history
  • Loading branch information
twschiller committed Jul 6, 2024
1 parent 09b2a67 commit 876a1c2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/sidebar/activateMod/ActivateModPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function setupMocksAndRender(
appApiMock.onGet().reply(200, []);

const entry = sidebarEntryFactory("activateMods", {
modIds: [modDefinition.metadata.id],
mods: [{ modId: modDefinition.metadata.id, initialOptions: {} }],
heading: "Activate Mod",
});

Expand Down
4 changes: 2 additions & 2 deletions src/store/sidebar/eventKeyUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ describe("eventKeyForEntry", () => {
expect(eventKeyForEntry(value)).toBeNull();
});

it("uses modId for activateRecipe", () => {
it("uses modId for activateMods", () => {
const modId = validateRegistryId("@test/test-recipe");
const entry = sidebarEntryFactory("activateMods", {
modComponentRef: modComponentRefFactory({ blueprintId: modId }),
mods: [{ modId, initialOptions: {} }],
});
// Main part is an object hash of the mod ids
expect(eventKeyForEntry(entry)).toStartWith("activate-");
Expand Down
22 changes: 11 additions & 11 deletions src/testUtils/factories/sidebarEntryFactories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,27 @@ const panelEntryFactory = define<PanelEntry>({
heading: (n: number) => `Panel Test ${n}`,
payload: null,
});
export function sidebarEntryFactory<T = PanelEntry>(
export function sidebarEntryFactory(
type: "panel",
override?: FactoryConfig<T>,
override?: FactoryConfig<PanelEntry>,
): PanelEntry;
export function sidebarEntryFactory<T = TemporaryPanelEntry>(
export function sidebarEntryFactory(
type: "temporaryPanel",
override?: FactoryConfig<T>,
override?: FactoryConfig<TemporaryPanelEntry>,
): TemporaryPanelEntry;
export function sidebarEntryFactory<T = FormPanelEntry>(
export function sidebarEntryFactory(
type: "form",
override?: FactoryConfig<T>,
override?: FactoryConfig<FormPanelEntry>,
): FormPanelEntry;
export function sidebarEntryFactory<T = ModActivationPanelEntry>(
export function sidebarEntryFactory(
type: "activateMods",
override?: FactoryConfig<T>,
override?: FactoryConfig<ModActivationPanelEntry>,
): ModActivationPanelEntry;
export function sidebarEntryFactory<T = StaticPanelEntry>(
export function sidebarEntryFactory(
type: "staticPanel",
override?: FactoryConfig<T>,
override?: FactoryConfig<StaticPanelEntry>,
): StaticPanelEntry;
export function sidebarEntryFactory<T = SidebarEntry>(
export function sidebarEntryFactory<T extends SidebarEntry = SidebarEntry>(
type: EntryType,
override?: FactoryConfig<T>,
): SidebarEntry {
Expand Down

0 comments on commit 876a1c2

Please sign in to comment.