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

236 add first e2e test newbies page #237

Merged
merged 11 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default function RootLayout({
children,
params: { locale },
}: {
children: React.ReactNode;
params: { locale: string };
}) {
return (
<html lang={locale} dir="rtl">
<body>{children}</body>
</html>
);
}
7 changes: 5 additions & 2 deletions components/Common/Faqs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const Faqs = ({ faqs }: FaqsProps) => {
{t('secondParagraph')}
</p>

<div className="min-h-[60px] px-4 md:mx-20 ">
<div className="min-h-[60px] px-4 md:mx-20" data-testid="faq-section">
<Accordion
type="single"
className="font-medium"
Expand All @@ -45,7 +45,10 @@ const Faqs = ({ faqs }: FaqsProps) => {
<AccordionTrigger className="text-lg text-right">
{faq.question}
</AccordionTrigger>
<AccordionContent className="text-base font-inter pl-6">
<AccordionContent
className="text-base font-inter pl-6"
data-testid={`faq-content-${index + 1}`}
>
{faq.answer}
</AccordionContent>
</AccordionItem>
Expand Down
1 change: 1 addition & 0 deletions components/Newbies/LinksSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const LinksSection = () => {
<div className="flex flex-col items-center mt-8 gap-4 sm:flex-row sm:items-center sm:justify-center sm:flex-wrap">
{linksData.map((linkData, index) => (
<a
data-testid={`NewbiesExternalLink-${linkData.icon}`}
key={index}
href={linkData.link}
target="_blank"
Expand Down
2 changes: 1 addition & 1 deletion components/Projects/FiltersBar/FiltersBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import FilterTagBtn from './FilterTagBtn';
import useFocusTrap from '@/components/hooks/useFocusTrap';
import { ProjectFilter } from '@/types';
import Link from 'next/link';
import { SearchInput } from '@/components/Common/inputs/SearchInput';
import { ProjectPaginationFilter } from '@/types/project';
import { useTranslations } from 'next-intl';
import { SearchInput } from '@/components/Common/Inputs/SearchInput';

interface FiltersBarProps {
filters: ProjectFilter[];
Expand Down
1 change: 1 addition & 0 deletions components/utils/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export const Dropdown = <T extends OptionValue>({
{options.map(item =>
item.linkPath ? (
<Link
data-testId={item.title}
href={item.linkPath}
onClick={toggleDropdown}
onKeyUp={e => (e.key === 'Escape' ? toggleDropdown() : null)}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"check-lint": "eslint . --ext ts --ext tsx --ext js",
"format": "npx prettier --write . --config ./.prettierrc",
"prepare": "husky install",
"test": "npx playwright test",
"test": "npx playwright test --ui",
"test-result": "npx playwright show-report"
},
"lint-staged": {
Expand Down
77 changes: 77 additions & 0 deletions tests/newbiesPage.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { test, expect } from '@playwright/test';

const BASE_URL = 'http://localhost:3000/he';

test.describe('Test Newbies page', () => {
test('should navigate to the Newbies page', async ({ page }) => {
await page.goto(BASE_URL);
await page.click('text="קהילה"');
await page.click('[data-testid="Newbies"]');

await page.waitForNavigation();

const pageTitle = await page.title();
expect(pageTitle).toContain('Newbies');
});

test('should render NEWBIES', async ({ page }) => {
await page.goto(`${BASE_URL}/newbies`);
expect(await page.textContent('h1')).toContain('NEWBIES');
});

test('External links contain correct URLs', async ({ page }) => {
await page.goto(`${BASE_URL}/newbies`);

const linksData = [
{
name: 'Maakaf_Logo',
link: 'https://github.com/UrielOfir/os-practice',
},
{
name: 'Discord_Logo',
link: 'https://discord.com/invite/a2VyCjRk2M',
},
{
name: 'WhatsApp_Logo',
link: 'https://chat.whatsapp.com/E5a59DtSaHNBwnczxVW1FY',
},
];

for (const linkData of linksData) {
const linkSelector = `[data-testid="NewbiesExternalLink-${linkData.name}"]`;
const linkExists = await page.waitForSelector(linkSelector);
expect(linkExists).toBeTruthy();

const linkElement = await page.$(linkSelector);
const linkURL = await linkElement?.getAttribute('href');
expect(linkURL).toBe(linkData.link);
}
});

test('FAQ items are clickable and expandable', async ({ page }) => {
await page.goto(`${BASE_URL}/newbies`);
await page.waitForSelector('[data-testid="faq-section"]');

const faqItems = await page.$$('[data-testid^="faq-item-"]');

for (let i = 0; i < faqItems.length; i++) {
const faqItem = faqItems[i];

const trigger = await faqItem.$('[data-testid^="faq-trigger-"]');
await trigger?.click();

await page.waitForSelector(
'[data-testid^="faq-content-"][aria-expanded="true"]'
);

const content = await faqItem.$('[data-testid^="faq-content-"]');
expect(content).not.toBeNull();

await trigger?.click();

await page.waitForSelector(
'[data-testid^="faq-content-"][aria-expanded="false"]'
);
}
});
});
Loading