Skip to content

Commit 335e1fa

Browse files
authored
Merge pull request #303 from oslabs-beta/dev
Added unit tests and small updates to website
2 parents edb74fd + 8fb3bc1 commit 335e1fa

File tree

8 files changed

+108
-37
lines changed

8 files changed

+108
-37
lines changed

src/backend/linkFiber.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,6 @@ function createTree(
185185
_debugHookTypes,
186186
} = currentFiber;
187187

188-
// if (currentFiber.tag === 10) {
189-
// const queue = [currentFiber];
190-
// while (queue.length > 0) {
191-
// const tempFiber = queue.shift();
192-
// if (tempFiber.tag === 0) console.log(tempFiber);
193-
// if (tempFiber.sibling) {
194-
// queue.push(tempFiber.sibling);
195-
// }
196-
// if (tempFiber.child) {
197-
// queue.push(tempFiber.child);
198-
// }
199-
// }
200-
// }
201-
202188
// check to see if we can get the information we were looking for
203189
// need to figure out what tag is
204190
if (tag === 5) {

www/__tests__/Blogs.test.tsx

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ import React from 'react';
55

66
const posts = [
77
{
8-
title: 'Our Legendary Article here',
9-
href: '#',
10-
category: { name: 'Greatness', href: '#' },
8+
title: 'Traveling through time with Reactime',
9+
href: 'https://medium.com/@reactime/reactime-v17-0-0-now-with-support-for-the-context-api-and-a-modern-ui-f0edf9e54dae',
10+
category: { name: 'React Debugging', href: 'https://medium.com/tag/react-devtools' },
1111
description:
12-
'Reactime v17, we have come a long way from beta. Now introducing full Context API support and CustomHooks support: thereby allowing developers to better visualize the states and ... ',
13-
date: 'Dec 14, 2022',
14-
datetime: '2022-12-14',
12+
'Reactime v17, we have come a long way from beta. Now introducing full Context API support: thereby allowing developers to better visualize the states and ... ',
13+
date: 'Jan 3, 2023',
14+
datetime: '2023-1-03',
1515
imageUrl:
1616
'https://images.unsplash.com/photo-1496128858413-b36217c2ce36?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1679&q=80',
1717
readingTime: '6 min',
1818
author: {
1919
name: 'James Nghiem',
20-
href: '#',
20+
href: 'https://medium.com/@reactime',
2121
imageUrl:
22-
'https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80',
22+
'https://github.com/jemzir.png',
2323
},
2424
},
2525
{
@@ -70,10 +70,19 @@ describe('Blog component test ', () => {
7070
});
7171

7272
it ('displays the correct information for each blog post', () => {
73-
const blogs = screen.getAllByTestId('blog')
74-
blogs.forEach((blog) => {
75-
73+
posts.forEach(post => {
74+
expect(screen.getByText(post.title)).toBeInTheDocument();
75+
expect(screen.getByText(post.description.trim())).toBeInTheDocument();
76+
expect(screen.getByText(post.date)).toBeInTheDocument();
77+
expect(screen.getByText(post.category.name)).toBeInTheDocument();
78+
expect(screen.getAllByText(post.author.name)[0]).toBeInTheDocument();
79+
})
80+
});
7681

82+
it ('clicking a post link navigates to the correct URL', () => {
83+
posts.forEach((post, index) => {
84+
const postLink = post.href
85+
expect(screen.getAllByTestId('link')[index]).toHaveAttribute('href', postLink);
7786
})
7887
});
7988
});

www/__tests__/LandingPage.test.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {screen, render, fireEvent} from '@testing-library/react';
2+
import '@testing-library/jest-dom/extend-expect';
3+
import LandingPage from '../src/pages/components/LandingPage';
4+
import Blogs from '../src/pages/components/Blogs';
5+
import People from '../src/pages/components/TeamSection';
6+
import FeaturesSection from '../src/pages/components/FeaturesSection';
7+
import {trpc} from '../src/utils/trpc';
8+
// Work in progress. Trying to mock the trpc object
9+
10+
11+
jest.mock("../src/utils/trpc", () => {
12+
const mockCreateUser = jest.fn();
13+
const mockFindAll = jest.fn();
14+
15+
const mockUserRouter = {
16+
createUser: mockCreateUser,
17+
findAll: mockFindAll
18+
};
19+
20+
const mockAppRouter = {
21+
user: mockUserRouter
22+
};
23+
return {
24+
appRouter: mockAppRouter
25+
};
26+
});
27+
28+
describe('Navbar Component Test ', () => {
29+
beforeEach(() => {
30+
render(<LandingPage />)
31+
});
32+
33+
it ('check that the button is rendered on the page', () => {
34+
const button = screen.getByRole('button');
35+
console.debug(button)
36+
expect(button).toHaveLength(1);
37+
expect(screen.getByText("A time travel debugger for modern react apps")).toBeInTheDocument();
38+
});
39+
});

www/__tests__/NavBar.test.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {screen, render, fireEvent} from '@testing-library/react';
2+
import '@testing-library/jest-dom/extend-expect';
3+
import NavBar from '../src/pages/components/NavBar';
4+
5+
describe('Navbar Component Test ', () => {
6+
beforeEach(() => {
7+
render(<NavBar />)
8+
});
9+
10+
it ('navbar should have two buttons(anchor tags)', () => {
11+
const buttons = screen.getAllByRole('link');
12+
expect(buttons).toHaveLength(2)
13+
});
14+
15+
it ('clicking a post link navigates to the correct URL', () => {
16+
expect(screen.getAllByRole('link')[0]).toHaveAttribute('href', 'http://github.com/open-source-labs/reactime');
17+
expect(screen.getAllByRole('link')[1]).toHaveAttribute('href', 'https://chrome.google.com/webstore/detail/reactime/cgibknllccemdnfhfpmjhffpjfeidjga?hl=en-US');
18+
})
19+
})

www/__tests__/TeamSection.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {screen, render} from '@testing-library/react';
2+
import '@testing-library/jest-dom/extend-expect';
3+
import People, { Profile } from '../src/pages/components/TeamSection';
4+
5+
// http://localhost/_next/image?url=https%3A%2F%2Fgithub.com%2Fwiltonlee948.png&w=256&q=75
6+
7+
it('test to see if all the contributor images show up', async () => {
8+
render(<People />);
9+
const image = screen.getAllByTestId('image');
10+
expect(image.length).toBe(72);
11+
});
12+
13+
14+
test('the value from the profile attribute should be in the src', async () => {
15+
render(<Profile key='' profile='react' name='' />);
16+
const src = await screen.getByTestId('image').getAttribute('src');
17+
expect(src).toContain('react');
18+
});

www/src/pages/components/Blogs.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
const posts = [
22
{
3-
title: 'Our Legendary Article here',
4-
href: '#',
5-
category: { name: 'Greatness', href: '#' },
3+
title: 'Traveling through time with Reactime',
4+
href: 'https://medium.com/@reactime/reactime-v17-0-0-now-with-support-for-the-context-api-and-a-modern-ui-f0edf9e54dae',
5+
category: { name: 'React Debugging', href: 'https://medium.com/tag/react-devtools' },
66
description:
7-
'Reactime v17, we have come a long way from beta. Now introducing full Context API support and CustomHooks support: thereby allowing developers to better visualize the states and ... ',
8-
date: 'Dec 14, 2022',
9-
datetime: '2022-12-14',
7+
'Reactime v17, we have come a long way from beta. Now introducing full Context API support: thereby allowing developers to better visualize the states and ... ',
8+
date: 'Jan 3, 2023',
9+
datetime: '2023-1-03',
1010
imageUrl:
1111
'https://images.unsplash.com/photo-1496128858413-b36217c2ce36?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1679&q=80',
1212
readingTime: '6 min',
1313
author: {
1414
name: 'James Nghiem',
15-
href: '#',
15+
href: 'https://medium.com/@reactime',
1616
imageUrl:
17-
'https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80',
17+
'https://github.com/jemzir.png',
1818
},
1919
},
2020
{
@@ -80,7 +80,7 @@ export default function Blogs() {
8080
{post.category.name}
8181
</a>
8282
</p>
83-
<a href={post.href} className="mt-2 block">
83+
<a href={post.href} data-testid='link' className="mt-2 block">
8484
<p className="text-xl font-semibold text-gray-900">{post.title}</p>
8585
<p className="mt-3 text-base text-gray-500">{post.description}</p>
8686
</a>

www/src/pages/components/LandingPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default function LandingPage() {
3838
</div>
3939
<div className="mt-20">
4040
<div>
41-
<a href="#" className="inline-flex space-x-4">
41+
<a target="_blank" href="https://medium.com/@reactime/reactime-v17-0-0-now-with-support-for-the-context-api-and-a-modern-ui-f0edf9e54dae" className="inline-flex space-x-4">
4242
<span className="rounded bg-rose-50 px-2.5 py-1 text-sm font-semibold text-rose-500">
4343
What's new
4444
</span>

www/src/pages/components/TeamSection.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ const people: string[][] = [
7777
]
7878

7979
function replace(e: React.SyntheticEvent<HTMLImageElement>): void{
80-
console.log('test');
8180
e.currentTarget.onerror = null;
8281
e.currentTarget.src = "/profileFallback.png"
8382
}
@@ -112,7 +111,7 @@ function replace(e: React.SyntheticEvent<HTMLImageElement>): void{
112111
profile: string | undefined,
113112
name: string | undefined,
114113
}
115-
function Profile({profile, name}: profileType) {
114+
export function Profile({profile, name}: profileType) {
116115
const [imageError, setImageError] = useState(false);
117116
return (
118117
<div className="space-y-4">
@@ -123,6 +122,7 @@ function replace(e: React.SyntheticEvent<HTMLImageElement>): void{
123122
className="mx-auto h-20 w-20 rounded-full lg:h-24 lg:w-24"
124123
onError={(e) => setImageError(true)}
125124
alt="missing-profile-image"
125+
data-testid="image"
126126
/>
127127
<div className="space-y-2">
128128
<div className="text-xs font-medium lg:text-sm">

0 commit comments

Comments
 (0)