diff --git a/web/src/Routes.js b/web/src/Routes.js index d72ab0c..87dd3b7 100644 --- a/web/src/Routes.js +++ b/web/src/Routes.js @@ -21,8 +21,10 @@ const Routes = () => { + + diff --git a/web/src/components/Article/Article.js b/web/src/components/Article/Article.js new file mode 100644 index 0000000..204e68a --- /dev/null +++ b/web/src/components/Article/Article.js @@ -0,0 +1,17 @@ +import { Link, routes } from '@redwoodjs/router'; + +const Article = ({article}) => { + return ( +
+
+

+ {article.title} +

+
+
{article.body}
+
Posted at: {article.createdAt}
+
+ ) +} + +export default Article diff --git a/web/src/components/Article/Article.stories.js b/web/src/components/Article/Article.stories.js new file mode 100644 index 0000000..a8ee6f8 --- /dev/null +++ b/web/src/components/Article/Article.stories.js @@ -0,0 +1,7 @@ +import Article from './Article' + +export const generated = () => { + return
+} + +export default { title: 'Components/Article' } diff --git a/web/src/components/Article/Article.test.js b/web/src/components/Article/Article.test.js new file mode 100644 index 0000000..3dc4e57 --- /dev/null +++ b/web/src/components/Article/Article.test.js @@ -0,0 +1,14 @@ +import { render } from '@redwoodjs/testing/web' + +import Article from './Article' + +// Improve this test with help from the Redwood Testing Doc: +// https://redwoodjs.com/docs/testing#testing-components + +describe('Article', () => { + it('renders successfully', () => { + expect(() => { + render(
) + }).not.toThrow() + }) +}) diff --git a/web/src/components/ArticleCell/ArticleCell.js b/web/src/components/ArticleCell/ArticleCell.js new file mode 100644 index 0000000..ade644f --- /dev/null +++ b/web/src/components/ArticleCell/ArticleCell.js @@ -0,0 +1,24 @@ +import Article from 'src/components/Article'; + +export const QUERY = gql` + query FindArticleQuery($id: Int!) { + article: post(id: $id) { + id + title + body + createdAt + } + } +` + +export const Loading = () =>
Loading...
+ +export const Empty = () =>
Empty
+ +export const Failure = ({ error }) => ( +
Error: {error.message}
+) + +export const Success = ({ article }) => { + return
+} diff --git a/web/src/components/ArticleCell/ArticleCell.mock.js b/web/src/components/ArticleCell/ArticleCell.mock.js new file mode 100644 index 0000000..3c12aa1 --- /dev/null +++ b/web/src/components/ArticleCell/ArticleCell.mock.js @@ -0,0 +1,6 @@ +// Define your own mock data here: +export const standard = () => ({ + article: { + id: 42, + }, +}) diff --git a/web/src/components/ArticleCell/ArticleCell.stories.js b/web/src/components/ArticleCell/ArticleCell.stories.js new file mode 100644 index 0000000..abc6e27 --- /dev/null +++ b/web/src/components/ArticleCell/ArticleCell.stories.js @@ -0,0 +1,20 @@ +import { Loading, Empty, Failure, Success } from './ArticleCell' +import { standard } from './ArticleCell.mock' + +export const loading = () => { + return Loading ? : null +} + +export const empty = () => { + return Empty ? : null +} + +export const failure = () => { + return Failure ? : null +} + +export const success = () => { + return Success ? : null +} + +export default { title: 'Cells/ArticleCell' } diff --git a/web/src/components/ArticleCell/ArticleCell.test.js b/web/src/components/ArticleCell/ArticleCell.test.js new file mode 100644 index 0000000..56a6cb2 --- /dev/null +++ b/web/src/components/ArticleCell/ArticleCell.test.js @@ -0,0 +1,41 @@ +import { render } from '@redwoodjs/testing/web' +import { Loading, Empty, Failure, Success } from './ArticleCell' +import { standard } from './ArticleCell.mock' + +// Generated boilerplate tests do not account for all circumstances +// and can fail without adjustments, e.g. Float and DateTime types. +// Please refer to the RedwoodJS Testing Docs: +// https://redwoodjs.com/docs/testing#testing-cells +// https://redwoodjs.com/docs/testing#jest-expect-type-considerations + +describe('ArticleCell', () => { + it('renders Loading successfully', () => { + expect(() => { + render() + }).not.toThrow() + }) + + it('renders Empty successfully', async () => { + expect(() => { + render() + }).not.toThrow() + }) + + it('renders Failure successfully', async () => { + expect(() => { + render() + }).not.toThrow() + }) + + // When you're ready to test the actual output of your component render + // you could test that, for example, certain text is present: + // + // 1. import { screen } from '@redwoodjs/testing/web' + // 2. Add test: expect(screen.getByText('Hello, world')).toBeInTheDocument() + + it('renders Success successfully', async () => { + expect(() => { + render() + }).not.toThrow() + }) +}) diff --git a/web/src/components/ArticlesCell/ArticlesCell.js b/web/src/components/ArticlesCell/ArticlesCell.js index 1437f5d..8fcb260 100644 --- a/web/src/components/ArticlesCell/ArticlesCell.js +++ b/web/src/components/ArticlesCell/ArticlesCell.js @@ -1,3 +1,5 @@ +import Article from 'src/components/Article'; + export const QUERY = gql` query ArticlesQuery { articles: posts { @@ -19,16 +21,10 @@ export const Failure = ({ error }) => ( export const Success = ({ articles }) => { return ( -
    + <> {articles.map((article) => ( -
    -
    -

    {article.title}

    -
    -

    {article.body}

    -
    Created at: {article.createdAt}
    -
    +
    ))} -
