diff --git a/web/src/components/Article/Article.test.js b/web/src/components/Article/Article.test.js index c1295cd..9f2f339 100644 --- a/web/src/components/Article/Article.test.js +++ b/web/src/components/Article/Article.test.js @@ -2,17 +2,29 @@ import { render, screen } from '@redwoodjs/testing' import Article from './Article' +const ARTICLE = { + id: 1, + title: 'First post', + body: `Neutra tacos hot chicken prism raw denim, put a bird on it enamel pin post-ironic vape cred DIY. Street art next level umami squid. Hammock hexagon glossier 8-bit banjo. Neutra la croix mixtape echo park four loko semiotics kitsch forage chambray. Semiotics salvia selfies jianbing hella shaman. Letterpress helvetica vaporware cronut, shaman butcher YOLO poke fixie hoodie gentrify woke heirloom.`, + createdAt: new Date().toISOString(), +} + describe('Article', () => { it('renders a blog post', () => { - const article = { - id: 1, - title: 'First post', - body: `Neutra tacos hot chicken prism raw denim, put a bird on it enamel pin post-ironic vape cred DIY. Street art next level umami squid. Hammock hexagon glossier 8-bit banjo. Neutra la croix mixtape echo park four loko semiotics kitsch forage chambray. Semiotics salvia selfies jianbing hella shaman. Letterpress helvetica vaporware cronut, shaman butcher YOLO poke fixie hoodie gentrify woke heirloom.`, - createdAt: new Date().toISOString(), - } - render(
) + render(
) - expect(screen.getByText(article.title)).toBeInTheDocument() - expect(screen.getByText(article.body)).toBeInTheDocument() + expect(screen.getByText(ARTICLE.title)).toBeInTheDocument() + expect(screen.getByText(ARTICLE.body)).toBeInTheDocument() + }) + + it('renders a summary of a blog post', () => { + render(
) + + expect(screen.getByText(ARTICLE.title)).toBeInTheDocument() + expect( + screen.getByText( + 'Neutra tacos hot chicken prism raw denim, put a bird on it enamel pin post-ironic vape cred DIY. Str...' + ) + ).toBeInTheDocument() }) }) diff --git a/web/src/components/Comment/Comment.js b/web/src/components/Comment/Comment.js new file mode 100644 index 0000000..3552dea --- /dev/null +++ b/web/src/components/Comment/Comment.js @@ -0,0 +1,21 @@ +const formattedDate = (datetime) => { + const parsedDate = new Date(datetime) + const month = parsedDate.toLocaleString('default', { month: 'long' }) + return `${parsedDate.getDate()} ${month} ${parsedDate.getFullYear()}` +} + +const Comment = ({ comment }) => { + return ( +
+
+

{comment.name}

+ +
+

{comment.body}

+
+ ) +} + +export default Comment diff --git a/web/src/components/Comment/Comment.stories.js b/web/src/components/Comment/Comment.stories.js new file mode 100644 index 0000000..5919c8e --- /dev/null +++ b/web/src/components/Comment/Comment.stories.js @@ -0,0 +1,15 @@ +import Comment from './Comment' + +export const generated = () => { + return ( + + ) +} + +export default { title: 'Components/Comment' } diff --git a/web/src/components/Comment/Comment.test.js b/web/src/components/Comment/Comment.test.js new file mode 100644 index 0000000..a1bc6f8 --- /dev/null +++ b/web/src/components/Comment/Comment.test.js @@ -0,0 +1,14 @@ +import { render } from '@redwoodjs/testing/web' + +import Comment from './Comment' + +// Improve this test with help from the Redwood Testing Doc: +// https://redwoodjs.com/docs/testing#testing-components + +describe('Comment', () => { + it('renders successfully', () => { + expect(() => { + render() + }).not.toThrow() + }) +})