Skip to content

Commit e5c9eef

Browse files
AMBARI-26262: Ambari Admin React Build Fix & add missing files. (#3914)
co-authered by: Himanshu Maurya <himanshumaurya09876>
1 parent a087805 commit e5c9eef

File tree

13 files changed

+150
-68
lines changed

13 files changed

+150
-68
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
const mockClusterInfo = {
19+
"href" : "http://example.com",
20+
"items" : [
21+
{
22+
"href" : "http://example.com/api/v1/clusters/cluster1",
23+
"Clusters" : {
24+
"cluster_id" : 1,
25+
"cluster_name" : "cluster1"
26+
}
27+
}
28+
]
29+
};
30+
31+
export default mockClusterInfo;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
export enum ControlType {
19+
INPUT = "input",
20+
TEXT = "text",
21+
LINK = "link",
22+
CHECKBOX = "checkbox",
23+
}
24+
25+
export enum ClusterType {
26+
LOCAL = "LOCAL_AMBARI",
27+
REMOTE = "REMOTE_AMBARI",
28+
CUSTOM = "CUSTOM_AMBARI",
29+
}
30+
31+
export enum ViewTypes {
32+
FILES = "FILES",
33+
TEZ = "TEZ",
34+
CAPACITY_SCHEDULER = "CAPACITY-SCHEDULER",
35+
}
36+
37+
export enum EntityType {
38+
USER = "USER",
39+
GROUP = "GROUP",
40+
ROLE = "ROLE",
41+
}

ambari-admin/src/main/resources/ui/ambari-admin/src/tests/AddGroup.test.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ import AddGroup from "../screens/Users/AddGroup";
2020
import { describe, it, beforeEach, expect, vi } from "vitest";
2121
import "@testing-library/jest-dom/vitest";
2222
import UserGroupApi from "../api/userGroupApi";
23-
import { Router } from "react-router";
23+
import { HashRouter } from "react-router-dom";
2424
import AppContent from "../context/AppContext";
25-
import { createMemoryHistory } from "history";
2625
import toast from "react-hot-toast";
2726
import { userNames } from "../__mocks__/mockUserNames";
2827
import { GroupDataType } from "../api/types";
@@ -68,9 +67,9 @@ describe("AddGroup component", () => {
6867
const renderComponent = (props = mockProps) => {
6968
render(
7069
<AppContent.Provider value={mockContext}>
71-
<Router history={createMemoryHistory()}>
70+
<HashRouter>
7271
<AddGroup {...props} />
73-
</Router>
72+
</HashRouter>
7473
</AppContent.Provider>
7574
);
7675
};

ambari-admin/src/main/resources/ui/ambari-admin/src/tests/AddUser.test.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ import AddUser from "../screens/Users/AddUser";
2020
import { describe, it, beforeEach, expect, vi } from "vitest";
2121
import "@testing-library/jest-dom/vitest";
2222
import UserGroupApi from "../api/userGroupApi";
23-
import { Router } from "react-router";
23+
import { HashRouter } from "react-router-dom";
2424
import AppContent from "../context/AppContext";
25-
import { createMemoryHistory } from "history";
2625
import { rbacData } from "../__mocks__/mockRbacData";
2726
import toast from "react-hot-toast";
2827
import { UserDataType } from "../api/types";
@@ -67,9 +66,9 @@ describe("AddUser component", () => {
6766
const renderComponent = (props = mockProps) => {
6867
render(
6968
<AppContent.Provider value={mockContext}>
70-
<Router history={createMemoryHistory()}>
69+
<HashRouter>
7170
<AddUser {...props} />
72-
</Router>
71+
</HashRouter>
7372
</AppContent.Provider>
7473
);
7574
};

ambari-admin/src/main/resources/ui/ambari-admin/src/tests/DeregisterRemoteCluster.test.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
*/
1818
import { describe, it, expect, vi } from "vitest";
1919
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
20-
import { createMemoryHistory } from "history";
21-
import { Router } from "react-router-dom";
20+
import { HashRouter } from "react-router-dom";
2221
import "@testing-library/jest-dom/vitest";
2322
import RemoteClusterApi from "../api/remoteCluster";
2423
import DeregisterRemoteCluster from "../screens/ClusterManagement/RemoteClusters/DeregisterRemoteCluster";
@@ -35,9 +34,9 @@ const mockContext = {
3534
const renderDeregisterRemoteCluster = () => {
3635
render(
3736
<AppContent.Provider value={mockContext}>
38-
<Router history={createMemoryHistory()}>
37+
<HashRouter>
3938
<DeregisterRemoteCluster clusterName={mockClusterName} />
40-
</Router>
39+
</HashRouter>
4140
</AppContent.Provider>
4241
);
4342
};

ambari-admin/src/main/resources/ui/ambari-admin/src/tests/EditGroup.test.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ import { describe, it, beforeEach, expect, vi } from "vitest";
2121
import "@testing-library/jest-dom/vitest";
2222
import UserGroupApi from "../api/userGroupApi";
2323
import PrivilegeApi from "../api/privilegeApi";
24-
import { Router } from "react-router";
24+
import { HashRouter } from "react-router-dom";
2525
import AppContent from "../context/AppContext";
26-
import { createMemoryHistory } from "history";
2726
import toast from "react-hot-toast";
2827
import { rbacData } from "../__mocks__/mockRbacData";
2928
import { userNames } from "../__mocks__/mockUserNames";
@@ -66,9 +65,9 @@ describe("EditGroup component", () => {
6665
const renderComponent = () => {
6766
render(
6867
<AppContent.Provider value={mockContext}>
69-
<Router history={createMemoryHistory()}>
68+
<HashRouter>
7069
<EditGroup />
71-
</Router>
70+
</HashRouter>
7271
</AppContent.Provider>
7372
);
7473
};

ambari-admin/src/main/resources/ui/ambari-admin/src/tests/EditRemoteCluster.test.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import {
2323
waitFor,
2424
within,
2525
} from "@testing-library/react";
26-
import { createMemoryHistory } from "history";
27-
import { Router } from "react-router-dom";
26+
import { HashRouter } from "react-router-dom";
2827
import { mockClusterDataForEdit } from "../__mocks__/mockRemoteCluster";
2928
import "@testing-library/jest-dom/vitest";
3029
import RemoteClusterApi from "../api/remoteCluster";
@@ -41,9 +40,9 @@ const mockContext = {
4140
const renderEditRemoteCluster = () => {
4241
render(
4342
<AppContent.Provider value={mockContext}>
44-
<Router history={createMemoryHistory()}>
43+
<HashRouter>
4544
<EditRemoteCluster />
46-
</Router>
45+
</HashRouter>
4746
</AppContent.Provider>
4847
);
4948
};
@@ -96,12 +95,11 @@ describe("EditRemoteCluster component", () => {
9695
it("should redirect to /remoteCluster on clicking cancel button", async () => {
9796
RemoteClusterApi.getRemoteClusterByName = async () =>
9897
mockClusterDataForEdit;
99-
const history = createMemoryHistory();
10098
render(
10199
<AppContent.Provider value={mockContext}>
102-
<Router history={history}>
100+
<HashRouter>
103101
<EditRemoteCluster />
104-
</Router>
102+
</HashRouter>
105103
</AppContent.Provider>
106104
);
107105

@@ -113,7 +111,7 @@ describe("EditRemoteCluster component", () => {
113111
await waitFor(() => {});
114112

115113
await waitFor(() => {
116-
expect(history.location.pathname).toBe("/remoteClusters");
114+
expect(window.location.hash).toBe("#/remoteClusters");
117115
});
118116
});
119117

ambari-admin/src/main/resources/ui/ambari-admin/src/tests/EditUser.test.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ import EditUser from "../screens/Users/EditUser";
2020
import { describe, it, beforeEach, expect, vi } from "vitest";
2121
import "@testing-library/jest-dom/vitest";toast
2222
import UserGroupApi from "../api/userGroupApi";
23-
import { Router } from "react-router";
23+
import { HashRouter } from "react-router-dom";
2424
import AppContent from "../context/AppContext";
25-
import { createMemoryHistory } from "history";
2625
import toast from "react-hot-toast";
2726
import { rbacData } from "../__mocks__/mockRbacData";
2827
import { groupNames } from "../__mocks__/mockGroupNames";
@@ -66,9 +65,9 @@ describe("EditUser component", () => {
6665
const renderComponent = () => {
6766
render(
6867
<AppContent.Provider value={mockContext}>
69-
<Router history={createMemoryHistory()}>
68+
<HashRouter>
7069
<EditUser />
71-
</Router>
70+
</HashRouter>
7271
</AppContent.Provider>
7372
);
7473
};

ambari-admin/src/main/resources/ui/ambari-admin/src/tests/ListUsersGroups.test.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ import {
2525
import Users from "../screens/Users";
2626
import { describe, it, beforeEach, expect, vi } from "vitest";
2727
import "@testing-library/jest-dom/vitest";
28-
import { Router } from "react-router";
28+
import { HashRouter } from "react-router-dom";
2929
import AppContent from "../context/AppContext";
30-
import { createMemoryHistory } from "history";
3130
import UserGroupApi from "../api/userGroupApi";
3231
import { usersList, paginatedUsersList } from "../__mocks__/mockUsersList";
3332
import { groupsList, paginatedGroupsList } from "../__mocks__/mockGroupsList";
@@ -66,9 +65,9 @@ import {
6665
const renderUserComponent = () => {
6766
render(
6867
<AppContent.Provider value={mockContext}>
69-
<Router history={createMemoryHistory()}>
68+
<HashRouter>
7069
<Users />
71-
</Router>
70+
</HashRouter>
7271
</AppContent.Provider>
7372
);
7473
};

ambari-admin/src/main/resources/ui/ambari-admin/src/tests/RegisterRemoteCluster.test.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
*/
1818
import { describe, it, expect } from "vitest";
1919
import { render, screen, waitFor, fireEvent } from "@testing-library/react";
20-
import { createMemoryHistory } from "history";
21-
import { Router } from "react-router-dom";
20+
import { HashRouter } from "react-router-dom";
2221
import "@testing-library/jest-dom/vitest";
2322
import RemoteClusterApi from "../api/remoteCluster";
2423
import RegisterRemoteCluster from "../screens/ClusterManagement/RemoteClusters/RegisterRemoteCluster";
@@ -34,9 +33,9 @@ const mockContext = {
3433
const renderRegisterRemoteCluster = () => {
3534
render(
3635
<AppContent.Provider value={mockContext}>
37-
<Router history={createMemoryHistory()}>
36+
<HashRouter>
3837
<RegisterRemoteCluster />
39-
</Router>
38+
</HashRouter>
4039
</AppContent.Provider>
4140
);
4241
};
@@ -68,12 +67,11 @@ describe("RegisterRemoteCluster component", () => {
6867
});
6968

7069
it("should redirect to /remoteCluster on clicking cancel button", async () => {
71-
const history = createMemoryHistory();
7270
render(
7371
<AppContent.Provider value={mockContext}>
74-
<Router history={history}>
72+
<HashRouter>
7573
<RegisterRemoteCluster />
76-
</Router>
74+
</HashRouter>
7775
</AppContent.Provider>
7876
);
7977
expect(getClusterName()).toBeInTheDocument();
@@ -88,7 +86,7 @@ describe("RegisterRemoteCluster component", () => {
8886
await waitFor(() => {});
8987

9088
await waitFor(() => {
91-
expect(history.location.pathname).toBe("/remoteClusters");
89+
expect(window.location.hash).toBe("#/remoteClusters");
9290
});
9391
});
9492

0 commit comments

Comments
 (0)