generated from ooloo-io/reddit-timer-base
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* header task: first commit * header task: fixed missing default 'javascript' * header task: fixed default link: '/search/javascript' * header after first review * header fixing test * implemented unit test * header: before rebase after app-skeleton-review * resolved conflicts. Fixed unit tests * footer: initial commit * implemented Footer.js and Footer.style.js * footer: completed unit tests * hero-section: initial commit with with fixes from previous PR * hero-section: completed unit tests * hero-section: fixed linting issues in unit tests * hero-section: fixed Apps to have all unit tests pass * hero-section: added missing test descriptions in footer.js * hero-section: refactor components and file structure after review * info-section: initial commit * info-section: implemented About and How it works sections * info-section: fix link to https://ooloo.io/employers * info-section: implemented react-router-hash-link * info-section: fixed ooloo.io link * info-section: implemented unit tests * info-section: fixed linting errors * info-section: fixed linting errors * info-section: fix unit test using this: testing-library/dom-testing-library#477 (comment) * info-section: commit after review * subreddit-form: initial commit. Setup folder structure * subreddit-form: implement tests * subreddit-form: fix lint error in Header.js * subreddit-form: completed unit and e2e tests * subreddit-form: fixes and cleanup after review
- Loading branch information
Showing
22 changed files
with
211 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from 'react'; | ||
import { MemoryRouter, Route } from 'react-router-dom'; | ||
import { render, screen, within } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
import App from '../app'; | ||
import { defaultSubReddit } from '../config'; | ||
|
||
const setup = (initialPath = '/') => { | ||
let history; | ||
|
||
render( | ||
<MemoryRouter initialEntries={[initialPath]}> | ||
<App /> | ||
<Route | ||
path="*" | ||
render={(props) => { | ||
history = props.history; | ||
return null; | ||
}} | ||
/> | ||
</MemoryRouter>, | ||
); | ||
return { history }; | ||
}; | ||
|
||
describe('subreddit form', () => { | ||
it('updates the URL when submitting the form', () => { | ||
const { history } = setup('/search/python'); | ||
const searchInput = screen.getByLabelText('r /'); | ||
|
||
expect(searchInput.value).toBe('python'); | ||
|
||
userEvent.clear(searchInput); | ||
userEvent.type(searchInput, 'Gatsbyjs'); | ||
|
||
expect(searchInput.value).toBe('Gatsbyjs'); | ||
|
||
const submitButton = screen.getByRole('button', { name: /search/i }); | ||
userEvent.click(submitButton); | ||
|
||
expect(history.location.pathname).toEqual('/search/Gatsbyjs'); | ||
}); | ||
|
||
it('input value changes to default subredit when seach link in header is clicked', () => { | ||
setup('/search/reactjs'); | ||
const searchInput = screen.getByRole('textbox'); | ||
const header = screen.getByRole('banner'); | ||
const searchLink = within(header).getByRole('link', { name: /search/i }); | ||
|
||
userEvent.click(searchLink); | ||
|
||
expect(searchInput.value).toBe(defaultSubReddit); | ||
}); | ||
}); |
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,15 @@ | ||
import styled from 'styled-components'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const Button = styled.button` | ||
height:36px; | ||
line-height: 36px; | ||
padding: 0 16px; | ||
border: none; | ||
border-radius: 4px; | ||
font-weight: 500; | ||
font-size: ${(props) => props.theme.font.size.small}; | ||
color: ${(props) => props.theme.color.primary}; | ||
cursor: pointer; | ||
text-transform: uppercase; | ||
`; |
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 @@ | ||
export { Button as default } from './Button.style'; |
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,9 @@ | ||
import styled from 'styled-components'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const Container = styled.div` | ||
width: 100%; | ||
max-width: 778px; | ||
margin: 0 auto; | ||
padding: 0 20px; | ||
`; |
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 @@ | ||
export { Container as default } from './Container.style'; |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
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
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,15 @@ | ||
import React from 'react'; | ||
|
||
import { Container, Headline } from './SearchPage.style'; | ||
import SubredditForm from './SubredditForm'; | ||
|
||
function SearchPage() { | ||
return ( | ||
<Container> | ||
<Headline>Find the best time for a subreddit</Headline> | ||
<SubredditForm /> | ||
</Container> | ||
); | ||
} | ||
|
||
export default SearchPage; |
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,13 @@ | ||
import styled from 'styled-components'; | ||
|
||
import UnstyledContainer from '../common/container'; | ||
|
||
export const Container = styled(UnstyledContainer)` | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
`; | ||
|
||
export const Headline = styled.h1` | ||
margin-top: 18px 0 0; | ||
`; |
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,46 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { useHistory, useParams } from 'react-router-dom'; | ||
|
||
import { | ||
Form, Input, Label, | ||
} from './SubredditForm.style'; | ||
import Button from '../common/button'; | ||
|
||
function SubredditForm() { | ||
const { subreddit: initialSubreddit } = useParams(); | ||
const [subreddit, setSubreddit] = useState(initialSubreddit); | ||
|
||
function handleChange(event) { | ||
setSubreddit(event.target.value); | ||
} | ||
|
||
const history = useHistory(); | ||
|
||
function handleSubmit(evt) { | ||
evt.preventDefault(); | ||
history.push(`/search/${subreddit}`); | ||
} | ||
|
||
// update input value when URL is updated externally | ||
// (e.g. when user clicks on search link in header) | ||
useEffect(() => { | ||
setSubreddit(initialSubreddit); | ||
}, [initialSubreddit]); | ||
|
||
return ( | ||
<Form onSubmit={handleSubmit}> | ||
<Label> | ||
r / | ||
<Input | ||
type="text" | ||
value={subreddit} | ||
name="subreddit" | ||
onChange={handleChange} | ||
/> | ||
</Label> | ||
<Button>Search</Button> | ||
</Form> | ||
); | ||
} | ||
|
||
export default SubredditForm; |
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,21 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const Form = styled.form` | ||
margin: 20px 0 0; | ||
display: flex; | ||
align-items: center; | ||
`; | ||
|
||
export const Label = styled.label` | ||
font-size: 18px; | ||
`; | ||
|
||
export const Input = styled.input` | ||
width: 370px; | ||
height: 36px; | ||
margin: 0 10px; | ||
padding: 0 15px; | ||
font-size: ${(props) => props.theme.font.size.small}; | ||
color: ${(props) => props.theme.color.dark}; | ||
border: 1px solid ${(props) => props.theme.color.midLight}; | ||
`; |
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 @@ | ||
export { default } from './SearchPage'; |
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