Fix Deployment Scale Button "minus" (#1728)

Signed-off-by: vshakirova <vshakirova@mirantis.com>
This commit is contained in:
Violetta authored and GitHub committed 2020-12-10 21:18:30 +02:00
1 parent d143b234b7
commit 961a38d52f
2 files changed
+31 -19

No files matched your search

@@ -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}`);
expect(await component.getByTestId("current-scale")).toHaveTextContent(`${initReplicas}`);
expect((await component.baseElement.querySelector("input").value)).toBe(`${initReplicas + 1}`);
fireEvent.click(down); fireEvent.click(down);
expect(await getByTestId("desired-scale")).toHaveTextContent("1"); expect(await component.getByTestId("desired-scale")).toHaveTextContent(`${initReplicas}`);
// edge case, desiredScale must > 0 expect(await component.getByTestId("current-scale")).toHaveTextContent(`${initReplicas}`);
fireEvent.click(down); expect((await component.baseElement.querySelector("input").value)).toBe(`${initReplicas}`);
fireEvent.click(down);
expect(await getByTestId("desired-scale")).toHaveTextContent("1"); // edge case, desiredScale must = 0
const times = 120; 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");
}); });
}); });
@@ -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>