Skip to content

Commit

Permalink
fix #1928
Browse files Browse the repository at this point in the history
  • Loading branch information
const314 committed Jul 2, 2021
1 parent 78993a4 commit 9391884
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
12 changes: 7 additions & 5 deletions examples/ts/hacker-news/client/containers/NewestByPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ const NewestByPage = ({
first: (+page - 1) * ITEMS_PER_PAGE,
},
},
null,
[]
[],
[page]
)
const { data: stories, status } = useSelector(selector)
const { data: stories, status } = useSelector(selector) || {
data: [],
status: ResultStatus.Initial,
}

useEffect(() => {
getStories()
}, [getStories])
}, [page])

const isLoading =
status === ResultStatus.Initial || status === ResultStatus.Requested

return !isLoading ? (
<Stories items={stories} page={page} type="newest" />
) : null
Expand Down
9 changes: 6 additions & 3 deletions examples/ts/hacker-news/client/containers/ShowByPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ const ShowByPage = ({
},
},
[],
[]
[page]
)
const { data: stories, status } = useSelector(selector)
const { data: stories, status } = useSelector(selector) || {
data: [],
status: ResultStatus.Initial,
}

useEffect(() => {
getStories()
}, [getStories])
}, [page])

const isLoading =
status === ResultStatus.Initial && status === ResultStatus.Requested
Expand Down
28 changes: 28 additions & 0 deletions examples/ts/hacker-news/test/e2e/2.story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,31 @@ test('#1921: upvote/unvote story', async (t) => {
.expect(await Selector('div').withAttribute('title', 'upvote').exists)
.eql(true)
})

test('#1928: stories pagination', async (t) => {
for (let i = 0; i < 25; i++) {
await t.navigateTo(`${ROOT_URL}/submit`)

await t.typeText(Selector('input[type=text]').nth(1), `Story #${i + 1}`, {
paste: true,
})
await t.typeText('textarea', `Story #${i + 1} text`, { paste: true })
await t.click('button')

await waitSelector(
t,
'HackerNews',
Selector('a').withText(`Ask HN: Story #${i + 1}`)
)
}
await t.navigateTo(`${ROOT_URL}/newest`)
await t.expect(Selector('div').withText('Ask HN: Story #24').exists).eql(true)
await t.click(Selector('a').withText('More'))
await t
.expect(Selector('div').withText('Ask HN: Story #24').exists)
.eql(false)
await t.expect(Selector('div').withText('Ask HN: Story #3').exists).eql(true)
await t.click(Selector('a').withText('Prev'))
await t.expect(Selector('div').withText('Ask HN: Story #24').exists).eql(true)
await t.expect(Selector('div').withText('Ask HN: Story #3').exists).eql(false)
})

0 comments on commit 9391884

Please sign in to comment.