Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Apr 11, 2024
1 parent 6c396b4 commit a7a833e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
4 changes: 4 additions & 0 deletions web/src/client/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ const ZFCP_DISK_IFACE = "org.opensuse.Agama.Storage1.ZFCP.Disk";
* @property {boolean} subvol
* @property {boolean} delete
*
* @todo Define an enum for space policies.
*
* @typedef {object} ProposalSettings
* @property {ProposalTarget} target
* @property {string} [targetDevice]
Expand Down Expand Up @@ -144,6 +146,8 @@ const ZFCP_DISK_IFACE = "org.opensuse.Agama.Storage1.ZFCP.Disk";
*
* @typedef {keyof VolumeTargets} VolumeTarget
*
* @todo Define an enum for file system types.
*
* @typedef {object} VolumeOutline
* @property {boolean} required
* @property {string[]} fsTypes
Expand Down
7 changes: 7 additions & 0 deletions web/src/components/storage/ProposalPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ export default function ProposalPage() {
calculate(newSettings).catch(console.error);
};

/**
* @todo Enable type checking and ensure the components are called with the correct props.
*
* @note The default value for `settings` should be `undefined` instead of an empty object, and
* the settings prop of the components should accept both a ProposalSettings object or undefined.
*/

return (
// TRANSLATORS: Storage page title
<Page icon="hard_drive" title={_("Storage")}>
Expand Down
55 changes: 38 additions & 17 deletions web/src/components/storage/ProposalSettingsSection.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,33 @@ jest.mock("@patternfly/react-core", () => {
};
});

/** @type {Volume} */
let volume;

/** @type {ProposalSettingsSectionProps} */
let props;

beforeEach(() => {
volume = {
mountPath: "/",
target: "DEFAULT",
fsType: "Btrfs",
minSize: 1024,
maxSize: 2048,
autoSize: false,
snapshots: false,
transactional: false,
outline: {
required: true,
fsTypes: ["Btrfs", "Ext4"],
supportAutoSize: true,
snapshotsConfigurable: true,
snapshotsAffectSizes: true,
sizeRelevantVolumes: [],
adjustByRam: false
}
};

props = {
settings: {
target: "DISK",
Expand All @@ -66,11 +89,9 @@ beforeEach(() => {
};
});

const rootVolume = { mountPath: "/", fsType: "Btrfs", outline: { snapshotsConfigurable: true } };

describe("if snapshots are configurable", () => {
beforeEach(() => {
props.settings = { volumes: [rootVolume] };
props.settings.volumes = [volume];
});

it("renders the snapshots switch", () => {
Expand All @@ -82,7 +103,7 @@ describe("if snapshots are configurable", () => {

describe("if snapshots are not configurable", () => {
beforeEach(() => {
props.settings = { volumes: [{ ...rootVolume, outline: { ...rootVolume.outline, snapshotsConfigurable: false } }] };
volume.outline.snapshotsConfigurable = false;
});

it("does not render the snapshots switch", () => {
Expand Down Expand Up @@ -115,9 +136,10 @@ it("requests a volume change when onChange callback is triggered", async () => {
});

describe("Encryption field", () => {
describe("if encryption password setting is not set yet", () => {
describe.skip("if encryption password setting is not set yet", () => {
beforeEach(() => {
props.settings = {};
// Currently settings cannot be undefined.
props.settings = undefined;
});

it("does not render the encryption switch", () => {
Expand All @@ -129,7 +151,7 @@ describe("Encryption field", () => {

describe("if encryption password setting is set", () => {
beforeEach(() => {
props.settings = { encryptionPassword: "" };
props.settings.encryptionPassword = "";
});

it("renders the encryption switch", () => {
Expand All @@ -141,8 +163,7 @@ describe("Encryption field", () => {

describe("if encryption password is not empty", () => {
beforeEach(() => {
props.settings = { encryptionPassword: "1234" };
props.onChange = jest.fn();
props.settings.encryptionPassword = "1234";
});

it("renders the encryption switch as selected", () => {
Expand Down Expand Up @@ -203,8 +224,7 @@ describe("Encryption field", () => {

describe("if encryption password is empty", () => {
beforeEach(() => {
props.settings = { encryptionPassword: "" };
props.onChange = jest.fn();
props.settings.encryptionPassword = "";
});

it("renders the encryption switch as not selected", () => {
Expand Down Expand Up @@ -263,9 +283,10 @@ describe("Encryption field", () => {
});

describe("Space policy field", () => {
describe("if there is no space policy", () => {
describe.skip("if there is no space policy", () => {
beforeEach(() => {
props.settings = {};
// Currently settings cannot be undefined.
props.settings = undefined;
});

it("does not render the space policy field", () => {
Expand All @@ -277,15 +298,15 @@ describe("Space policy field", () => {

describe("if there is a space policy", () => {
beforeEach(() => {
props.settings = {
spacePolicy: "delete"
};
props.settings.spacePolicy = "delete";
});

it("renders the button with a text according to given policy", () => {
const { rerender } = plainRender(<ProposalSettingsSection {...props} />);
screen.getByRole("button", { name: /deleting/ });
rerender(<ProposalSettingsSection settings={{ spacePolicy: "resize" }} />);

props.settings.spacePolicy = "resize";
rerender(<ProposalSettingsSection {...props} />);
screen.getByRole("button", { name: /shrinking/ });
});

Expand Down

0 comments on commit a7a833e

Please sign in to comment.