Skip to content

Commit

Permalink
feat: adding unit tests for support-us,Testimonial and JobSummary com…
Browse files Browse the repository at this point in the history
…ponent (#1813)

Co-authored-by: akshatnema <20bcs022@iiitdmj.ac.in>
  • Loading branch information
reachaadrika and akshatnema authored Jul 11, 2023
1 parent bd1c6bf commit 53e7517
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 109 deletions.
4 changes: 2 additions & 2 deletions components/JobSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export default function JobSummary({ job, className = '' }) {
<div className="px-4 py-5 sm:px-6">
<dl>
<dt className="sr-only">Location</dt>
<dd className="flex mt-1 text-sm text-gray-900">
<dd className="flex mt-1 text-sm text-gray-900" data-testid="JobSummary-dd">
<svg viewBox="0 0 20 20" fill="currentColor" className="h-5 w-5 text-gray-400"><path fillRule="evenodd" d="M5.05 4.05a7 7 0 119.9 9.9L10 18.9l-4.95-4.95a7 7 0 010-9.9zM10 11a2 2 0 100-4 2 2 0 000 4z" clipRule="evenodd"></path></svg>
<div className="ml-4">
{!job.location || job.location === 'remote' && <p>Remote</p>}
<p className="text-gray-700">{!job.region || job.region === 'any' ? 'Anywhere (on planet Earth)' : job.region}</p>
<p className="text-gray-700" data-testid="JobSummary-paragraph">{!job.region || job.region === 'any' ? 'Anywhere (on planet Earth)' : job.region}</p>
</div>
</dd>
</dl>
Expand Down
99 changes: 0 additions & 99 deletions components/SupportUs.js

This file was deleted.

51 changes: 51 additions & 0 deletions components/SupportUs/SupportItemsList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
export const items = [
{
href: "https://slack.com/media-kit",
imgSrc: "/img/supportus/slack.webp",
imgTitle: "Slack - Free Standard Subscription.",
imgClass: "inline-block px-4 sm:h-10",
section: 1,
},
{
href: "https://toast.ninja/",
imgSrc: "/img/supportus/toast.webp",
imgTitle: "Toast - Free services.",
imgClass: "inline-block px-4 sm:h-10",
section: 1,
},
{
href: "https://www.netlify.com/",
imgSrc: "/img/supportus/netlify.webp",
imgTitle: "Netlify - Free website deployment.",
imgClass: "inline-block px-4 sm:h-10",
section: 1,
},
{
href: "https://sonarcloud.io/",
imgSrc: "/img/supportus/sonarcloud.webp",
imgTitle: "Sonarcloud - Free tier for automated project scanning.",
imgClass: "inline-block px-4 md:h-14",
section: 2,
},
{
href: "https://www.digitalocean.com/press/",
imgSrc: "/img/supportus/digitalocean.webp",
imgTitle: "DigitalOcean - 500 dollars on cloud services.",
imgClass: "inline-block px-2 sm:h-8",
section: 2,
},
{
href: "https://restream.io/",
imgSrc: "/img/supportus/restream.webp",
imgTitle: "Restream - Free professional plan subscription.",
imgClass: "inline-block px-4 sm:h-6",
section: 2,
},
{
href: "https://sessionize.com/",
imgSrc: "/img/supportus/sessionize.webp",
imgTitle: "Sessionize-Free community license for AACoT Madrid.",
imgClass: "inline-block px-4 sm:h-9",
section: 3,
},
];
65 changes: 65 additions & 0 deletions components/SupportUs/SupportUs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { items } from "./SupportItemsList";
export default function SupportUs({ className = '', showSupportBanner = true }) {
return (
<div className={ `text-center ${ className }` } data-testid="SupportUs-main">
<div className="flex flex-wrap md:mb-4 sm:py-2 items-center justify-center md:px-4" data-testid="SupportUs-section">
{ items
.filter((item) => item.section === 1)
.map((item, index) => (
<a
key={ index }
href={ item.href }
target="_blank"
rel="noopener noreferrer"
className='block relative text-center w-2/3 px-4 py-4 sm:p-0 sm:w-1/3 md:w-1/3 lg:w-1/5'
>
<img
className={ item.imgClass }
src={ item.imgSrc }
title={ item.imgTitle }
/>
</a>
)) }
</div>
<div className="flex flex-wrap mb-4 items-center justify-center md:px-2" data-testid="SupportUs-subsection">
{ items
.filter((item) => item.section === 2)
.map((item, index) => (
<a
key={ index }
href={ item.href }
target="_blank"
rel="noopener noreferrer"
className='block relative text-center w-2/3 px-4 py-4 sm:p-0 sm:w-1/3 md:w-1/3 lg:w-1/5'
>
<img
className={ item.imgClass }
src={ item.imgSrc }
title={ item.imgTitle }
/>
</a>
)) }
</div>
<div className="flex flex-wrap mb-4 items-center justify-center md:px-2" data-testid="SupportUs-last-div">
{ items
.filter((item) => item.section === 3)
.map((item, index) => (
<a
key={ index }
href={ item.href }
target="_blank"
rel="noopener noreferrer"
className='block relative text-center w-2/3 px-4 py-4 sm:p-0 sm:w-1/3 md:w-1/3 lg:w-1/5'
>
<img
className={ item.imgClass }
src={ item.imgSrc }
title={ item.imgTitle }
/>
</a>
)) }
</div>
</div>
);
}

2 changes: 1 addition & 1 deletion components/Testimonial.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function Testimonial({
<footer className="mt-6">
<div className="flex">
<figure className="flex-shrink-0 inline-flex rounded-full border-2 border-white">
<img className="h-12 w-12 rounded-full" src={authorAvatar} alt={authorName}/>
<img className="h-12 w-12 rounded-full" src={authorAvatar} alt={authorName} data-testid="Testimonial-img"/>
</figure>
<div className="ml-4 text-left">
<p className="text-base leading-6 font-bold text-gray-900">{authorName}</p>
Expand Down
18 changes: 18 additions & 0 deletions cypress/test/JobSummary.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { mount } from 'cypress/react';
import JobSummary from '../../components/JobSummary';
describe('JobSummary', () => {
it('renders job summary with correct information', () => {
const job = {
location: 'remote',
region: 'Anywhere (on planet Earth)',
employmentType: 'Full-time',
closingOn: 'Closing on June 30, 2023',
};

mount(<JobSummary job={job} className="custom-class" />);
cy.get('[data-testid="JobSummary-dd"]').contains('Remote').should('exist');
cy.get('[data-testid="JobSummary-paragraph"]').contains('Anywhere (on planet Earth)').should('exist');
cy.contains(job.employmentType).should('exist');
cy.contains(job.closingOn).should('exist');
});
});
53 changes: 53 additions & 0 deletions cypress/test/SupportUs.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import SupportUs from '../../components/SupportUs/SupportUs';
describe('SupportUs component', () => {
beforeEach(() => {
cy.mount(<SupportUs />);
});

it('renders the SupportUs component', () => {
cy.get('[data-testid="SupportUs-main"]')
.should('be.visible')
.within(() => {
cy.get('[data-testid="SupportUs-section"]').should('exist'); // First section div
cy.get('[data-testid="SupportUs-subsection"]').should('exist'); // Second section div
cy.get('[data-testid="SupportUs-last-div"]').should('exist'); // Third section div
});
});

it('renders correct number of items in each section', () => {
cy.get('[data-testid="SupportUs-section"]').find('a').should('have.length', 3); // First section
cy.get('[data-testid="SupportUs-subsection"]').find('a').should('have.length', 3); // Second section
cy.get('[data-testid="SupportUs-last-div"]').find('a').should('have.length', 1); // Third section
});

it('opens links in new tab', () => {
cy.get('[data-testid="SupportUs-main"]').each((section) => {
cy.wrap(section)
.find('a')
.each((link) => {
cy.wrap(link).should('have.attr', 'target', '_blank');
});
});
});

it('has valid href attribute in each link', () => {
cy.get('[data-testid="SupportUs-main"]').each((section) => {
cy.wrap(section)
.find('a')
.each((link) => {
cy.wrap(link).should('have.attr', 'href').and('not.be.empty');
});
});
});

it('displays the correct image in each item', () => {
cy.get('[data-testid="SupportUs-main"]').each((section) => {
cy.wrap(section)
.find('a')
.each((link) => {
cy.wrap(link).find('img').should('have.attr', 'src').and('not.be.empty');
});
});
});

});
27 changes: 27 additions & 0 deletions cypress/test/Testimonial.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { mount } from 'cypress/react';
import Testimonial from '../../components/Testimonial';

describe('Testimonial Component', () => {
it('should render the testimonial with correct data', () => {
const testimonialData = {
text: 'This is a test testimonial.',
authorName: 'Lukasz Gornicki',
authorDescription: 'CEO at Company',
authorAvatar: '/img/avatars/lpgornicki.webp',
};
mount(
<Testimonial
text={ testimonialData.text }
authorName={ testimonialData.authorName }
authorDescription={ testimonialData.authorDescription }
authorAvatar={ testimonialData.authorAvatar }
/>
);

cy.contains(testimonialData.text);
cy.contains(testimonialData.authorName);
cy.contains(testimonialData.authorDescription);
cy.get('[data-testid="Testimonial-img"]').should('have.attr', 'src', testimonialData.authorAvatar);
cy.get('[data-testid="Testimonial-img"]').should('have.attr', 'alt', testimonialData.authorName);
});
});
14 changes: 7 additions & 7 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Paragraph from '../components/typography/Paragraph'
import TextLink from '../components/typography/TextLink'
import GoldSponsors from '../components/sponsors/GoldSponsors'
import SilverSponsors from '../components/sponsors/SilverSponsors'
import SupportUs from '../components/SupportUs'
import SupportUs from '../components/SupportUs/SupportUs'
import StickyNavbar from '../components/navigation/StickyNavbar'
import GoogleCalendarButton from '../components/buttons/GoogleCalendarButton';
import ICSFileButton from '../components/buttons/ICSFileButton';
Expand Down Expand Up @@ -147,7 +147,7 @@ function HomePage() {
</div>
</Container>
<Container wide>
<NewsroomSection />
<NewsroomSection />
</Container>
</div>

Expand All @@ -163,7 +163,7 @@ function HomePage() {
>
Platinum Sponsors
</Heading>
<Sponsors className="mt-4" showSupportBanner={false} />
<Sponsors className="mt-4" showSupportBanner={ false } />
</Container>

<Container className="text-center pb-6" wide as="section">
Expand All @@ -174,9 +174,9 @@ function HomePage() {
>
Gold Sponsors
</Heading>
<GoldSponsors className="mt-4" showSupportBanner={false} />
<GoldSponsors className="mt-4" showSupportBanner={ false } />
</Container>

<Container className="text-center pyb-6" wide as="section">
<Heading
level="h3"
Expand All @@ -185,7 +185,7 @@ function HomePage() {
>
Silver Sponsors
</Heading>
<SilverSponsors className="mt-4" showSupportBanner={false} />
<SilverSponsors className="mt-4" showSupportBanner={ false } />
</Container>


Expand Down Expand Up @@ -215,7 +215,7 @@ function HomePage() {
Email us
</TextLink> for more info.
</Paragraph>
<SupportUs className="mt-4" showSupportBanner={false} />
<SupportUs className="mt-4" showSupportBanner={ false } />
</Container>
<Container className="text-center pb-20 mt-8" wide as="section">
<Heading level="h3" typeStyle="heading-lg" className="mb-4">
Expand Down

0 comments on commit 53e7517

Please sign in to comment.