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 newsroom component #1891

Merged
merged 34 commits into from
Jul 17, 2023

Conversation

reachaadrika
Copy link
Contributor

Description

  • Newsroom component , of the website , has following components within it , and each component represented a piece of Newsroom component . Following are the components that are included for this :

  • Featured BlogItem
    image

  • Newsroom
    image

-NewsroomArticle
image

  • NewsroomBlogPost
    image

-NewsroomSection
image

-NewsroomYoutube
image

-YoutubeCard
image

-Swiper
image

Related issue(s)
fixes #1773

@netlify
Copy link

netlify bot commented Jul 3, 2023

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 78b1943
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/64b55fd8fe742a00087c47c0
😎 Deploy Preview https://deploy-preview-1891--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: adding unit tests for newroom component feat: adding unit tests for newsroom component Jul 3, 2023
@github-actions
Copy link

github-actions bot commented Jul 3, 2023

⚡️ Lighthouse report for the changes in this PR:

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

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

Copy link
Member

@akshatnema akshatnema left a comment

Choose a reason for hiding this comment

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

Do relevant changes as suggested in test files as well.

components/newsroom/Newsroom.js Outdated Show resolved Hide resolved
components/newsroom/Newsroom.js Outdated Show resolved Hide resolved
components/newsroom/Newsroom.js Outdated Show resolved Hide resolved
components/newsroom/Newsroom.js Outdated Show resolved Hide resolved
Comment on lines 21 to 28
<section className="mt-10 lg:mt-4 relative w-fit mx-auto lg:w-1/2" data-testid="NewsroomSection-div">
<div className='absolute z-10 -mt-6'>
<Button className="text-center block md:inline-block border-secondary-500 border text-secondary-500 shadow-md p-2" text="FEATURED BLOG POST" bgClassName="bg-secondary-100" />
</div>
<FeaturedBlogPost post={posts[0]} />
</section>
<section className="lg:text-left lg:max-w-xl lg:w-1/2 lg:ml-12 mt-5 lg:my-auto">
<section className="lg:text-left lg:max-w-xl lg:w-1/2 lg:ml-12 mt-5 lg:my-auto" data-testid="Newsroom-sectionDiv">
<Heading typeStyle="heading-md-semibold" level="h3">
Copy link
Member

Choose a reason for hiding this comment

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

