Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 20e8969

Browse files
test: update testcases
1 parent a3f9739 commit 20e8969

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

src/components/Footer/__tests__/Footer.test.tsx

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import '@testing-library/jest-dom';
33
import { cleanup, render, screen, RenderResult, within } from '@site/src/test-utils';
44
import Footer from '../';
5+
import userEvent from '@testing-library/user-event';
56

67
describe('HeroHeader', () => {
78
let render_result: RenderResult;
@@ -25,27 +26,23 @@ describe('HeroHeader', () => {
2526
);
2627
expect(footer_description).toBeInTheDocument();
2728
});
28-
it('should render community link properly', () => {
29-
const community_link = screen.getByTestId('community-link');
30-
expect(community_link).toBeInTheDocument();
31-
expect(community_link).toHaveAttribute('href', 'https://deriv.vanillacommunity.com/');
32-
});
33-
it('should render the button inside community link properly', () => {
34-
const community_link = screen.getByTestId('community-link');
35-
const { getByRole } = within(community_link);
36-
const button = getByRole('button');
37-
expect(button).toHaveTextContent('Join our community');
38-
});
39-
it('should render telegram link properly', () => {
40-
const telegram_link = screen.getByTestId('telegram-link');
41-
expect(telegram_link).toBeInTheDocument();
42-
expect(telegram_link).toHaveAttribute('href', 'https://t.me/+g6FV5tFY1u9lZGE1');
43-
});
44-
it('should render the button inside telegram link properly', () => {
45-
const telegram_link = screen.getByTestId('telegram-link');
46-
const { getByRole } = within(telegram_link);
47-
const button = getByRole('button');
48-
expect(button).toHaveTextContent('Telegram');
29+
it('should render community link when community button is clicked', async () => {
30+
window.open = jest.fn();
31+
32+
const communityButton = screen.getByRole('button', { name: 'Join our community' });
33+
expect(communityButton).toBeInTheDocument();
34+
await userEvent.click(communityButton);
35+
36+
expect(window.open).toHaveBeenCalledWith('https://deriv.vanillacommunity.com/');
37+
});
38+
it('should render telegram link when telegram button is clicked', async () => {
39+
window.open = jest.fn();
40+
41+
const telegramButton = screen.getByRole('button', { name: 'Telegram' });
42+
expect(telegramButton).toBeInTheDocument();
43+
await userEvent.click(telegramButton);
44+
45+
expect(window.open).toHaveBeenCalledWith('https://t.me/+g6FV5tFY1u9lZGE1');
4946
});
5047
it('should render footer body texts properly', () => {
5148
const help_text = screen.getByText(/^we're here to help$/i);

src/components/Footer/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ const Footer = () => {
1616
<button
1717
className={styles.communityButton}
1818
onClick={() => window.open('https://deriv.vanillacommunity.com/')}
19-
data-testid='community-link'
2019
>
2120
Join our community
2221
</button>
2322
<button
2423
className={styles.communityButton}
2524
onClick={() => window.open('https://t.me/+g6FV5tFY1u9lZGE1')}
26-
data-testid='telegram-link'
2725
>
2826
<div className={styles.Telegram}>
2927
<img src='/img/telegram.svg' className={styles.TelegramIcon} />

0 commit comments

Comments
 (0)