From ce4a18899f24ba89b63ef743476ec0dbf1999ecf Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Fri, 3 Nov 2023 23:03:06 +0100
Subject: refactor(components): rewrite SearchForm component

* remove searchPage prop (the consumer should handle the submit)
* change onSubmit type
* use `useForm` hook to handle the form
---
 .../organisms/layout/posts-list.test.tsx           | 36 ++++++----------------
 1 file changed, 10 insertions(+), 26 deletions(-)

(limited to 'src/components/organisms/layout/posts-list.test.tsx')

diff --git a/src/components/organisms/layout/posts-list.test.tsx b/src/components/organisms/layout/posts-list.test.tsx
index d5273fc..fabf31f 100644
--- a/src/components/organisms/layout/posts-list.test.tsx
+++ b/src/components/organisms/layout/posts-list.test.tsx
@@ -1,47 +1,31 @@
 import { describe, expect, it } from '@jest/globals';
-import { render, screen } from '../../../../tests/utils';
+import { render, screen as rtlScreen } from '../../../../tests/utils';
 import { PostsList } from './posts-list';
-import { posts, searchPage } from './posts-list.fixture';
+import { posts } from './posts-list.fixture';
 
 describe('PostsList', () => {
   it('renders the correct number of posts', () => {
-    render(
-      <PostsList posts={posts} total={posts.length} searchPage={searchPage} />
-    );
-    expect(screen.getAllByRole('article')).toHaveLength(posts.length);
+    render(<PostsList posts={posts} total={posts.length} />);
+    expect(rtlScreen.getAllByRole('article')).toHaveLength(posts.length);
   });
 
   it('renders the number of loaded posts', () => {
-    render(
-      <PostsList posts={posts} total={posts.length} searchPage={searchPage} />
-    );
+    render(<PostsList posts={posts} total={posts.length} />);
     const info = `${posts.length} loaded articles out of a total of ${posts.length}`;
-    expect(screen.getByText(info)).toBeInTheDocument();
+    expect(rtlScreen.getByText(info)).toBeInTheDocument();
   });
 
   it('renders a load more button', () => {
     render(
-      <PostsList
-        posts={posts}
-        total={posts.length}
-        showLoadMoreBtn={true}
-        searchPage={searchPage}
-      />
+      <PostsList posts={posts} total={posts.length} showLoadMoreBtn={true} />
     );
     expect(
-      screen.getByRole('button', { name: /Load more/i })
+      rtlScreen.getByRole('button', { name: /Load more/i })
     ).toBeInTheDocument();
   });
 
   it('renders a search form if no results', () => {
-    render(
-      <PostsList
-        posts={[]}
-        total={0}
-        showLoadMoreBtn={true}
-        searchPage={searchPage}
-      />
-    );
-    expect(screen.getByRole('searchbox')).toBeInTheDocument();
+    render(<PostsList posts={[]} total={0} showLoadMoreBtn={true} />);
+    expect(rtlScreen.getByRole('searchbox')).toBeInTheDocument();
   });
 });
-- 
cgit v1.2.3

