e poter gestire lo stato con redux
+import { render } from '../../../util/test-utils';
+import '@testing-library/jest-dom';
+import userEvent from '@testing-library/user-event';
+
+import NavBar from '../NavBar';
+import searchBarReducer, { setSearchBar } from "../../../features/SearchBar/searchBarSlice";
+
+describe('NavBar component', () => {
+ test('Logo is an active link to homepage', () => {
+ render();
+ //screen.debug();
+ const linkHome = screen.getByLabelText('Pagina iniziale');
+ expect(linkHome).toBeVisible();
+ expect(linkHome).toBeEnabled();
+ });
+
+ test('Search input value', () => {
+ render();
+
+ const searchBox = screen.getByPlaceholderText('Cerca su Reddit');
+ expect(searchBox).toBeInTheDocument();
+ expect(searchBox).toHaveDisplayValue('');
+ expect(searchBarReducer(undefined, {})).toEqual({searchTerm: ''});
+
+ userEvent.type(searchBox, 'cow');
+ expect(searchBox).toHaveValue('cow');
+ expect(searchBarReducer({searchTerm: ''}, setSearchBar('cow'))).toEqual({searchTerm: 'cow'});
+ });
+
+ test('button search', () => {
+ render();
+
+ const buttonSearch = screen.getByRole('button');
+ const aSearch = screen.getByText(/Search/);
+ expect(buttonSearch).toBeInTheDocument();
+ expect(buttonSearch).toBeEnabled();
+ expect(buttonSearch).toContainElement(aSearch);
+
+ });
+});
\ No newline at end of file
diff --git a/reddit-client/src/Components/Subreddit/Subreddit.js b/reddit-client/src/Components/Subreddit/Subreddit.js
index 2e40e1c..33a0405 100644
--- a/reddit-client/src/Components/Subreddit/Subreddit.js
+++ b/reddit-client/src/Components/Subreddit/Subreddit.js
@@ -19,10 +19,10 @@ export function Subreddit ({subreddit}) {
{icon !== "" ?

- :
r/
+ :
r/
}
- r/{name || 'non trovato'}
+ r/{name}
);
}
\ No newline at end of file
diff --git a/reddit-client/src/Components/Subreddit/__tests__/Subreddit.test.js b/reddit-client/src/Components/Subreddit/__tests__/Subreddit.test.js
new file mode 100644
index 0000000..1d92d56
--- /dev/null
+++ b/reddit-client/src/Components/Subreddit/__tests__/Subreddit.test.js
@@ -0,0 +1,51 @@
+import React from "react";
+import { screen } from '@testing-library/react';
+
+//funzione render personalizzata per includere e poter gestire lo stato con redux
+import { render } from '../../../util/test-utils';
+import '@testing-library/jest-dom';
+import userEvent from '@testing-library/user-event';
+
+import {Subreddit} from '../Subreddit';
+
+describe('Subreddit component', () => {
+ const initialState = {
+ name: "sports",
+ headerImg: "https://a.thumbs.redditmedia.com/OG0cMFwrTOQE6Gj5xW2pwTMpjkegILNnJEzHZukZTW4.png",
+ title: "Reddit Sports",
+ color: "#ff4500",
+ icon: "https://b.thumbs.redditmedia.com/V3oOhkQE_SiCz2dvI2uA7TlbcfvaIMPw2AQjtIdqMUk.png",
+ id: "2qgzy"
+ }
+
+ test('Render with prop', () => {
+ render();
+ //screen.debug();
+ const imgIcon = screen.getByRole('img');
+ expect(imgIcon).toBeInTheDocument();
+ expect(imgIcon).toHaveAttribute('src', expect.stringContaining(initialState.icon));
+ expect(imgIcon).toBeVisible();
+ });
+
+ test('Render without prop', () => {
+ render();
+ //screen.debug();
+ const imgIcon = screen.queryByRole('img');
+ expect(imgIcon).toBeNull();
+
+ const subNameP = screen.getByText('r/example title');
+ expect(subNameP).toBeInTheDocument();
+ });
+
+ test('Render with prop and empty icon', () => {
+ initialState.icon = '';
+ render();
+ //screen.debug();
+ const imgIcon = screen.queryByRole('img');
+ expect(imgIcon).toBeNull();
+
+ const rIcon = screen.getByTestId('emptyIcon');
+ expect(rIcon).toBeInTheDocument();
+ });
+
+});
\ No newline at end of file
diff --git a/reddit-client/src/features/SectionSubreddits/SectionSubreddits.js b/reddit-client/src/features/SectionSubreddits/SectionSubreddits.js
index 536e6d7..21daf19 100644
--- a/reddit-client/src/features/SectionSubreddits/SectionSubreddits.js
+++ b/reddit-client/src/features/SectionSubreddits/SectionSubreddits.js
@@ -32,16 +32,16 @@ export default function SectionSubreddits() {
return (
-