-
Notifications
You must be signed in to change notification settings - Fork 3
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 #96 from ligangty/2.0-refactor
Add Unit tests for Header and Footer
- Loading branch information
Showing
3 changed files
with
104 additions
and
7 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright (C) 2023 Red Hat, Inc. (https://github.com/Commonjava/indy-ui-service) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import React from "react"; | ||
import {render, screen, cleanup, waitFor} from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import NavFooter from "./NavFooter.jsx"; | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
describe('Footer tests', () => { | ||
it("Verify Footer for elements existing", async ()=>{ | ||
const mockStats = { | ||
version: "3.3.2", | ||
commitId: "f472176", | ||
builder: "test-builder", | ||
timestamp: "2023-10-24 05:54 +0000" | ||
}; | ||
global.fetch = jest.fn(() => Promise.resolve({ | ||
ok: true, | ||
json: () => Promise.resolve(mockStats), | ||
})); | ||
render(<NavFooter />); | ||
expect(screen.getByRole("link", {name: "Docs"})).toHaveAttribute("href", "http://commonjava.github.io/indy/"); | ||
expect(screen.getByRole("link", {name: "Issues"})).toHaveAttribute("href", "http://github.com/commonjava/indy/issues"); | ||
await waitFor(()=>{ | ||
expect(screen.getByText(`Version:${mockStats.version}`)).toBeInTheDocument(); | ||
expect(screen.getByRole("link", {name: mockStats.commitId})).toHaveAttribute("href", `http://github.com/commonjava/indy/commit/${mockStats.commitId}`); | ||
expect(screen.getByRole("link", {name: mockStats.builder})).toHaveAttribute("href", `http://github.com/${mockStats.builder}`); | ||
}); | ||
|
||
}); | ||
}); |
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,55 @@ | ||
/** | ||
* Copyright (C) 2023 Red Hat, Inc. (https://github.com/Commonjava/indy-ui-service) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import React from "react"; | ||
import {render, screen, cleanup} from '@testing-library/react'; | ||
import userEvent from "@testing-library/user-event"; | ||
import {MemoryRouter} from 'react-router-dom'; | ||
import '@testing-library/jest-dom'; | ||
import NavHeader from "./NavHeader.jsx"; | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
describe('Header tests', () => { | ||
it("Verify Header for elements existing", async ()=>{ | ||
const user = userEvent.setup(); | ||
render(<MemoryRouter><NavHeader /></MemoryRouter>); | ||
expect(screen.getByRole("link", {Name: "Indy"})).toBeInTheDocument(); | ||
const remoteReposButton = screen.getByRole("button", {name: "Remote Repositories"}); | ||
expect(remoteReposButton).toBeInTheDocument(); | ||
const hostedReposButton = screen.getByRole("button", {name: "Hosted Repositories"}); | ||
expect(hostedReposButton).toBeInTheDocument(); | ||
const groupsButton = screen.getByRole("button", {name: "Groups"}); | ||
expect(groupsButton).toBeInTheDocument(); | ||
expect(screen.getByRole("button", {name: "REST API"})).toBeInTheDocument(); | ||
const addonsButton = screen.getByRole("button", {name: "more"}); | ||
expect(addonsButton).toBeInTheDocument(); | ||
// TODO: test the user login elements later when implemented | ||
|
||
await user.click(remoteReposButton); | ||
await user.click(hostedReposButton); | ||
await user.click(groupsButton); | ||
expect(screen.getAllByRole("link", {name: "maven"})).toHaveLength(3); | ||
expect(screen.getAllByRole("link", {name: "generic-http"})).toHaveLength(3); | ||
expect(screen.getAllByRole("link", {name: "npm"})).toHaveLength(3); | ||
|
||
await user.click(addonsButton); | ||
expect(screen.getByRole("link", {name: "Not-Found Cache"})).toBeInTheDocument(); | ||
expect(screen.getByRole("link", {name: "Delete Cache"})).toBeInTheDocument(); | ||
}); | ||
}); |