Skip to content

Commit 06f259f

Browse files
dvaldiviacesnietor
andauthored
Run React Tests (#508)
Co-authored-by: Cesar N <[email protected]>
1 parent 77e7491 commit 06f259f

File tree

5 files changed

+196
-124
lines changed

5 files changed

+196
-124
lines changed

.github/workflows/react.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: "React Tests"
2+
on:
3+
push:
4+
pull_request:
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Install modules
11+
working-directory: ./portal-ui
12+
run: yarn
13+
- name: Run tests
14+
working-directory: ./portal-ui
15+
run: yarn test

portal-ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
},
7575
"proxy": "http://localhost:9090/",
7676
"devDependencies": {
77+
"jest": "^24.9.0",
7778
"prettier": "^1.19.1",
7879
"typescript": "^4.1.2"
7980
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// This file is part of MinIO Console Server
2+
// Copyright (c) 2020 MinIO, Inc.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
import { getBytes, niceBytes, setMemoryResource } from "../utils";
18+
19+
test("A variety of formatting results", () => {
20+
expect(niceBytes("1024")).toBe("1.0 KiB");
21+
expect(niceBytes("1048576")).toBe("1.0 MiB");
22+
expect(niceBytes("1073741824")).toBe("1.0 GiB");
23+
});
24+
25+
test("From value and unit to a number of bytes", () => {
26+
expect(getBytes("1", "KiB")).toBe("1024");
27+
expect(getBytes("1", "MiB")).toBe("1048576");
28+
expect(getBytes("1", "GiB")).toBe("1073741824");
29+
});
30+
31+
test("From value and unit to a number of bytes for kubernetes", () => {
32+
expect(getBytes("1", "Ki", true)).toBe("1024");
33+
expect(getBytes("1", "Mi", true)).toBe("1048576");
34+
expect(getBytes("1", "Gi", true)).toBe("1073741824");
35+
});
36+
37+
test("Determine the amount of memory to use", () => {
38+
expect(setMemoryResource(1024, "1024", 1024)).toStrictEqual({
39+
error: "There are not enough memory resources available",
40+
limit: 0,
41+
request: 0,
42+
});
43+
expect(setMemoryResource(64, "1099511627776", 34359738368)).toStrictEqual({
44+
error:
45+
"The requested memory is greater than the max available memory for the selected number of nodes",
46+
limit: 0,
47+
request: 0,
48+
});
49+
expect(setMemoryResource(2, "17179869184", 34359738368)).toStrictEqual({
50+
error: "",
51+
limit: 34359738368,
52+
request: 2147483648,
53+
});
54+
});

portal-ui/src/common/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ export const k8sfactorForDropdown = () => {
9494
export const getBytes = (
9595
value: string,
9696
unit: string,
97-
fork8s: boolean = false
97+
fromk8s: boolean = false
9898
) => {
9999
const vl: number = parseFloat(value);
100100

101-
const unitsTake = fork8s ? k8sCalcUnits : units;
101+
const unitsTake = fromk8s ? k8sCalcUnits : units;
102102

103103
const powFactor = unitsTake.findIndex((element) => element === unit);
104104

0 commit comments

Comments
 (0)