+ ) } diff --git a/web/src/components/Post/PostForm/PostForm.js b/web/src/components/Post/PostForm/PostForm.js index 250a307..f50ce4a 100644 --- a/web/src/components/Post/PostForm/PostForm.js +++ b/web/src/components/Post/PostForm/PostForm.js @@ -5,6 +5,7 @@ import { Label, TextField, Submit, + TextAreaField } from '@redwoodjs/forms' const PostForm = (props) => { @@ -48,7 +49,7 @@ const PostForm = (props) => { Body - {
  • About
  • +
  • + Contact Us +
  • diff --git a/web/src/layouts/PostsLayout/PostsLayout.js b/web/src/layouts/PostsLayout/PostsLayout.js index bad7cb7..3b1763d 100644 --- a/web/src/layouts/PostsLayout/PostsLayout.js +++ b/web/src/layouts/PostsLayout/PostsLayout.js @@ -15,7 +15,7 @@ const PostsLayout = ({ children }) => {
    +
    New Post -
    {children}
    +
    {children}
    ) } diff --git a/web/src/pages/ArticlePage/ArticlePage.js b/web/src/pages/ArticlePage/ArticlePage.js new file mode 100644 index 0000000..1a520bd --- /dev/null +++ b/web/src/pages/ArticlePage/ArticlePage.js @@ -0,0 +1,13 @@ +import { MetaTags } from '@redwoodjs/web' +import ArticleCell from 'src/components/ArticleCell'; + +const ArticlePage = ({id}) => { + return ( + <> + + + + ) +} + +export default ArticlePage diff --git a/web/src/pages/ArticlePage/ArticlePage.stories.js b/web/src/pages/ArticlePage/ArticlePage.stories.js new file mode 100644 index 0000000..008d3e0 --- /dev/null +++ b/web/src/pages/ArticlePage/ArticlePage.stories.js @@ -0,0 +1,7 @@ +import ArticlePage from './ArticlePage' + +export const generated = () => { + return +} + +export default { title: 'Pages/ArticlePage' } diff --git a/web/src/pages/ArticlePage/ArticlePage.test.js b/web/src/pages/ArticlePage/ArticlePage.test.js new file mode 100644 index 0000000..583138d --- /dev/null +++ b/web/src/pages/ArticlePage/ArticlePage.test.js @@ -0,0 +1,14 @@ +import { render } from '@redwoodjs/testing/web' + +import ArticlePage from './ArticlePage' + +// Improve this test with help from the Redwood Testing Doc: +// https://redwoodjs.com/docs/testing#testing-pages-layouts + +describe('ArticlePage', () => { + it('renders successfully', () => { + expect(() => { + render() + }).not.toThrow() + }) +}) diff --git a/web/src/pages/ContactPage/ContactPage.js b/web/src/pages/ContactPage/ContactPage.js new file mode 100644 index 0000000..0d784f9 --- /dev/null +++ b/web/src/pages/ContactPage/ContactPage.js @@ -0,0 +1,24 @@ +import { MetaTags } from '@redwoodjs/web' +import { Form, TextField, Submit, TextAreaField } from '@redwoodjs/forms' + +const ContactPage = () => { + const onSubmit = (data) => { + console.log(data) + } + return ( + <> + +
    + + + + + + + Save + + + ) +} + +export default ContactPage diff --git a/web/src/pages/ContactPage/ContactPage.stories.js b/web/src/pages/ContactPage/ContactPage.stories.js new file mode 100644 index 0000000..0894c0b --- /dev/null +++ b/web/src/pages/ContactPage/ContactPage.stories.js @@ -0,0 +1,7 @@ +import ContactPage from './ContactPage' + +export const generated = () => { + return +} + +export default { title: 'Pages/ContactPage' } diff --git a/web/src/pages/ContactPage/ContactPage.test.js b/web/src/pages/ContactPage/ContactPage.test.js new file mode 100644 index 0000000..1bd9289 --- /dev/null +++ b/web/src/pages/ContactPage/ContactPage.test.js @@ -0,0 +1,14 @@ +import { render } from '@redwoodjs/testing/web' + +import ContactPage from './ContactPage' + +// Improve this test with help from the Redwood Testing Doc: +// https://redwoodjs.com/docs/testing#testing-pages-layouts + +describe('ContactPage', () => { + it('renders successfully', () => { + expect(() => { + render() + }).not.toThrow() + }) +})