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

Testing #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"plugins": ["react", "prettier"],
"rules": {
"prettier/prettier": "error",
"prettier/prettier": ["error", { "endOfLine": "auto" }],
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"react/prop-types": 0
}
Expand Down
9 changes: 7 additions & 2 deletions src/hackathons-collector/logic-components/listing-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const ListingItem = ({
return (
<Entry>
<article style={customStyles}>
<div className="tags">
<div className="tags" data-testid="tags-element">
<span className="city">@{location}</span>
{tags.map((tag) => (
<span key={tag}>#{tag}</span>
Expand All @@ -42,7 +42,12 @@ const ListingItem = ({
{disabled ? (
''
) : (
<a target="_blank" rel="noopener noreferrer" href={url}>
<a
target="_blank"
rel="noopener noreferrer"
href={url}
data-testid="url-element"
>
website
</a>
)}
Expand Down
35 changes: 34 additions & 1 deletion src/hackathons-collector/logic-components/listing-item.test.js
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
test.todo('test');
import React from 'react';
import { render, screen } from '@testing-library/react';
// import userEvent from '@testing-library/user-event';
Copy link
Collaborator

@roertbb roertbb Feb 25, 2021

Choose a reason for hiding this comment

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

if unused - can be removed? 😉

import moment from 'moment';
import 'moment/locale/en-gb';
Copy link
Collaborator

@roertbb roertbb Feb 25, 2021

Choose a reason for hiding this comment

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

we don't need that actually here actually, it would be worth it to do that in setupTests to make it work for all tests

import ListingItem from './listing-item';

const event = {
date: '25.03.2021',
Copy link
Collaborator

@roertbb roertbb Feb 25, 2021

Choose a reason for hiding this comment

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

new Date(2021, 2, 25) would be more suitable to match events coming from events.js

title: 'hackathon',
tags: ['hello', 'js'],
location: 'Poznan',
description: 'pierwszy w 2021',
url: 'https://reactywny.pl',
};

test('check ListingItem component render', () => {
render(<ListingItem event={event} />);

expect(screen.getByText(`@${event.location}`)).toBeInTheDocument();
expect(screen.getByText(event.title)).toBeInTheDocument();
expect(screen.getByText(event.description)).toBeInTheDocument();
expect(
screen.getByText(moment(event.date).format('dddd'))
).toBeInTheDocument();
});

test('check tag array render', () => {
render(<ListingItem event={event} />);

event.tags.forEach((tag) => {
expect(screen.getByText(`#${tag}`)).toBeInTheDocument();
});
});