Skip to content

Commit

Permalink
Fix missing post (#1131)
Browse files Browse the repository at this point in the history
* Fix missing post

* Update node version in GH Actions
  • Loading branch information
alessbell authored Oct 15, 2020
1 parent a97304a commit 3380a01
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '13.14'
node-version: '12.19'
- run: npm ci
- run: npm run type-check
- run: npm run lint
Expand Down
14 changes: 11 additions & 3 deletions __tests__/pages/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const posts = [
frontmatter: {
title: 'Third post',
date: 'January 3, 1980',
spoiler: '3...',
keywords: ['keyword three'],
},
fields: {
Expand Down Expand Up @@ -78,7 +77,8 @@ describe('Homepage', () => {
screen.getByText('A blog by Alessia Bellisario')
).toBeInTheDocument();

// displays 3 posts
// displays 3 posts, and expects all to be there...
// ...even the node without a spoiler
expect(screen.getAllByText(/post/i)).toHaveLength(3);
posts.forEach(({ node: { frontmatter, fields } }) => {
expect(
Expand All @@ -87,9 +87,17 @@ describe('Homepage', () => {
expect(
screen.getByText(frontmatter.title || fields.slug)
).toHaveAttribute('href', fields.slug);
expect(screen.getByText(frontmatter.spoiler)).toBeInTheDocument();
});

// expects the spoilers that do exist (they are optional)
// to be in the document
expect(
screen.getByText(posts[0].node.frontmatter.spoiler || '')
).toBeInTheDocument();
expect(
screen.getByText(posts[1].node.frontmatter.spoiler || '')
).toBeInTheDocument();

// can open and close details
userEvent.click(screen.getByText(/filter by tag/i));
expect(
Expand Down
5 changes: 1 addition & 4 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ const BlogIndex = ({
})
.map(({ node: { id, fields, frontmatter } }) => (
<div key={id} style={{ margin: '1.5rem 0' }}>
{fields?.slug &&
frontmatter?.title &&
frontmatter?.spoiler &&
frontmatter?.date ? (
{fields?.slug && frontmatter?.title ? (
<>
<h3>
<BlogLink to={fields.slug}>{frontmatter.title}</BlogLink>
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true
},
"include": ["src/**/*"]
"include": ["src/**/*", "__tests__/**/*"]
}

1 comment on commit 3380a01

@vercel
Copy link

@vercel vercel bot commented on 3380a01 Oct 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.