Skip to content

Commit

Permalink
test: added e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
goratt12 authored and benfurber committed Jan 17, 2025
1 parent 5f2cfa3 commit 56e7e92
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
41 changes: 41 additions & 0 deletions packages/cypress/src/integration/research/list.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
describe('[Research - List Articles]', () => {
const researchPageUrl = '/research'

beforeEach(() => {
cy.visit(researchPageUrl)
})

it('[By Everyone - Lists all research articles]', () => {
cy.step('Verify page loads with research articles')
cy.get('[data-cy=ResearchList]').should('be.visible')
cy.get('[data-cy=ResearchListItem]').should('have.length.greaterThan', 0)
})

it('[Search Functionality - Filters articles]', () => {
const searchTerm = 'test'

cy.step('Type a keyword into the search bar')
cy.get('[data-cy=research-search-box]').clear().type(searchTerm)

cy.step('Verify filtered results are displayed')
cy.get('[data-cy=ResearchListItem]').should('have.length.at.least', 1)
})

it('[Pagination - Displays additional articles]', () => {
cy.step('Verify pagination is visible')
let itemCount
cy.get('[data-cy=ResearchListItem]').then((items) => {
itemCount = items.length
})
cy.get('[data-cy=loadMoreButton]').should('be.visible')
cy.get('[data-cy=loadMoreButton]').click()

cy.step('Verify additional articles are loaded')
cy.then(() => {
cy.get('[data-cy=ResearchListItem]').should(
'have.length.greaterThan',
itemCount,
)
})
})
})
11 changes: 9 additions & 2 deletions src/pages/Research/Content/ResearchList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,21 @@ const ResearchList = observer(() => {
/>

{showDrafts ? (
<ul style={{ listStyle: 'none', padding: 0, margin: 0 }}>
<ul
style={{ listStyle: 'none', padding: 0, margin: 0 }}
data-cy="ResearchList"
>
{drafts.map((item) => {
return <ResearchListItem key={item._id} item={item} />
})}
</ul>
) : (
<>
{researchItems && researchItems.length !== 0 && (
<ul style={{ listStyle: 'none', padding: 0, margin: 0 }}>
<ul
style={{ listStyle: 'none', padding: 0, margin: 0 }}
data-cy="ResearchList"
>
{researchItems.map((item) => (
<ResearchListItem key={item._id} item={item} />
))}
Expand All @@ -121,6 +127,7 @@ const ResearchList = observer(() => {
>
<Button
type="button"
data-cy="loadMoreButton"
onClick={() => fetchResearchItems(lastId)}
>
{listing.loadMore}
Expand Down

0 comments on commit 56e7e92

Please sign in to comment.