I see that the data-testId used in both div tag are of almost same name, written in different style. You shouldn't practice this naming conventions. Instead, make the testId related to the content inside the div. For example, NewsroomSection-div can be written as NewsroomSection-Featured and Newsroom-sectionDiv can be written as NewsroomSection-main.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applying the suggested changes

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/newsroom/NewsroomYoutube.js Outdated Show resolved Hide resolved
components/newsroom/YouTubeCard.js Outdated Show resolved Hide resolved
components/newsroom/YouTubeCard.js Outdated Show resolved Hide resolved
Comment on lines 4 to 254
{
"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.

Store this object as part of different static file where you can use this content to test BlogLayout and DocLayout as well.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once this PR is merged , will add for docsLayout and BlogLayout as well , else it will cause a lot of conflicts .

@akshatnema akshatnema added the gsoc This label should be used for issues or discussions related to ideas for Google Summer of Code label Jul 10, 2023
target="_blank"
rel="noopener noreferrer"
data-testid={ `article-${ index }` }
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={ `article-${ index }` }
data-testid={ `NewsroomArticle-${ index }` }

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

@@ -53,10 +53,10 @@ export default function NewsroomBlogPosts() {
</Swiper>

<div className="flex flex-row ml-2 justify-content-center md:justify-content-start">
<button ref={prevElRef} className={`${buttonClass} py-3 px-6 ml-0 ${current === 0 ? 'cursor-not-allowed bg-white border-gray-200 text-gray-200' : 'bg-secondary-100 hover:bg-secondary-500 border-secondary-500 text-secondary-500 hover:text-white'}`}>
<button ref={prevElRef} className={`${buttonClass} py-3 px-6 ml-0 ${current === 0 ? 'cursor-not-allowed bg-white border-gray-200 text-gray-200' : 'bg-secondary-100 hover:bg-secondary-500 border-secondary-500 text-secondary-500 hover:text-white'}`} data-testid="Blog-Next">
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
<button ref={prevElRef} className={`${buttonClass} py-3 px-6 ml-0 ${current === 0 ? 'cursor-not-allowed bg-white border-gray-200 text-gray-200' : 'bg-secondary-100 hover:bg-secondary-500 border-secondary-500 text-secondary-500 hover:text-white'}`} data-testid="Blog-Next">
<button ref={prevElRef} className={`${buttonClass} py-3 px-6 ml-0 ${current === 0 ? 'cursor-not-allowed bg-white border-gray-200 text-gray-200' : 'bg-secondary-100 hover:bg-secondary-500 border-secondary-500 text-secondary-500 hover:text-white'}`} data-testid="Blog-Prev-button">

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

<ArrowLeft className='w-4' />
</button>
<button ref={nextElRef} className={`${buttonClass} py-1 px-4 ${checkLastSnapIndex(current) ? 'cursor-not-allowed bg-white border-gray-200 text-gray-200' : 'bg-secondary-100 hover:bg-secondary-500 border-secondary-500 text-secondary-500 hover:text-white'}`}>
<button ref={nextElRef} className={`${buttonClass} py-1 px-4 ${checkLastSnapIndex(current) ? 'cursor-not-allowed bg-white border-gray-200 text-gray-200' : 'bg-secondary-100 hover:bg-secondary-500 border-secondary-500 text-secondary-500 hover:text-white'}`} data-testid="Blog-Prev">
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
<button ref={nextElRef} className={`${buttonClass} py-1 px-4 ${checkLastSnapIndex(current) ? 'cursor-not-allowed bg-white border-gray-200 text-gray-200' : 'bg-secondary-100 hover:bg-secondary-500 border-secondary-500 text-secondary-500 hover:text-white'}`} data-testid="Blog-Prev">
<button ref={nextElRef} className={`${buttonClass} py-1 px-4 ${checkLastSnapIndex(current) ? 'cursor-not-allowed bg-white border-gray-200 text-gray-200' : 'bg-secondary-100 hover:bg-secondary-500 border-secondary-500 text-secondary-500 hover:text-white'}`} data-testid="Blog-Next-button">

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

@@ -17,7 +17,7 @@ export default function NewsroomYoutube({ className = '' }) {
const buttonClass = 'shadow-md rounded border mx-2 mb-2 focus:outline-none';

return (
<div className="flex-col overflow-auto">
<div className="flex-col overflow-auto" data-testid="NewsroomYoutube-main">
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
<div className="flex-col overflow-auto" data-testid="NewsroomYoutube-main">
<div className={`flex-col overflow-auto ${className}`} data-testid="NewsroomYoutube-main">

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

@@ -41,10 +41,10 @@ export default function NewsroomYoutube({ className = '' }) {
</Swiper>

<div className="flex flex-row ml-2 justify-content-center md:justify-content-start">
<button ref={prevElRef} className={`${buttonClass} py-3 px-6 ml-0 ${current === 0 ? 'cursor-not-allowed bg-white border-gray-200 text-gray-200' : 'bg-secondary-100 hover:bg-secondary-500 border-secondary-500 text-secondary-500 hover:text-white'}`}>
<button ref={prevElRef} className={`${buttonClass} py-3 px-6 ml-0 ${current === 0 ? 'cursor-not-allowed bg-white border-gray-200 text-gray-200' : 'bg-secondary-100 hover:bg-secondary-500 border-secondary-500 text-secondary-500 hover:text-white'}`} data-testid="Youtube-Next">
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
<button ref={prevElRef} className={`${buttonClass} py-3 px-6 ml-0 ${current === 0 ? 'cursor-not-allowed bg-white border-gray-200 text-gray-200' : 'bg-secondary-100 hover:bg-secondary-500 border-secondary-500 text-secondary-500 hover:text-white'}`} data-testid="Youtube-Next">
<button ref={prevElRef} className={`${buttonClass} py-3 px-6 ml-0 ${current === 0 ? 'cursor-not-allowed bg-white border-gray-200 text-gray-200' : 'bg-secondary-100 hover:bg-secondary-500 border-secondary-500 text-secondary-500 hover:text-white'}`} data-testid="Youtube-Prev-button">

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/newsroom/NewsroomBlogPost.cy.js Show resolved Hide resolved
});
it('slides to the next slide', () => {
mount(<NewsroomBlogPosts />);
cy.get('[data-testid="Blog-Next"]').click();
Copy link
Member

Choose a reason for hiding this comment

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

Make the click event work automatically using trigger or { force: true }.

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

it('slides to the next slide', () => {
mount(<NewsroomBlogPosts />);
cy.get('[data-testid="Blog-Next"]').click();

Copy link
Member

Choose a reason for hiding this comment

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

Use CSS class libraries of swiper to see which is the active post inside the slider. CSS library used is: swiper-slide-active.

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

@@ -0,0 +1,25 @@
import { mount } from 'cypress/react'
import NewsroomSection from '../../../components/newsroom/NewsroomSection';
const newsroom = ["Latest news and blogs", "Welcome to our Newsroom section. Here, you'll get latest information about our blogs, articles, announcements and Youtube live-streams. Let's get upto date with the recent activities in the organization."]
Copy link
Member

Choose a reason for hiding this comment

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

Only check for the heading, the content inside heading can be modified later on.

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

Copy link
Member

Choose a reason for hiding this comment

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

This is not updated in implementation yet.

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

const newsroom = ["Latest news and blogs", "Welcome to our Newsroom section. Here, you'll get latest information about our blogs, articles, announcements and Youtube live-streams. Let's get upto date with the recent activities in the organization."]
describe('Features Component', () => {
it('renders without errors', () => {
mount(<NewsroomSection />);
Copy link
Member

Choose a reason for hiding this comment

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

Use beforeEach function of cypress to avoid repition of mount function.

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

cypress/test/newsroom/Newsroom.cy.js Outdated Show resolved Hide resolved
Comment on lines 26 to 37
it('checks TwitterTimelineEmbed', () => {
mount(
<div className='w-full md:w-1/2 px-2 md:pr-0 md:pl-4'>
<div className="rounded-xl shadow-md mt-8 w-full mx-auto md:mt-0" data-testid="Newsroom-Twitter">
<TwitterTimelineEmbed
sourceType="profile"
screenName="AsyncAPISpec"
options={ { tweetLimit: '2' } }
/>
</div>
</div>
);
Copy link
Member

Choose a reason for hiding this comment

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

We can't test the component like this by moounting the hardcoded implementation right from the test file. You should check for the Twitter Ebed using data-testId only.

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,25 @@
import { mount } from 'cypress/react'
import NewsroomSection from '../../../components/newsroom/NewsroomSection';
const newsroom = ["Latest news and blogs", "Welcome to our Newsroom section. Here, you'll get latest information about our blogs, articles, announcements and Youtube live-streams. Let's get upto date with the recent activities in the organization."]
Copy link
Member

Choose a reason for hiding this comment

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

This is not updated in implementation yet.

@akshatnema
Copy link
Member

/rtm

@asyncapi-bot asyncapi-bot merged commit ab12e85 into asyncapi:master Jul 17, 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.

adding unit tests for newsroom component
3 participants