test: added test and fixed reload issue

This commit is contained in:
Pablo F.G
2026-03-27 08:31:01 +01:00
parent d8b677ec11
commit 0977844bc7
6 changed files with 867 additions and 562 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -149,4 +149,13 @@ export class ProfileOrganizationsHarness {
async cancel() {
await this.cancelButton().click();
}
async submitDelete() {
await this.submitButton(/delete/i).click();
}
async selectTargetTenant(name: string) {
await this.targetTenantSelect().click();
await this.orgName(name).last().click();
}
}

View File

@@ -8,6 +8,7 @@ import {
switchTenant,
SwitchTenantState,
} from "@/actions/users/tenants";
import { reloadPage } from "@/lib/navigation";
import { useToast } from "@/components/ui";
import { CustomServerInput } from "@/components/ui/custom";
import { FormButtons } from "@/components/ui/form";
@@ -39,7 +40,7 @@ export const CreateTenantForm = ({
title: "Organization created",
description: "Switching to the new organization.",
});
window.location.reload();
reloadPage();
} else {
// Create succeeded but switch failed — org exists, user can switch manually
toast({

View File

@@ -16,6 +16,7 @@ vi.mock("@/auth.config", () => ({
vi.mock("@/actions/users/tenants", () => ({
deleteTenant: vi.fn(),
switchTenant: vi.fn(),
switchThenDeleteTenant: vi.fn(),
}));
const mockToast = vi.fn();

View File

@@ -4,6 +4,7 @@ import { useSession } from "next-auth/react";
import { Dispatch, SetStateAction, useActionState, useEffect } from "react";
import { switchTenant } from "@/actions/users/tenants";
import { reloadPage } from "@/lib/navigation";
import { useToast } from "@/components/ui";
import { FormButtons } from "@/components/ui/form";
@@ -30,7 +31,7 @@ export const SwitchTenantForm = ({
title: "Organization switched",
description: "The page will reload to apply the change.",
});
window.location.reload();
reloadPage();
} else {
toast({
variant: "destructive",

View File

@@ -2,7 +2,7 @@ import { http, HttpResponse } from "msw";
const API_BASE =
process.env.NEXT_PUBLIC_API_BASE_URL ?? "https://api.test.prowler.com/api/v1";
1;
/**
* Default MSW handlers for the prowler backend API.
* These provide sensible defaults for server action tests.