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

Refactor after rebase from master

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
Signed-off-by: Hung-Han (Henry) Chen <1474479+chenhunghan@users.noreply.github.com>
This commit is contained in:
Hung-Han (Henry) Chen 2020-11-02 16:51:17 +08:00 committed by Hung-Han (Henry) Chen
parent d07c292f99
commit a807be545b
No known key found for this signature in database
GPG Key ID: 32931168425E1C95

View File

@ -107,17 +107,17 @@ describe('<DeploymentScaleDialog />', () => {
deploymentApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas); deploymentApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas);
const { getByTestId } = render(<DeploymentScaleDialog />); const { getByTestId } = render(<DeploymentScaleDialog />);
DeploymentScaleDialog.open(dummyDeployment); DeploymentScaleDialog.open(dummyDeployment);
let currentScale, desiredScale
// we need to wait for the DeploymentScaleDialog to show up // we need to wait for the DeploymentScaleDialog to show up
// because there is an <Animate /> in <Dialog /> which renders null at start. // because there is an <Animate /> in <Dialog /> which renders null at start.
await waitFor(async () => await waitFor(async () => {
[currentScale, desiredScale] = await Promise.all([ const [currentScale, desiredScale] = await Promise.all([
getByTestId('current-scale'), getByTestId('current-scale'),
getByTestId('desired-scale'), getByTestId('desired-scale'),
]) ])
); expect(currentScale).toHaveTextContent(`${initReplicas}`);
expect(currentScale).toHaveTextContent(`${initReplicas}`); expect(desiredScale).toHaveTextContent(`${initReplicas}`);
expect(desiredScale).toHaveTextContent(`${initReplicas}`); });
}); });
it('changes the desired scale when clicking the icon buttons +/-', async () => { it('changes the desired scale when clicking the icon buttons +/-', async () => {
@ -125,30 +125,26 @@ describe('<DeploymentScaleDialog />', () => {
deploymentApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas); deploymentApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas);
const { getByTestId } = render(<DeploymentScaleDialog />); const { getByTestId } = render(<DeploymentScaleDialog />);
DeploymentScaleDialog.open(dummyDeployment); DeploymentScaleDialog.open(dummyDeployment);
let desiredScale, up, down await waitFor(async () => {
await waitFor(async () => const desiredScale = await getByTestId('desired-scale');
[desiredScale, up, down] = await Promise.all([ expect(desiredScale).toHaveTextContent(`${initReplicas}`);
getByTestId('desired-scale'), });
getByTestId('desired-replicas-up'), const up = await getByTestId('desired-replicas-up');
getByTestId('desired-replicas-down'), const down = await getByTestId('desired-replicas-down')
])
);
// initially, the desired scale should equals to initReplicas
expect(desiredScale).toHaveTextContent(`${initReplicas}`);
fireEvent.click(up); fireEvent.click(up);
expect(desiredScale).toHaveTextContent('2'); expect(await getByTestId('desired-scale')).toHaveTextContent(`${initReplicas + 1}`);
fireEvent.click(down); fireEvent.click(down);
expect(desiredScale).toHaveTextContent('1'); expect(await getByTestId('desired-scale')).toHaveTextContent('1');
// edge case, desiredScale must > 0 // edge case, desiredScale must > 0
fireEvent.click(down); fireEvent.click(down);
fireEvent.click(down); fireEvent.click(down);
expect(desiredScale).toHaveTextContent('1'); expect(await getByTestId('desired-scale')).toHaveTextContent('1');
const times = 120; const times = 120;
// edge case, desiredScale must < scaleMax (100) // 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(desiredScale).toHaveTextContent('100'); expect(await getByTestId('desired-scale')).toHaveTextContent('100');
}); });
}); });