-
-
Notifications
You must be signed in to change notification settings - Fork 201
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 #26 from oslabs-beta/testing
added unit tests to website components
- Loading branch information
Showing
8 changed files
with
108 additions
and
37 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
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,39 @@ | ||
import {screen, render, fireEvent} from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import LandingPage from '../src/pages/components/LandingPage'; | ||
import Blogs from '../src/pages/components/Blogs'; | ||
import People from '../src/pages/components/TeamSection'; | ||
import FeaturesSection from '../src/pages/components/FeaturesSection'; | ||
import {trpc} from '../src/utils/trpc'; | ||
// Work in progress. Trying to mock the trpc object | ||
|
||
|
||
jest.mock("../src/utils/trpc", () => { | ||
const mockCreateUser = jest.fn(); | ||
const mockFindAll = jest.fn(); | ||
|
||
const mockUserRouter = { | ||
createUser: mockCreateUser, | ||
findAll: mockFindAll | ||
}; | ||
|
||
const mockAppRouter = { | ||
user: mockUserRouter | ||
}; | ||
return { | ||
appRouter: mockAppRouter | ||
}; | ||
}); | ||
|
||
describe('Navbar Component Test ', () => { | ||
beforeEach(() => { | ||
render(<LandingPage />) | ||
}); | ||
|
||
it ('check that the button is rendered on the page', () => { | ||
const button = screen.getByRole('button'); | ||
console.debug(button) | ||
expect(button).toHaveLength(1); | ||
expect(screen.getByText("A time travel debugger for modern react apps")).toBeInTheDocument(); | ||
}); | ||
}); |
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,19 @@ | ||
import {screen, render, fireEvent} from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import NavBar from '../src/pages/components/NavBar'; | ||
|
||
describe('Navbar Component Test ', () => { | ||
beforeEach(() => { | ||
render(<NavBar />) | ||
}); | ||
|
||
it ('navbar should have two buttons(anchor tags)', () => { | ||
const buttons = screen.getAllByRole('link'); | ||
expect(buttons).toHaveLength(2) | ||
}); | ||
|
||
it ('clicking a post link navigates to the correct URL', () => { | ||
expect(screen.getAllByRole('link')[0]).toHaveAttribute('href', 'http://github.com/open-source-labs/reactime'); | ||
expect(screen.getAllByRole('link')[1]).toHaveAttribute('href', 'https://chrome.google.com/webstore/detail/reactime/cgibknllccemdnfhfpmjhffpjfeidjga?hl=en-US'); | ||
}) | ||
}) |
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,18 @@ | ||
import {screen, render} from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import People, { Profile } from '../src/pages/components/TeamSection'; | ||
|
||
// http://localhost/_next/image?url=https%3A%2F%2Fgithub.com%2Fwiltonlee948.png&w=256&q=75 | ||
|
||
it('test to see if all the contributor images show up', async () => { | ||
render(<People />); | ||
const image = screen.getAllByTestId('image'); | ||
expect(image.length).toBe(72); | ||
}); | ||
|
||
|
||
test('the value from the profile attribute should be in the src', async () => { | ||
render(<Profile key='' profile='react' name='' />); | ||
const src = await screen.getByTestId('image').getAttribute('src'); | ||
expect(src).toContain('react'); | ||
}); |
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
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