1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix Deployment Scale Button "minus" (#1728)

Signed-off-by: vshakirova <vshakirova@mirantis.com>
This commit is contained in:
Violetta 2020-12-10 23:18:30 +04:00 committed by GitHub
parent d143b234b7
commit 961a38d52f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 20 deletions

View File

@ -128,33 +128,45 @@ describe("<DeploymentScaleDialog />", () => {
const initReplicas = 1; const initReplicas = 1;
deploymentApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas); deploymentApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas);
const { getByTestId } = render(<DeploymentScaleDialog />); const component = render(<DeploymentScaleDialog />);
DeploymentScaleDialog.open(dummyDeployment); DeploymentScaleDialog.open(dummyDeployment);
await waitFor(async () => { await waitFor(async () => {
const desiredScale = await getByTestId("desired-scale"); expect(await component.getByTestId("desired-scale")).toHaveTextContent(`${initReplicas}`);
expect(await component.getByTestId("current-scale")).toHaveTextContent(`${initReplicas}`);
expect(desiredScale).toHaveTextContent(`${initReplicas}`); expect((await component.baseElement.querySelector("input").value)).toBe(`${initReplicas}`);
}); });
const up = await getByTestId("desired-replicas-up"); const up = await component.getByTestId("desired-replicas-up");
const down = await getByTestId("desired-replicas-down"); const down = await component.getByTestId("desired-replicas-down");
fireEvent.click(up); fireEvent.click(up);
expect(await getByTestId("desired-scale")).toHaveTextContent(`${initReplicas + 1}`); expect(await component.getByTestId("desired-scale")).toHaveTextContent(`${initReplicas + 1}`);
fireEvent.click(down); expect(await component.getByTestId("current-scale")).toHaveTextContent(`${initReplicas}`);
expect(await getByTestId("desired-scale")).toHaveTextContent("1"); expect((await component.baseElement.querySelector("input").value)).toBe(`${initReplicas + 1}`);
// edge case, desiredScale must > 0
fireEvent.click(down); fireEvent.click(down);
fireEvent.click(down); expect(await component.getByTestId("desired-scale")).toHaveTextContent(`${initReplicas}`);
expect(await getByTestId("desired-scale")).toHaveTextContent("1"); expect(await component.getByTestId("current-scale")).toHaveTextContent(`${initReplicas}`);
const times = 120; expect((await component.baseElement.querySelector("input").value)).toBe(`${initReplicas}`);
// edge case, desiredScale must = 0
let times = 10;
for (let i = 0; i < times; i++) {
fireEvent.click(down);
}
expect(await component.getByTestId("desired-scale")).toHaveTextContent("0");
expect((await component.baseElement.querySelector("input").value)).toBe("0");
// edge case, desiredScale must = 100 scaleMax (100)
times = 120;
// edge case, desiredScale must < scaleMax (100)
for (let i = 0; i < times; i++) { for (let i = 0; i < times; i++) {
fireEvent.click(up); fireEvent.click(up);
} }
expect(await getByTestId("desired-scale")).toHaveTextContent("100"); expect(await component.getByTestId("desired-scale")).toHaveTextContent("100");
expect((component.baseElement.querySelector("input").value)).toBe("100");
expect(await component.getByTestId("warning"))
.toHaveTextContent("High number of replicas may cause cluster performance issues");
}); });
}); });

View File

@ -91,7 +91,7 @@ export class DeploymentScaleDialog extends Component<Props> {
}; };
desiredReplicasDown = () => { desiredReplicasDown = () => {
this.desiredReplicas > 1 && this.desiredReplicas--; this.desiredReplicas > 0 && this.desiredReplicas--;
}; };
renderContents() { renderContents() {
@ -124,7 +124,7 @@ export class DeploymentScaleDialog extends Component<Props> {
</div> </div>
</div> </div>
{warning && {warning &&
<div className="warning"> <div className="warning" data-testid="warning">
<Icon material="warning"/> <Icon material="warning"/>
<Trans>High number of replicas may cause cluster performance issues</Trans> <Trans>High number of replicas may cause cluster performance issues</Trans>
</div> </div>