-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from sinamics/more_tests
Added more tests
- Loading branch information
Showing
13 changed files
with
1,860 additions
and
987 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"recommendations": ["prisma.prisma"] | ||
} | ||
"recommendations": [ | ||
"prisma.prisma", | ||
"rome.rome" | ||
] | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
import "@testing-library/jest-dom"; | ||
|
||
jest.mock("../../utils/api", () => ({ | ||
api: { | ||
admin: { | ||
getAllOptions: { | ||
useQuery: () => ({ | ||
data: {}, | ||
isLoading: false, | ||
refetch: jest.fn(), | ||
}), | ||
}, | ||
}, | ||
networkMember: { | ||
getNetworkMemberById: { | ||
useQuery: () => ({ | ||
data: {}, | ||
isLoading: false, | ||
refetch: jest.fn(), | ||
}), | ||
}, | ||
updateNetworkMember: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
deleteNetworkMember: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
stash: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
UpdateDatabaseOnly: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
create: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
delete: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
Update: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
} | ||
}, | ||
network: { | ||
getNetworkById: { | ||
useQuery: () => ({ | ||
data: { | ||
network: { | ||
nwid: "1234567890", | ||
name: "Test Network", | ||
private: true, | ||
ipAssignmentPools: [ | ||
{ ipRangeStart: "10.0.0.1", ipRangeEnd: "10.0.0.254" }, | ||
], | ||
routes: [{ target: "10.0.0.0/24" }], | ||
dns: { | ||
domain: "", | ||
servers: [], | ||
}, | ||
tags: [], | ||
multicastLimit: 32, | ||
enableBroadcast: true, | ||
rutes: [ | ||
{ | ||
target: "172.25.28.0/24", | ||
via: null, | ||
}, | ||
], | ||
rules: [ | ||
{ | ||
not: false, | ||
or: false, | ||
type: "ACTION_ACCEPT", | ||
}, | ||
], | ||
v4AssignMode: { | ||
zt: false, // Changed state to checked | ||
}, | ||
}, | ||
members: [], | ||
zombieMembers: [], | ||
}, | ||
isLoading: false, | ||
refetch: jest.fn(), | ||
}), | ||
}, | ||
updateNetwork: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
getFlowRule: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
setFlowRule: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
deleteNetwork: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
inviteUserByMail: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
networkName: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
networkDescription: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
privatePublicNetwork: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
enableIpv4AutoAssign: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
easyIpAssignment: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
advancedIpAssignment: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
managedRoutes: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
dns: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
multiCast: { | ||
useMutation: () => ({ | ||
mutate: jest.fn(), | ||
}), | ||
}, | ||
}, | ||
}, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,14 +21,14 @@ describe("LoginForm", () => { | |
}); | ||
|
||
it("renders the LoginForm component", () => { | ||
render(<LoginForm />); | ||
render(<LoginForm setViewForgotForm={() => {}} />); | ||
expect( | ||
screen.getByRole("heading", { name: /Sign In/i }), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it("updates email and password inputs on change", () => { | ||
render(<LoginForm />); | ||
render(<LoginForm setViewForgotForm={() => {}} />); | ||
|
||
const emailInput = screen.getByPlaceholderText("[email protected]"); | ||
const passwordInput = screen.getByPlaceholderText("Enter your password"); | ||
|
@@ -41,7 +41,7 @@ describe("LoginForm", () => { | |
}); | ||
|
||
it("submits the form with correct email and password", async () => { | ||
render(<LoginForm />); | ||
render(<LoginForm setViewForgotForm={() => {}} />); | ||
|
||
(signIn as jest.Mock).mockResolvedValue({}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import "../__mocks__/networkById"; | ||
import { render, screen, fireEvent, waitFor } from "@testing-library/react"; | ||
import { NetworkDns } from "~/components/modules/networkDns"; | ||
import { NextRouter, useRouter } from "next/router"; | ||
import { api } from "~/utils/api"; | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
import { NextIntlProvider } from "next-intl"; | ||
import enTranslation from "~/locales/en/common.json"; | ||
|
||
// Mocking the next/router module | ||
jest.mock("next/router", () => ({ | ||
useRouter: jest.fn(), | ||
})); | ||
|
||
const mockedRouter: Partial<NextRouter> = { | ||
query: { | ||
id: "test-id", | ||
}, | ||
}; | ||
const mockUseRouter = useRouter as jest.MockedFunction<typeof useRouter>; | ||
mockUseRouter.mockReturnValue(mockedRouter as NextRouter); | ||
|
||
describe("<NetworkDns />", () => { | ||
let queryClient: QueryClient; | ||
|
||
beforeEach(() => { | ||
queryClient = new QueryClient(); | ||
(useRouter as jest.Mock).mockImplementation(() => ({ | ||
query: { | ||
id: "test-id", | ||
}, | ||
})); | ||
}); | ||
it("sends the correct DNS IP to the server when submitted", async () => { | ||
const mockMutation = jest.fn(); | ||
|
||
const useQueryMock = jest.fn().mockReturnValue({ | ||
data: { | ||
network: { | ||
nwid: "test-id", | ||
dns: { | ||
domain: "", | ||
servers: [], | ||
}, | ||
}, | ||
}, | ||
isLoading: false, | ||
refetch: jest.fn(), | ||
}); | ||
|
||
api.network.getNetworkById.useQuery = useQueryMock; | ||
api.network.dns.useMutation = jest.fn().mockReturnValue({ | ||
mutate: mockMutation, | ||
}); | ||
|
||
render( | ||
<QueryClientProvider client={queryClient}> | ||
<NextIntlProvider locale="en" messages={enTranslation}> | ||
<NetworkDns /> | ||
</NextIntlProvider> | ||
</QueryClientProvider>, | ||
); | ||
|
||
// Simulate typing in the DNS IP address | ||
const dnsInput = screen.getByPlaceholderText("10.147.20.190"); | ||
fireEvent.change(dnsInput, { target: { value: "192.168.1.1" } }); | ||
|
||
const dnsDomain = screen.getByPlaceholderText("home.arpa"); | ||
fireEvent.change(dnsDomain, { target: { value: "test-domain" } }); | ||
|
||
// Simulate clicking the submit button | ||
const submitButton = screen.getByText("Submit"); | ||
fireEvent.click(submitButton); | ||
|
||
// Verify the mock API mutation is called with the right value | ||
await waitFor(() => { | ||
expect(mockMutation).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
central: false, | ||
nwid: "test-id", | ||
updateParams: { | ||
dns: { | ||
domain: "test-domain", | ||
servers: ["192.168.1.1"], | ||
}, | ||
}, | ||
}), | ||
expect.anything(), | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.