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 layout component #1914

Merged
merged 27 commits into from
Jul 16, 2023

Conversation

reachaadrika
Copy link
Contributor

Description

  • A brief Introduction , about Layout component , this component , has the basic layouts for all other components , and it renders the pattern in which these components have to be rendered

  • BlogLayout : This component renders the Blog like structure and renders the blog posts for this .
    image

  • Column Layout : This component renders any children component in column component
    image

  • DocsLayout : This component renders the Docs like structure and renders the docs posts for this
    image

-JobsLayout : This component renders the Jobs like structure and renders the docs posts for this

  • GenericLAYOUT , GenericPostLayout , GenericWideLayout : These components are for Generic components , where by passing props like title , images and others we can modify it too .

-Layout , this component is the main file and renders the component based on various if and else basis , according to the pathnames , here I have added some extra divs that wraps these components for testing .

NOTE :- These components had extensive use of routers , thus I mocked routers since cypress doesn't provide this functionality I have mocked a Router and then wrapped the children components and have passed the pathname to it as value .

Related issue(s)
fixes #1913

@netlify
Copy link

netlify bot commented Jul 7, 2023

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit b9453a0
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/64b3d4df3b7e24000885590a
😎 Deploy Preview https://deploy-preview-1914--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@reachaadrika reachaadrika changed the title feat : Add tests for layout component feat: adding unit tests for layout component Jul 7, 2023
@github-actions
Copy link

github-actions bot commented Jul 7, 2023

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 45
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 100
🔴 PWA 30

Lighthouse ran on https://deploy-preview-1914--asyncapi-website.netlify.app/

<Tag className={fluid ? fluidClassNames : normalClassNames}>
<Tag
className={fluid ? fluidClassNames : normalClassNames}
data-testid="Container-div"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data-testid="Container-div"
data-testid="Container-main"

Applicable everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

components/layout/DocsLayout.js Outdated Show resolved Hide resolved
components/layout/GenericLayout.js Outdated Show resolved Hide resolved
<ApplyJobButton
job={post}
className="mt-4 inline-block"
data-testid="ApplyJobLayout"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data-testid="ApplyJobLayout"
data-testid="ApplyJobButton"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 16 to 18
onOpen: () => {},
onClose: () => {},
onInput: () => {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the functions, part of React Context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

cypress/test/layout/GenericPostLayout.cy.js Outdated Show resolved Hide resolved
Comment on lines 4 to 501
},
{
content: 'Most popular repositories',
slug: 'most-popular-repositories',
lvl: 3,
i: 19,
seen: 0,
},
{
content: 'Traffic growth',
slug: 'traffic-growth',
lvl: 3,
i: 20,
seen: 0,
},
{
content: "What's next with GitHub",
slug: 'whats-next-with-github',
lvl: 3,
i: 21,
seen: 0,
},
{
content: 'npm',
slug: 'npm',
lvl: 2,
i: 22,
seen: 0,
},
{
content: 'Top packages',
slug: 'top-packages',
lvl: 3,
i: 23,
seen: 0,
},
{
content: "What's next with npm",
slug: 'whats-next-with-npm',
lvl: 3,
i: 24,
seen: 0,
},
{
content: 'YouTube',
slug: 'youtube',
lvl: 2,
i: 25,
seen: 0,
},
{
content: 'Watch time goes crazy',
slug: 'watch-time-goes-crazy',
lvl: 3,
i: 26,
seen: 0,
},
{
content: 'Most popular videos',
slug: 'most-popular-videos',
lvl: 3,
i: 27,
seen: 0,
},
{
content: "What's next with YouTube",
slug: 'whats-next-with-youtube',
lvl: 3,
i: 28,
seen: 0,
},
{
content: 'Open Collective',
slug: 'open-collective',
lvl: 2,
i: 29,
seen: 0,
},
{
content: 'Ultimate questions - how many people use the spec?',
slug: 'ultimate-questions---how-many-people-use-the-spec',
lvl: 2,
i: 30,
seen: 0,
},
{
content: 'Final words',
slug: 'final-words',
lvl: 2,
i: 31,
seen: 0,
},
],
readingTime: 18,
sectionSlug: '/blog',
sectionWeight: 0,
id: 'pages/blog/2020-summary.md',
isIndex: false,
slug: '/blog/2020-summary',
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test data shouldn't be part of test files. Make these content available inside fixtures folder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1,32 @@
import { mount } from 'cypress/react';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this component test file as it is no more in use inside codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 5 to 60
const post = {
title: 'API Architect',
date: '06/22/2021',
category: 'Architect',
closingOn: '08/22/2021',
contact: 'https://apiture.com/careers/?gh_jid=5303104002',
company: {
name: 'Apiture',
logoUrl: '/img/logos/companies/apiture.png',
},
toc: [
{
content: 'About the team',
slug: 'about-the-team',
lvl: 2,
i: 0,
seen: 0,
},
{
content: 'TL;DR',
slug: 'tldr',
lvl: 2,
i: 1,
seen: 0,
},
{
content: 'About the job',
slug: 'about-the-job',
lvl: 2,
i: 2,
seen: 0,
},
{
content: 'About you',
slug: 'about-you',
lvl: 2,
i: 3,
seen: 0,
},
{
content: 'Pay and benefits',
slug: 'pay-and-benefits',
lvl: 2,
i: 4,
seen: 0,
},
],
readingTime: 5,
excerpt:
'About the team\n\nWe are an open API banking platform, focused on creating cutting-edge technology for financial institutions.\nThe platform allows banks the fast and flexible deployment of features that',
sectionSlug: '/jobs',
sectionWeight: 0,
id: 'pages/jobs/apiture-api-architect.md',
isIndex: false,
slug: '/jobs/apiture-api-architect',
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this static data in fixtures/post.json and then use it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

cypress/test/layout/Layout.cy.js Outdated Show resolved Hide resolved
cypress/utils/router.js Outdated Show resolved Hide resolved
Comment on lines 29 to 31
MockRouter.propTypes = {
children: PropTypes.node.isRequired,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to define propTypes like this? We are not using Typescript and eslint warnings can be ignored for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@akshatnema akshatnema added the gsoc This label should be used for issues or discussions related to ideas for Google Summer of Code label Jul 13, 2023
{/* Twitter Card data */}
<meta name="twitter:card" value="summary_large_image" />
<meta name="twitter:card" content="summary_large_image" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why value has been changed to content?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to some error , resolved this to previous one since it is not needed now .

@akshatnema
Copy link
Member

/rtm

@asyncapi-bot asyncapi-bot merged commit bd4504a into asyncapi:master Jul 16, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gsoc This label should be used for issues or discussions related to ideas for Google Summer of Code ready-to-merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add tests for layout component
4 participants