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: add integration tests for dashboard component & community pages #1953

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
36cf5b1
integration test for dashboard
reachaadrika Jul 14, 2023
1683fba
fixes for dashboard unit tests
reachaadrika Jul 14, 2023
2d3511f
Merge branch 'master' into dashboard_integration_tests
reachaadrika Jul 14, 2023
d21f53b
Merge branch 'master' into dashboard_integration_tests
reachaadrika Jul 17, 2023
c9d07ea
Merge branch 'master' of https://github.com/reachaadrika/website into…
reachaadrika Jul 17, 2023
e9bdc03
updated test for dashboard & mockApp
reachaadrika Jul 17, 2023
1eaf47f
Merge branch 'dashboard_integration_tests' of https://github.com/reac…
reachaadrika Jul 17, 2023
3d25ae8
Merge branch 'master' into dashboard_integration_tests
reachaadrika Jul 17, 2023
9ad0ca2
add community pages
reachaadrika Jul 17, 2023
5049edb
Update formatting in test files
akshatnema Jul 18, 2023
ed1d8d0
Merge branch 'master' into dashboard_integration_tests
reachaadrika Jul 18, 2023
37b81e9
add tests for community\events
reachaadrika Jul 18, 2023
1c69e4b
Resolve errors
akshatnema Jul 20, 2023
a6d2646
Merge branch 'master' into dashboard_integration_tests
reachaadrika Jul 20, 2023
5ece9f1
Merge branch 'dashboard_integration_tests' of https://github.com/reac…
reachaadrika Jul 20, 2023
3efcff7
add events
reachaadrika Jul 20, 2023
447c4bf
completed events page
reachaadrika Jul 20, 2023
930e5b9
completed tsc page
reachaadrika Jul 20, 2023
a2a043c
removed redundant code
reachaadrika Jul 20, 2023
741b3fa
Merge branch 'master' into dashboard_integration_tests
reachaadrika Jul 24, 2023
0009188
Merge branch 'master' into dashboard_integration_tests
reachaadrika Jul 29, 2023
8d85110
Update cypress/test/pages/community/ambassadors/index.cy.js
reachaadrika Jul 30, 2023
3fb3789
add corrected data-testids for buttons
reachaadrika Jul 30, 2023
3c778c5
chanegs in ambassadors
reachaadrika Jul 30, 2023
b1fda59
refactor community/index
reachaadrika Jul 30, 2023
c64241a
add test for EventFilters and other changes
reachaadrika Jul 30, 2023
95d5966
Merge branch 'dashboard_integration_tests' of https://github.com/reac…
reachaadrika Jul 30, 2023
47f12db
add need for MockApp and MockRouter
reachaadrika Jul 30, 2023
db03487
Merge branch 'master' into dashboard_integration_tests
reachaadrika Aug 1, 2023
c13b3d7
add specific event filters test
reachaadrika Aug 1, 2023
b32aece
Update formatting and doc comments for test files
akshatnema Aug 1, 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
8 changes: 4 additions & 4 deletions components/community/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function SmallHomeCards({icon, tagline, taglineBg, type="large",
<a target={link.includes('http') && '_blank'}>
<div
className={`p-3 cursor-pointer border shadow-xl rounded w-full border-[#ad20e2] ${bg}`}
>
data-testid="Card-small-bg">
<div className="p-2 rounded-xl bg-gray-100 text-center w-min text-xs flex justify-between">
<span>{icon}</span> <span className="ml-[5px]">{tagline}</span>
</div>
Expand Down Expand Up @@ -41,10 +41,10 @@ export default function SmallHomeCards({icon, tagline, taglineBg, type="large",
className={`h-140 w-full shadow-xl rounded p-6 border ${
!bg && 'border-[#ad20e2]'
} ${bg}`}
>
data-testid="Card-lg-bg">
<div
className={`p-2 rounded-xl text-center w-min text-xs flex justify-between ${taglineBg}`}
>
data-testid="Card-lg-tagline">
<span>{icon}</span> <span className="ml-[5px]">{tagline}</span>
</div>

Expand All @@ -62,7 +62,7 @@ export default function SmallHomeCards({icon, tagline, taglineBg, type="large",
</div>
<div className="mt-10">
<Link href={link}>
<a>
<a data-testid="Card-link-lg">
<div className={`flex ${btnBg} cursor-pointer`}>
<IconArrowUp className={`w-[20px] ${btnBg}`} />{' '}
<span className="ml-2 text-sm">{btnText}</span>
Expand Down
3 changes: 3 additions & 0 deletions cypress/test/community/Card.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ describe('SmallHomeCards', () => {
cy.get('[data-testid="Card-desc"]').contains('Description').should('exist');
cy.get('[data-testid="Card-heading"]').should('have.class','mt-3');
cy.get('[data-testid="Card-desc"]').should('have.class','mt-2');
cy.get(`[href="/path"]`).should('exist');

});

it('renders large card correctly', () => {
Expand All @@ -46,6 +48,7 @@ describe('SmallHomeCards', () => {
// Testing for large prop classes and styles
cy.get('[data-testid="Card-heading-lg"]').contains('Heading').should('exist');
cy.get('[data-testid="Card-desc-lg"]').contains('Description').should('exist');
cy.get(`[href="/path"]`).should('exist');
cy.get('[data-testid="Card-heading-lg"]').should('have.class','mt-10');
cy.get('[data-testid="Card-desc-lg"]').should('have.class','mt-6');

Expand Down
6 changes: 2 additions & 4 deletions cypress/test/dashboard/GoodFirstIssuesTip.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ describe('GoodFirstIssuesTip', () => {
});

it('toggles the tip when hovering over the icon', () => {
cy.get('[data-testid="GoodFirstIssuesTip-hover-icon"]').trigger('mouseenter');
cy.get('[data-testid="GoodFirstIssuesTip-hover-icon"]').trigger('mouseleave');

cy.get('[data-testid="GoodFirstIssuesTip-hover-icon"]').click({force:true});
});

it('renders the tip content with the correct text', () => {
cy.get('[data-testid="GoodFirstIssuesTip-hover-icon"]').trigger('mouseenter');
cy.get('[data-testid="GoodFirstIssuesTip-hover-icon"]').click({force:true});
//checking for the available class here
cy.get('.bg-white').should('have.css', 'visibility', 'visible');

Expand Down
5 changes: 3 additions & 2 deletions cypress/test/dashboard/Header.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ describe('Header', () => {
'contain',
'Visualize our progress. Get involved.'
);
cy.get('[data-testid="Github-button"]').should('exist');
cy.get('[data-testid="Slack-button"]').should('exist');
Comment on lines -25 to -26
Copy link
Member

Choose a reason for hiding this comment

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

These lines shouldn't be removed. We should also check for buttons using data-testid also, apart from checking it via text.

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


cy.contains('Contribution Guide')
.should('have.attr', 'href', 'https://github.com/asyncapi?type=source#-contribute-to-asyncapi')
.should('have.attr', 'target', '_blank');
cy.contains('View on Github')
cy.contains('Join on Slack')
Copy link
Member

Choose a reason for hiding this comment

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

Why did we change these tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

});
});
95 changes: 95 additions & 0 deletions cypress/test/pages/community/ambassadors/index.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import MockApp from "../../../../utils/mockApp";
import Index from '../../../../../pages/community/ambassadors/index'
import ambassadorList from '../../../../../config/ambassador_lists.json'
import ambassadors from '../../../../../config/AMBASSADORS_MEMBERS.json'
import { addAdditionalUserInfo } from "../../../../../pages/community/ambassadors/index";
import { sortBy } from 'lodash';
reachaadrika marked this conversation as resolved.
Show resolved Hide resolved
describe('Test for Ambassadors', () => {
beforeEach(() => {
cy.mount(<MockApp><Index /></MockApp>)
});

it('displays the main Ambassadors section ', () => {
cy.get('[data-testid="Ambassadors-main"]').should('exist')
cy.get('[data-testid="Ambassadors-content"]').should('exist')
cy.get('[data-testid="Ambassadors-button"]').should('exist')
cy.get(`[href="https://github.com/asyncapi/community/blob/master/AMBASSADOR_ORGANIZATION.md#are-you-interested-in-becoming-an-official-asyncapi-ambassador"]`).should('exist');
cy.get('[data-testid="Ambassadors-Iframe"]').should('exist')
cy.get('[data-testid="Ambassadors-contributions"]').should('exist')
});

it('renders the ambassador list with correct data', () => {
ambassadorList.contents.forEach((link) => {
cy.get('[data-testid="Ambassadors-list"]')
.find(`img[alt="${link.title}"]`)
.should('exist')
.and('have.attr', 'src', link.icon);

cy.get('[data-testid="Ambassadors-list"]')
.contains('h2', link.title)
.should('exist');

cy.get('[data-testid="Ambassadors-list"]')
.contains('p', link.details)
.should('exist');
});
});

it('renders the ambassadors with correct data', () => {
const asyncapiAmbassadors = sortBy(
ambassadors.map((user) => addAdditionalUserInfo(user)),
['name']
);
cy.get('[data-testid="Ambassadors-members-main"]')
.children()
.should('have.length', asyncapiAmbassadors.length);

asyncapiAmbassadors.forEach((ambassador) => {
cy.get('[data-testid="Ambassadors-members-details"]')
.contains('div', ambassador.name)

cy.get('[data-testid="Ambassadors-members-img"]')
.find(`img[alt="${ambassador.name}"]`)

.and('have.attr', 'src', ambassador.img);

cy.get('[data-testid="Ambassadors-members"]')
.contains('div', ambassador.title);

});

});

it('displays the Tokens of our appreciation section with correct data', () => {
cy.contains('Tokens of our appreciation').should('exist');

cy.contains('We appreciate your commitment and passion for sharing your knowledge with your communities. Let us support you!')
.should('exist');
Copy link
Member

Choose a reason for hiding this comment

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

Instead of checking for the content, check for the respective tags, whether they are present. We are not concerned about testing the content inside the tag, we are testing whether the heading and relative content to it is present or not.

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


ambassadorList.tokens.forEach((token) => {
cy.contains('.mt-20 li', token.emoji).should('exist');
cy.contains('.mt-20 li', token.title).should('exist');
cy.contains('.mt-20 li', token.details).should('exist');
});
});

it('displays the Become an AsyncAPI Ambassador section with correct data', () => {
cy.contains('Become an AsyncAPI Ambassador').should('exist');

cy.contains('The AsyncAPI Ambassador program is now open for applications! If you’re selected, you’ll join AsyncAPI\'s mission of helping community members all over the world, build the future of Event-Driven APIs.')
.should('exist');
Copy link
Member

Choose a reason for hiding this comment

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

Don't check for content, check for the tags using data-testid.

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


cy.contains('Become an Ambassador now')
.should('have.attr', 'href', 'https://github.com/asyncapi/community/blob/master/AMBASSADOR_ORGANIZATION.md#are-you-interested-in-becoming-an-official-asyncapi-ambassador');
});

it('should display 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("[email protected]")
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');
});
});
28 changes: 28 additions & 0 deletions cypress/test/pages/community/dashboard.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import MockApp from "../../../utils/mockApp";
import Home from "../../../../pages/community/dashboard";
import Header from "../../../../components/dashboard/Header";
import { mount } from '@cypress/react'
describe('Integration Test for Dashboard ', () => {

it('should filter GoodFirstIssues and check dashboard render ', () => {
mount(
<MockApp>
<Home />
</MockApp>
);
// Click on the first filter option
cy.get(Header).should('exist')
cy.contains('AsyncAPI - Dashboard')
cy.get('[data-testid="Filters-img-container"]').click({ force: true });
cy.get('[data-testid="Filter-menu"]').within(() => {
cy.get('[data-testid="Select-form"]').eq(0).select('asyncapi/generator', { force: true });
cy.get('[data-testid="Select-form"]').eq(1).select('docs')
});
//check if selected is only displayed
cy.contains('asyncapi/generator');
cy.contains('docs')
//check if this is not selected options are not displayed
cy.should('not.contain', 'asyncapi/community');
cy.should('not.contain', 'javascript');
});
});
74 changes: 74 additions & 0 deletions cypress/test/pages/community/index.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import MockApp from "../../../utils/mockApp";
import CommunityIndexPage from "../../../../pages/community";

describe('CommunityIndexPage', () => {
beforeEach(() => {
cy.mount(<MockApp><CommunityIndexPage /></MockApp>)
});

it('displays the page title & check for first Community Home Card', () => {
cy.contains('AsyncAPI Community Meetings');
cy.get('[data-testid="CommunityIndex-HomeCard"]').should('exist')
cy.get('[data-testid="HomeCard-main"]').contains('Thanking our AsyncAPI Ambassadors')
cy.get('[data-testid="HomeCard-title"]').contains('Ambassador Programs')
cy.get(`[href="/community/ambassadors"]`).should('exist');
cy.get('[data-testid="HomeCard-button"]').should('exist');
cy.get(".bg-ambassador").should('exist')
});

it('checks for CommunityIndex Display Card', () => {
cy.get('[data-testid="CommunityIndex-IssuesCard"]').should('exist')
cy.get('[data-testid="Card-lg-bg"]').should('have.class', 'bg-code-editor-dark')
cy.get('[data-testid="Card-lg-tagline"]').should('have.class', 'bg-pink-100')
cy.get('[data-testid="Card-heading-lg"]').should('exist');
cy.get('[data-testid="Card-desc-lg"]').should('exist');
cy.get(`[href="/community/dashboard"]`).should('exist');
});

it('should display the Newsroom Card', () => {
cy.get('[data-testid="CommunityIndex-Newsroom-Card"]').should('exist');
cy.get('[data-testid="Card-lg-bg"]').should('have.class', 'bg-code-editor-dark');
cy.get('[data-testid="Card-lg-tagline"]').should('have.class', 'bg-pink-100');
cy.get('[data-testid="Card-heading-lg"]').should('exist');
cy.get('[data-testid="Card-desc-lg"]').should('exist');
cy.get('[href="/community/newsroom"]').should('exist');
});

it('should display the Toolings Card', () => {
cy.get('[data-testid="CommunityIndex-Toolings-Card"]').should('exist');
cy.get('[data-testid="Card-lg-tagline"]').should('exist')
cy.get('[data-testid="Card-heading-lg"]').should('exist')
cy.get('[data-testid="Card-desc-lg"]').should('exist')
cy.get('[href="/tools"]').should('exist');
});

it('should display other cards correctly', () => {
cy.get('[data-testid="CommunityCards-Goals"]').should('exist');
cy.get('[href="https://github.com/asyncapi/community/discussions/513"]').should('exist');
cy.get('[data-testid="CommunityCards-Contributors"]').should('exist');
cy.get('[href="https://github.com/orgs/asyncapi/discussions/593"]').should('exist');
cy.get('[data-testid="CommunityCards-TSC"]').should('exist');
cy.get('[href="/community/tsc"]').should('exist');
});

it('should display slack card ' ,() => {
cy.get('[data-testid="CommunityCards-Slack"]').should('exist');
cy.get('[data-testid="CommunityIndex-HomeCard"]').should('exist')
cy.get('[data-testid="HomeCard-main"]').contains('All community info, tracked')
cy.get('[data-testid="HomeCard-title"]').contains('AsyncAPI Slack')
cy.get(`[href="https://asyncapi.com/slack-invite"]`).should('exist');
cy.get('[data-testid="HomeCard-button"]').should('exist');
cy.get(".bg-channelCover").should('exist')
});

it('should display NewsletterSubscribe',()=>{
cy.get('[data-testid="CommunityCard-subscribe"]').should('exist');
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("[email protected]")
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');
});
Copy link
Member

Choose a reason for hiding this comment

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

This test shouldn't be repeated for every file. Instead, make integration test for this component in NewsletterSubscribe test file. Also, mock the API response for this form.

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

});
14 changes: 14 additions & 0 deletions cypress/test/pages/community/newsroom.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import MockApp from "../../../utils/mockApp";
import { mount } from "@cypress/react";
import NewsroomSection from '../../../../components/newsroom/NewsroomSection'

describe('Test for Newsroom Section Pages', () => {
it('renders correctly', () => {
mount(
<MockApp>
<NewsroomSection/>
</MockApp>
);

});
});
27 changes: 27 additions & 0 deletions cypress/utils/MockApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import AppContext from "../../context/AppContext";
Copy link
Member

Choose a reason for hiding this comment

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

Specify why MockApp has been created using comments.

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

import { MDXProvider } from "../../components/MDX";
import Layout from "../../components/layout/Layout";
import AlgoliaSearch from "../../components/AlgoliaSearch";
import { createRouter } from "./router";
import MockRouter from "./router";

import Head from "next/head";

export default function MockApp({ children }) {
return (
<AppContext.Provider value={{ path: createRouter.asPath }}>
<Head>
<script async defer src="https://buttons.github.io/buttons.js"></script>
</Head>
<MDXProvider>
<AlgoliaSearch>
<div className="flex flex-col min-h-screen">
<MockRouter pathname="/">
<Layout> {children} </Layout>
</MockRouter>
</div>
</AlgoliaSearch>
</MDXProvider>
</AppContext.Provider>
)
}
2 changes: 1 addition & 1 deletion cypress/utils/router.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { RouterContext } from 'next/dist/shared/lib/router-context';

const createRouter = (params) => ({
export const createRouter = (params) => ({
route: '/',
pathname: '/',
query: {},
Expand Down
Loading
Loading