Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions web/package/agama-web-ui.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Jan 8 13:12:44 UTC 2025 - David Diaz <dgonzalez@suse.com>

- Show the cancel action at product selection page only when
a product is already selected (gh#agama-project/agama#1881).

-------------------------------------------------------------------
Fri Dec 20 12:53:41 UTC 2024 - David Diaz <dgonzalez@suse.com>

Expand Down
66 changes: 46 additions & 20 deletions web/src/components/product/ProductSelectionPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { ProductSelectionPage } from "~/components/product";
import { Product } from "~/types/software";
import { useProduct } from "~/queries/software";

const mockConfigMutation = jest.fn();
const tumbleweed: Product = {
id: "Tumbleweed",
name: "openSUSE Tumbleweed",
Expand All @@ -42,37 +41,64 @@ const microOs: Product = {
description: "MicroOS description",
};

const mockConfigMutation = jest.fn();
let mockSelectedProduct: Product;

jest.mock("~/queries/software", () => ({
...jest.requireActual("~/queries/software"),
useProduct: (): ReturnType<typeof useProduct> => {
return {
products: [tumbleweed, microOs],
selectedProduct: tumbleweed,
selectedProduct: mockSelectedProduct,
};
},
useProductChanges: () => jest.fn(),
useConfigMutation: () => ({ mutate: mockConfigMutation }),
}));

describe("when the user chooses a product and hits the confirmation button", () => {
it("triggers the product selection", async () => {
const { user } = installerRender(<ProductSelectionPage />);
const productOption = screen.getByRole("radio", { name: microOs.name });
const selectButton = screen.getByRole("button", { name: "Select" });
await user.click(productOption);
await user.click(selectButton);
expect(mockConfigMutation).toHaveBeenCalledWith({ product: microOs.id });
describe("ProductSelectionPage", () => {
beforeEach(() => {
mockSelectedProduct = tumbleweed;
});

describe("when there is a product already selected", () => {
it("renders the Cancel button", () => {
installerRender(<ProductSelectionPage />);
screen.getByRole("button", { name: "Cancel" });
});
});

describe("when there is not a product selected yet", () => {
beforeEach(() => {
mockSelectedProduct = undefined;
});

it("does not render the Cancel button", () => {
installerRender(<ProductSelectionPage />);
expect(screen.queryByRole("button", { name: "Cancel" })).toBeNull();
});
});

describe("when the user chooses a product and hits the confirmation button", () => {
it("triggers the product selection", async () => {
const { user } = installerRender(<ProductSelectionPage />);
const productOption = screen.getByRole("radio", { name: microOs.name });
const selectButton = screen.getByRole("button", { name: "Select" });
await user.click(productOption);
await user.click(selectButton);
expect(mockConfigMutation).toHaveBeenCalledWith({ product: microOs.id });
});
});
});

describe("when the user chooses a product but hits the cancel button", () => {
it("does not trigger the product selection and goes back", async () => {
const { user } = installerRender(<ProductSelectionPage />);
const productOption = screen.getByRole("radio", { name: microOs.name });
const cancelButton = screen.getByRole("button", { name: "Cancel" });
await user.click(productOption);
await user.click(cancelButton);
expect(mockConfigMutation).not.toHaveBeenCalled();
expect(mockNavigateFn).toHaveBeenCalledWith("/");
describe("when the user chooses a product but hits the cancel button", () => {
it("does not trigger the product selection and goes back", async () => {
const { user } = installerRender(<ProductSelectionPage />);
const productOption = screen.getByRole("radio", { name: microOs.name });
const cancelButton = screen.getByRole("button", { name: "Cancel" });
await user.click(productOption);
await user.click(cancelButton);
expect(mockConfigMutation).not.toHaveBeenCalled();
expect(mockNavigateFn).toHaveBeenCalledWith("/");
});
});
});
2 changes: 1 addition & 1 deletion web/src/components/product/ProductSelectionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function ProductSelectionPage() {
</Center>
</Page.Content>
<Page.Actions>
<BackLink />
{selectedProduct && !isLoading && <BackLink />}
<Page.Submit
form="productSelectionForm"
isDisabled={isSelectionDisabled}
Expand Down