-
-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add unit tests for AuthorAvatars , TOC , Hero , Meeting and Dem…
…oAnimation and Figure components (#1831) Co-authored-by: akshatnema <[email protected]>%0ACo-authored-by: Akshat Nema <[email protected]>
- Loading branch information
1 parent
85d35a5
commit 7d5c2fd
Showing
14 changed files
with
347 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
import React from 'react' | ||
export default function AuthorAvatars({ authors = [] }) { | ||
return ( | ||
authors.map((author, index) => { | ||
let avatar = <img | ||
key={index} | ||
title={author.name} | ||
className={`${index > 0 ? `absolute left-${index * 7} top-0` : `relative mr-${(authors.length - 1) * 7}`} z-${(authors.length - 1 - index) * 10} h-10 w-10 border-2 border-white rounded-full object-cover hover:z-50`} | ||
src={author.photo} | ||
loading="lazy" | ||
/> | ||
let avatar = ( | ||
<img | ||
key={index} | ||
title={author.name} | ||
className={`${index > 0 ? `absolute left-${index * 7} top-0` : `relative mr-${(authors.length - 1) * 7}`} z-${(authors.length - 1 - index) * 10} h-10 w-10 border-2 border-white rounded-full object-cover hover:z-50`} | ||
src={author.photo} | ||
loading="lazy" | ||
data-testid="AuthorAvatars-img" | ||
/> | ||
); | ||
|
||
return author.link ? <a alt={author.name} href={author.link}>{avatar}</a> : {avatar} | ||
return author.link ? ( | ||
<a alt={author.name} href={author.link} data-testid="AuthorAvatars-link"> | ||
{avatar} | ||
</a> | ||
) : ( | ||
<React.Fragment key={index}>{avatar}</React.Fragment> | ||
); | ||
}) | ||
) | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React from 'react'; | ||
import { mount } from 'cypress/react' | ||
import AuthorAvatars from '../../components/AuthorAvatars'; | ||
|
||
describe('AuthorAvatars', () => { | ||
const authors = [ | ||
{ | ||
name: 'John Doe', | ||
photo: 'https://example.com/john-doe.jpg', | ||
link: 'https://example.com/john-doe' | ||
}, | ||
{ | ||
name: 'Jane Smith', | ||
photo: 'https://example.com/jane-smith.jpg', | ||
link: 'https://example.com/jane-smith' | ||
} | ||
]; | ||
|
||
|
||
it('renders the author avatars without links', () => { | ||
const authorsWithoutLinks = [ | ||
{ | ||
name: 'John Doe', | ||
photo: 'https://example.com/john-doe.jpg', | ||
link: null | ||
}, | ||
{ | ||
name: 'Jane Smith', | ||
photo: 'https://example.com/jane-smith.jpg', | ||
link: null | ||
}, | ||
]; | ||
mount(<AuthorAvatars authors={authorsWithoutLinks} />); | ||
authorsWithoutLinks.forEach((author, index) => { | ||
cy.get('[data-testid="AuthorAvatars-link"]') | ||
.should('not.exist'); | ||
|
||
cy.get('[data-testid="AuthorAvatars-img"]') | ||
.eq(index) | ||
.should('have.attr', 'src', author.photo) | ||
.should('have.attr', 'title', author.name) | ||
.should('have.class', index > 0 ? `absolute left-${index * 7} top-0` : `relative mr-${(authorsWithoutLinks.length - 1) * 7}`) | ||
.should('have.class', `z-${(authorsWithoutLinks.length - 1 - index) * 10}`) | ||
.should('have.class', 'h-10 w-10 border-2 border-white rounded-full object-cover hover:z-50'); | ||
}); | ||
}); | ||
|
||
|
||
|
||
it('renders the author avatars with links', () => { | ||
mount(<AuthorAvatars authors={authors} />); | ||
authors.forEach((author, index) => { | ||
cy.get(`[data-testid="AuthorAvatars-link"][alt="${author.name}"][href="${author.link}"]`) | ||
.should('have.length', 1) | ||
.within(() => { | ||
cy.get('[data-testid="AuthorAvatars-img"]') | ||
.should('have.attr', 'src', author.photo) | ||
.should('have.attr', 'title', author.name) | ||
.should('have.class', index > 0 ? `absolute left-${index * 7} top-0` : `relative mr-${(authors.length - 1) * 7}`) | ||
.should('have.class', `z-${(authors.length - 1 - index) * 10}`) | ||
.should('have.class', 'h-10 w-10 border-2 border-white rounded-full object-cover hover:z-50'); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import { mount } from 'cypress/react'; | ||
import DemoAnimation from '../../components/DemoAnimation'; | ||
|
||
describe('DemoAnimation', () => { | ||
it('renders without errors', () => { | ||
mount(<DemoAnimation />); | ||
|
||
cy.wait(100000); | ||
cy.contains('Play with it!').should('be.visible'); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { mount } from "cypress/react"; | ||
import Feedback from '../../components/Feedback' | ||
import MockRouter from '../../cypress/utils/router' | ||
describe('Meeting component', () => { | ||
beforeEach(() => { | ||
mount( | ||
<MockRouter><Feedback /></MockRouter> | ||
); | ||
}); | ||
|
||
it('shows success message on correct request', () => { | ||
cy.get('textarea').type('Sample feedback'); | ||
cy.intercept('POST', '/.netlify/functions/github_discussions', (req) => { | ||
req.reply({ | ||
statusCode: 200, | ||
body: { | ||
message: 'Feedback submitted successfully', | ||
}, | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
}); | ||
}).as('submitFeedback'); | ||
cy.get('form').submit(); | ||
cy.wait('@submitFeedback'); | ||
cy.get('[data-testid="Feedback-div"]').should('contain.text', 'Thank you for your feedback!'); | ||
|
||
}); | ||
it('should display error message on failed submission', () => { | ||
cy.get('textarea').type('Sample feedback'); | ||
cy.intercept('POST', '/.netlify/functions/github_discussions', (req) => { | ||
req.reply({ | ||
statusCode: 500, | ||
body: { | ||
message: 'We were unable to process your feedback', | ||
}, | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
}); | ||
}).as('submitFeedback'); | ||
cy.get('form').submit(); | ||
cy.wait('@submitFeedback'); | ||
cy.get('[data-testid="Feedback-error"]').should('contain.text', 'Oops! Something went wrong...'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import { mount } from 'cypress/react'; | ||
import Figure from '../../components/Figure'; | ||
|
||
describe('Figure', () => { | ||
it('renders the figure with the image and caption', () => { | ||
const src = '/img/posts/2020-summary/active-members.webp'; | ||
const caption = 'Figure 1: Slack active members weekly'; | ||
const widthClass = 'w-50'; | ||
const className = 'custom-class'; | ||
const float = 'left'; | ||
const altOnly = 'Alt Text'; | ||
const imageClass = 'custom-image-class'; | ||
|
||
mount( | ||
<Figure | ||
src={src} | ||
caption={caption} | ||
widthClass={widthClass} | ||
className={className} | ||
float={float} | ||
altOnly={altOnly} | ||
imageClass={imageClass} | ||
/> | ||
); | ||
|
||
cy.get('[data-testid="Figure-div"]').should('have.class', className); | ||
cy.get('[data-testid="Figure-div"]').should('have.class', `float-${float}`); | ||
cy.get('[data-testid="Figure-div"]').should('have.class', widthClass); | ||
|
||
cy.get('[data-testid="Figure-img"]').should('have.attr', 'src', src); | ||
cy.get('[data-testid="Figure-img"]').should('have.attr', 'alt', altOnly); | ||
cy.get('[data-testid="Figure-img"]').should('have.class', imageClass); | ||
|
||
cy.contains(caption).should('be.visible'); | ||
cy.contains(caption).should('have.text', caption); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { mount } from 'cypress/react'; | ||
import Hero from '../../components/Hero'; | ||
|
||
describe('Hero Component', () => { | ||
it('displays the correct content', () => { | ||
mount(<Hero />); | ||
|
||
cy.contains('Building the future of'); | ||
cy.contains('Event-Driven Architectures (EDA)'); | ||
cy.contains('Open-Source tools to easily build and maintain your event-driven architecture.'); | ||
cy.contains('Read the docs'); | ||
cy.contains('Quick search...'); | ||
cy.contains('Proud to be part of the Linux Foundation'); | ||
}); | ||
|
||
it('navigates to the documentation page when "Read the docs" button is clicked', () => { | ||
mount(<Hero />); | ||
cy.get('[data-testid="Button-link"]').contains('Read the docs'); | ||
|
||
}); | ||
|
||
it('performs a search when the search button is clicked', () => { | ||
mount(<Hero />); | ||
|
||
cy.get('[data-testid="Search-Button"]').contains('Quick search...').click(); | ||
|
||
// Type a search query and validate the results | ||
const searchQuery = 'example'; | ||
cy.get('input[type="search"]').type(searchQuery); | ||
|
||
}); | ||
}); |
Oops, something went wrong.