Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding unit tests for InlineHelp ,MacWindow , Newsletter , Profile ,Remember and Warning components #1827

Merged
merged 39 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5f866bf
adding tests for additional components
reachaadrika Jun 22, 2023
2a6f2c8
Merge branch 'master' into additional_tests
reachaadrika Jun 23, 2023
abdadac
Merge branch 'master' of https://github.com/reachaadrika/website into…
reachaadrika Jun 23, 2023
df79cec
Merge branch 'master' into additional_tests
reachaadrika Jun 23, 2023
c265ed5
add additional tests
reachaadrika Jun 23, 2023
ea50e66
Merge branch 'master' into additional_testcases
reachaadrika Jun 27, 2023
442f631
Merge branch 'master' into additional_tests
reachaadrika Jun 27, 2023
810f7f8
fixes
reachaadrika Jun 27, 2023
c9ffb30
fixes
reachaadrika Jun 27, 2023
80f25cb
Merge branch 'additional_testcases' of https://github.com/reachaadrik…
reachaadrika Jun 27, 2023
7bcda57
fixes
reachaadrika Jun 27, 2023
b90f9f9
Merge branch 'additional_testcases' of https://github.com/reachaadrik…
reachaadrika Jun 27, 2023
0129fe2
Merge branch 'additional_tests' of https://github.com/reachaadrika/we…
reachaadrika Jun 27, 2023
9caa38c
Revert "Merge branch 'additional_tests' of https://github.com/reachaa…
reachaadrika Jun 27, 2023
ab05b65
Revert "Merge branch 'master' into additional_testcases"
reachaadrika Jun 27, 2023
c5f841f
Revert "Merge branch 'additional_testcases' of https://github.com/rea…
reachaadrika Jun 27, 2023
7f860f7
Revert "Merge branch 'master' into additional_tests"
reachaadrika Jun 27, 2023
7e005d3
Revert "Revert "Merge branch 'master' into additional_testcases""
reachaadrika Jun 27, 2023
547553f
Merge branch 'master' into additional_tests
reachaadrika Jun 30, 2023
2960295
Merge branch 'master' of https://github.com/reachaadrika/website into…
reachaadrika Jun 30, 2023
8ce2b65
Merge branch 'master' into additional_tests
reachaadrika Jul 8, 2023
4449022
Merge branch 'master' into additional_tests
reachaadrika Jul 8, 2023
63ee9ed
Merge branch 'master' into additional_tests
reachaadrika Jul 10, 2023
6614f62
Merge branch 'master' into additional_tests
reachaadrika Jul 11, 2023
71e6ced
Update components/NewsletterSubscribe.js
reachaadrika Jul 11, 2023
5160f03
Merge branch 'master' into additional_tests
reachaadrika Jul 11, 2023
9625c50
Merge branch 'additional_tests' of https://github.com/reachaadrika/we…
reachaadrika Jul 11, 2023
f010f32
finished changes for Inline
reachaadrika Jul 11, 2023
952d623
Merge branch 'master' into additional_tests
reachaadrika Jul 14, 2023
a110b45
Update components/Warning.js
reachaadrika Jul 14, 2023
fcb5935
Update components/Warning.js
reachaadrika Jul 14, 2023
34df299
Update components/Warning.js
reachaadrika Jul 14, 2023
5c80208
Update components/Remember.js
reachaadrika Jul 14, 2023
33a4770
Update Warning.cy.js
reachaadrika Jul 14, 2023
2c22d32
Update Remember.cy.js
reachaadrika Jul 14, 2023
925e820
Update components/Profile.js
reachaadrika Jul 14, 2023
be06b6f
Merge branch 'master' into additional_tests
akshatnema Jul 16, 2023
9ffab70
Revert Ambassadors_members.json file
akshatnema Jul 16, 2023
0122320
Update mock data in Profile.js
akshatnema Jul 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/InlineHelp.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export default function InlineHelp({
<div className={className}>
{
isHelpVisible && (
<div className="absolute left-0 right-0 mt-6 p-2 bg-gray-800 text-center text-white text-xs rounded normal-case lg:-ml-4 lg:w-48">{text}</div>
<div className="absolute left-0 right-0 mt-6 p-2 bg-gray-800 text-center text-white text-xs rounded normal-case lg:-ml-4 lg:w-48" data-testid="InlineHelp">{text}</div>
)
}
<QuestionMark className="cursor-pointer h-4 -mt-0.5 inline-block text-gray-500" onClick={() => setIsHelpVisible(!isHelpVisible)} onMouseEnter={() => setIsHelpVisible(true)} onMouseLeave={() => setIsHelpVisible(false)} />
<QuestionMark className="cursor-pointer h-4 -mt-0.5 inline-block text-gray-500" onClick={() => setIsHelpVisible(!isHelpVisible)} onMouseEnter={() => setIsHelpVisible(true)} onMouseLeave={() => setIsHelpVisible(false)} data-testid="InlineHelp-icon" />
</div>
)
}
8 changes: 4 additions & 4 deletions components/MacWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ export default function MacWindow({
children,
}) {
return (
<div className={`${className} rounded`}>
<div className="flex text-left px-4 py-2">
<div className={`${className} rounded`} data-testid="MacWindow-main">
<div className="flex text-left px-4 py-2" data-testid="MacWindow-div">
<div>
<span className="inline-block rounded-full w-2.5 h-2.5 bg-mac-window-close mr-2"></span>
<span className="inline-block rounded-full w-2.5 h-2.5 bg-mac-window-minimize mr-2"></span>
<span className="inline-block rounded-full w-2.5 h-2.5 bg-mac-window-maximize mr-2"></span>
</div>
<div className="flex-1 text-gray-400 text-sm px-2 truncate text-left sm:text-center" title={title}>
<div className="flex-1 text-gray-400 text-sm px-2 truncate text-left sm:text-center" title={title} data-testid="MacWindow-title-div">
{title}
</div>
<div className="hidden sm:block"> {/* This block is used for aligning the title on the center */}
<div className="hidden sm:block" data-testid="MacWindow-title-center"> {/* This block is used for aligning the title on the center */}
<span className="inline-block w-2.5 h-2.5 mr-2"></span>
<span className="inline-block w-2.5 h-2.5 mr-2"></span>
<span className="inline-block w-2.5 h-2.5 mr-2"></span>
Expand Down
6 changes: 3 additions & 3 deletions components/NewsletterSubscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function NewsletterSubscribe ({
const paragraphTextColor = dark ? 'text-gray-300' : ''

return (
<div className={className}>
<div className={className} data-testid="NewsletterSubscribe-main">
<Heading
level="h3"
textColor={headTextColor}
Expand All @@ -28,8 +28,8 @@ export default function NewsletterSubscribe ({
<form name="form 1" method="POST" className="md:flex" data-netlify="true">
<input type="hidden" name="form-name" value="form 1" />
<input type="hidden" name="type" value={type} />
<input type="text" name="name" placeholder="Your name" className="form-input block w-full sm:text-sm sm:leading-5 md:mr-2 md:mt-0 md:flex-1 rounded-md" required />
<input type="email" name="email" placeholder="Your email" className="form-input block w-full mt-2 sm:text-sm sm:leading-5 md:mr-2 md:mt-0 md:flex-1 rounded-md" required />
<input type="text" name="name" placeholder="Your name" className="form-input block w-full sm:text-sm sm:leading-5 md:mr-2 md:mt-0 md:flex-1 rounded-md" required data-testid="NewsletterSubscribe-text-input"/>
<input type="email" name="email" placeholder="Your email" className="form-input block w-full mt-2 sm:text-sm sm:leading-5 md:mr-2 md:mt-0 md:flex-1 rounded-md" required data-testid="NewsletterSubscribe-email-input"/>
<Button type="submit" text="Subscribe" className="w-full mt-2 md:mr-2 md:mt-0 md:flex-1" />
</form>
</div>
Expand Down
5 changes: 3 additions & 2 deletions components/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ export default function Profile({profiles = [], className}) {
return null;
}
return (
<div className="p-4 grid grid-cols-2 sm:grid-cols-4 gap-5 border border-slate-100 mt-4 rounded drop-shadow-md">
<div className="p-4 grid grid-cols-2 sm:grid-cols-4 gap-5 border border-slate-100 mt-4 rounded drop-shadow-md" data-testid="Profiles-main">
{profiles.map((profile) => (
<a
<a
data-testid="Profiles-link"
href={profile.link}
key={profile.name}
target="_blank"
Expand Down
6 changes: 3 additions & 3 deletions components/Remember.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import LightBulb from './icons/LightBulb'

export default function Remember({ title = 'Remember', className, children }) {
return (
<div className={`${className} p-4 mt-4 mb-8 bg-secondary-100 rounded text-gray-900`}>
<h5 className="pb-2 mb-4 border-b border-gray-900 text-lg">
<div className={`${className} p-4 mt-4 mb-8 bg-secondary-100 rounded text-gray-900`} data-testid="Remember-main">
<h5 className="pb-2 mb-4 border-b border-gray-900 text-lg" data-testid="Remember-heading">
<LightBulb className="mr-2 -mt-0.5 h-8 inline-block" />
<span className="inline-block ml-2 font-medium font-sans antialiased">{title}</span>
<span className="inline-block ml-2 font-medium font-sans antialiased" data-testid="Remember-title">{title}</span>
</h5>
<div>
{ children }
Expand Down
6 changes: 3 additions & 3 deletions components/Warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import IconExclamation from "./icons/Exclamation";

export default function Warning({ className = '', title, description }) {
return (
<div className={`${className} rounded-md bg-yellow-50 p-4`}>
<div className={`${className} rounded-md bg-yellow-50 p-4`} data-testid="Warning-main">
<div className="flex">
<div className="flex-shrink-0">
<IconExclamation className="h-5 w-5" />
</div>
<div className="ml-3">
<h3 className="text-sm leading-5 font-medium text-yellow-800 uppercase">
<h3 className="text-sm leading-5 font-medium text-yellow-800 uppercase" data-testid="Warning-title">
{title}
</h3>
<div className="mt-2 text-sm leading-5 text-yellow-700">
<div className="mt-2 text-sm leading-5 text-yellow-700" data-testid="Warning-description">
<p>{description}</p>
</div>
</div>
Expand Down
20 changes: 20 additions & 0 deletions cypress/test/InlineHelp.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import { mount } from 'cypress/react';
import InlineHelp from '../../components/InlineHelp';

describe('InlineHelp', () => {
it('toggles help text visibility on click and hover', () => {
const text = 'Helpful information';
mount(<InlineHelp text={ text } />);
cy.get('[data-testid="InlineHelp"]').should('not.exist');
// Click on the question mark icon to show text
cy.get('[data-testid="InlineHelp-icon"]').click();
// Click on the question mark icon again to hide text
cy.get('[data-testid="InlineHelp-icon"]').click();
// Hover the question mark icon to show text
cy.get('[data-testid="InlineHelp-icon"]').trigger('mouseover');
// Move the cursor away from the question mark icon to hide text
cy.get('[data-testid="InlineHelp-icon"]').trigger('mouseout');

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

describe('MacWindow Component', () => {
it('renders the component props', () => {
const className = 'bg-code-editor-dark h-full border-gray-800 border shadow-lg transition-all duration-500 ease-in-out';
const contentClassName = "text-left text-white text-sm font-mono font-medium transition-all duration-500 ease-in-out break-words md:min-h-108";
const title="asyncapi.yaml";
const children = 'This is the children component for testing can be replaced';
mount(
<MacWindow
className={className}
contentClassName={contentClassName}
title={title}
>
{children}
</MacWindow>
);
cy.get('[data-testid="MacWindow-main"]')
.should('have.class', className)
.within(() => {
cy.get('[data-testid="MacWindow-div"]').should('exist');

cy.get('[data-testid="MacWindow-div"]').within(() => {
cy.get('div').should('have.length', 3);
});
cy.get('[data-testid="MacWindow-title-div"]')
.should('exist')
.and('have.attr', 'title', title)
.and('have.text', title);
cy.get('[data-testid="MacWindow-title-center"]').should('exist').and('have.length', 1);
});
});
});
18 changes: 18 additions & 0 deletions cypress/test/NewsletterSubscribe.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { mount } from 'cypress/react';
import NewsletterSubscribe from '../../components/NewsletterSubscribe';

describe('NewsletterSubscribe Component', () => {
it('renders the component with default props', () => {
mount(<NewsletterSubscribe />);

cy.get('[data-testid="NewsletterSubscribe-main"]').should('exist');
cy.get('[data-testid="NewsletterSubscribe-text-input"]').type("name");
cy.get('[data-testid="NewsletterSubscribe-email-input"]').type("test@gmail.com")
cy.get('form[name="form 1"]').should('exist');
cy.get('input[name="type"]').should('exist');
cy.get('input[name="name"]').should('exist');
cy.get('input[name="email"]').should('exist');

});
});
44 changes: 44 additions & 0 deletions cypress/test/Profile.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';
import { mount } from 'cypress/react';
import Profile from '../../components/Profile';
describe('Profile Component', () => {
it('renders null when profiles array is empty', () => {
const props = {
profiles: [],
className: 'my-profiles',
};
mount(<Profile {...props} />);
cy.get('[data-testid="Profiles-div"]').should('not.exist');
});

it('renders profile links and names when profiles array is not empty', () => {
const profiles = [
{
name: 'Alejandra Quetzalli',
avatar: 'https://avatars.githubusercontent.com/alequetzalli',
link: 'https://github.com/alequetzalli'
},
{
name: 'Azeez Elegbede',
avatar: 'https://avatars.githubusercontent.com/acethecreator',
link: 'https://github.com/acethecreator'
}
];
const props = {
profiles,
className: 'my-profiles',
};
mount(<Profile {...props} />);
cy.get('[data-testid="Profiles-main"]').find('[data-testid="Profiles-link"]').should('have.length', profiles.length)
.each(($profileLink, index) => {
const profile = profiles[index];
cy.wrap($profileLink)
.should('have.attr', 'href', profile.link)
.find('img')
.should('have.attr', 'src', profile.avatar)
.should('have.attr', 'alt', profile.name)
.siblings('.text-sm')
.should('have.text', profile.name);
});
});
});
42 changes: 42 additions & 0 deletions cypress/test/Remember.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import { mount } from 'cypress/react';
import Remember from '../../components/Remember';
import LightBulb from '../../components/icons/LightBulb';
describe('Remember Component', () => {
it('renders the component with the provided title and children', () => {
const title = 'Remember This';
const className = 'remember';
const children = <div data-testid="Remember-children">Remember content</div>;
mount(
<Remember title={title} className={className}>
{children}
</Remember>
);
cy.get('[data-testid="Remember-main"]')
.should('exist')
.within(() => {
cy.get('[data-testid="Remember-heading"]')
.should('have.length', 1)
.within(() => {
cy.get(LightBulb).should('exist');
cy.contains('[data-testid="Remember-title"]', title).should('exist');
});

cy.get('[data-testid="Remember-children"]').should('exist');
});
});

it('renders the component with default title and no children', () => {
const className = 'remember';
mount(<Remember className={className} />);
cy.get('[data-testid="Remember-main"]')
.should('exist')
.within(() => {
cy.get('[data-testid="Remember-heading"]').should('have.length', 1).within(() => {
cy.get(LightBulb).should('exist');
cy.contains('[data-testid="Remember-title"]', 'Remember').should('exist');
});
cy.get('[data-testid="Remember-children"]').should('not.exist');
});
});
});
22 changes: 22 additions & 0 deletions cypress/test/Warning.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { mount } from 'cypress/react';
import Warning from '../../components/Warning';
import IconExclamation from '../../components/icons/Exclamation';

describe('Warning Component', () => {
it('renders the component with the provided title and description', () => {
const className = 'my-warning';
const title = 'Warning Title';
const description = 'Warning description text';
mount(
<Warning className={className} title={title} description={description} />
);
cy.get('[data-testid="Warning-main"]')
.should('exist')
.within(() => {
cy.get(IconExclamation).should('exist');
cy.contains('[data-testid="Warning-title"]', title).should('exist');
cy.contains('[data-testid="Warning-description"]', description).should('exist');
});
});
});