Skip to content

Commit

Permalink
removed class name from several common cmponents
Browse files Browse the repository at this point in the history
  • Loading branch information
Blockchain-Country committed Dec 25, 2024
1 parent d8c5509 commit fcc5938
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import FilterSection from './components/filterSection/FilterSection'
import ManualAddBookSection from './components/manualAddBookSection/ManualAddBookSection'
import SearchBookSection from './components/searchBookSection/SearchBookSection'
import RandomBookSection from './components/randomBookSection/RandomBookSection'
import BookListSection from './components/BookListSection/BookListSection'
import BookListSection from './components/bookListSection/BookListSection'
import Header from './components/header/Header'
import Login from './components/user/login/Login'
import Signup from './components/user/signup/Signup'
Expand Down
24 changes: 18 additions & 6 deletions src/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,26 @@ describe('App functional Tests', () => {
})

// ManualAddBookSection form elements:
titleInput = screen.getByTestId('manualAddBook_input_title')
authorsInput = screen.getByTestId('manualAddBook_input_author')
submitBookBtn = screen.getByTestId('manualAddBook_submit_btn')
titleInput = screen.getByTestId((id) =>
id.includes('manualAddBook_input_title')
)
authorsInput = screen.getByTestId((id) =>
id.includes('manualAddBook_input_author')
)
submitBookBtn = screen.getByTestId((id) =>
id.includes('manualAddBook_submit_btn')
)
bookListSection_component = screen.getByTestId('bookList_section')
// FilterSection elements:
filterByTitleInput = screen.getByTestId('filter_title_input')
filterbyAuthorsInput = screen.getByTestId('filter_author_input')
clearAllFiltersBtn = screen.getByTestId('filter_clear_btn')
filterByTitleInput = screen.getByTestId((id) =>
id.includes('filter_title_input')
)
filterbyAuthorsInput = screen.getByTestId((id) =>
id.includes('filter_author_input')
)
clearAllFiltersBtn = screen.getByTestId((id) =>
id.includes('filter_clear_btn')
)
})

afterEach(() => {
Expand Down
26 changes: 19 additions & 7 deletions src/components/BookListSection/BookListSection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ describe('BookList Component Tests', () => {
const bookItems = within(container).getByTestId(
`bookList_item id=${bookId}`
)
const deleteBookBtn = within(bookItems).getByTestId('delete_book_btn')
const deleteBookBtn = within(bookItems).getByTestId((id) =>
id.includes('delete_book_btn')
)
expect(deleteBookBtn).toBeInTheDocument()

fireEvent.click(deleteBookBtn)
Expand All @@ -87,25 +89,35 @@ describe('BookList Component Tests', () => {
const { container } = setup(BookListSection, mockedStore)

const bookItem = within(container).getByTestId(`bookList_item id=${bookId}`)
const favoriteToggle = within(bookItem).getByTestId(
'book_favorite_toggle_false'
const favoriteToggle = within(bookItem).getByTestId((id) =>
id.includes('book_favorite_toggle_false')
)

// Toggle favorite on
fireEvent.click(favoriteToggle)
expect(
within(bookItem).getByTestId('book_favorite_toggle_true')
within(bookItem).getByTestId((id) =>
id.includes('book_favorite_toggle_true')
)
).toBeInTheDocument()

// Try deleting the book
const deleteBookBtn = within(bookItem).getByTestId('delete_book_btn')
const deleteBookBtn = within(bookItem).getByTestId((id) =>
id.includes('delete_book_btn')
)
fireEvent.click(deleteBookBtn)
expect(bookItem).toBeInTheDocument()

// Untoggle favorite
fireEvent.click(within(bookItem).getByTestId('book_favorite_toggle_true'))
fireEvent.click(
within(bookItem).getByTestId((id) =>
id.includes('book_favorite_toggle_true')
)
)
expect(
within(bookItem).getByTestId('book_favorite_toggle_false')
within(bookItem).getByTestId((id) =>
id.includes('book_favorite_toggle_false')
)
).toBeInTheDocument()

// Delete book
Expand Down
10 changes: 5 additions & 5 deletions src/components/BookListSection/book/Book.css
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ div[data-testid='book_actions'] {
gap: 0.5rem;
}

button[data-testid^='book_favorite_toggle_'] {
button[data-testid*='book_favorite_toggle_'] {
min-width: 0;
height: 3.5rem;
width: 3.5rem;
Expand All @@ -93,8 +93,8 @@ button[data-testid^='book_favorite_toggle_'] {
transition: background-color 0.3s ease;
}

button[data-testid='book_favorite_toggle_false']:hover,
button[data-testid='book_favorite_toggle_true']:hover {
button[data-testid*='book_favorite_toggle_false']:hover,
button[data-testid*='book_favorite_toggle_true']:hover {
background-color: #f6dbabfd;
}

Expand All @@ -114,14 +114,14 @@ button[data-testid='book_favorite_toggle_true']:hover {
}

/* Delete Button */
button[data-testid='delete_book_btn'] {
button[data-testid*='delete_book_btn'] {
margin: 0;
margin-right: 0.5rem;
background-color: #fff;
color: red;
border: 1px solid red;
}

button[data-testid='delete_book_btn']:hover {
button[data-testid*='delete_book_btn']:hover {
background-color: rgb(255, 204, 204);
}
13 changes: 6 additions & 7 deletions src/components/BookListSection/bookListModal/BookListModal.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,18 @@ div[data-testid='bookListModal_actions_wrapper'] {
}

/* Favorite Toggle Button */
button[data-testid^='bookListModal_favorite_toggle_'] {
button[data-testid*='bookListModal_favorite_toggle_'] {
min-width: 0;
height: 3.5rem;
width: 3.5rem;
padding: 0;
margin: 0;
border: 1px solid #fca510;
background-color: #fff;
/* transition: background-color 0.2s, transform 0.3s ease; */
}

button[data-testid^='bookListModal_favorite_toggle_false']:hover,
button[data-testid^='bookListModal_favorite_toggle_true']:hover {
button[data-testid*='bookListModal_favorite_toggle_false']:hover,
button[data-testid*='bookListModal_favorite_toggle_true']:hover {
background-color: #f6dbab;
}

Expand All @@ -92,18 +91,18 @@ button[data-testid^='bookListModal_favorite_toggle_true']:hover {
color: #e69303;
}

button[data-testid='bookListModal_delete_btn'] {
button[data-testid*='bookListModal_delete_btn'] {
margin: 0;
background-color: #fff;
color: red;
border: 1px solid red;
}

button[data-testid='bookListModal_delete_btn']:hover {
button[data-testid*='bookListModal_delete_btn']:hover {
background-color: rgb(255, 204, 204);
}

button[data-testid='bookListModal_delete_btn']:disabled {
button[data-testid*='bookListModal_delete_btn']:disabled {
border: 1px solid darkgray;
color: fff;
background-color: darkgray;
Expand Down
24 changes: 12 additions & 12 deletions src/components/common/button/Button.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.componentButton {
button[data-testid^='componentButton'] {
display: flex;
align-items: center;
justify-content: center;
Expand All @@ -15,32 +15,32 @@
box-shadow 0.1s ease;
}

.componentButton:hover {
button[data-testid^='componentButton']:hover {
transform: scale(1.03);
background-color: #0056b3;
}

span[data-testid='button_text'] {
transition: transform 0.2s ease;
}

span[data-testid='button_text']:hover {
transform: scale(1.05);
}

.componentButton:active {
button[data-testid^='componentButton']:active {
background-color: #016adb;
transform: scale(0.95);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.componentButton:disabled {
button[data-testid^='componentButton']:disabled {
background-color: darkgray;
border: 1px solid darkgray;
color: #fff;
cursor: not-allowed;
}

span[data-testid='button_text'] {
transition: transform 0.2s ease;
}

span[data-testid='button_text']:hover {
transform: scale(1.05);
}

[data-testid='search_spinner'] {
font-size: 1.5rem;
animation: spinner 1s infinite linear;
Expand Down
4 changes: 1 addition & 3 deletions src/components/common/button/Button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ const Button = ({
isLoading = false,
children,
'data-testid': testId,
className = '',
}) => {
return (
<button
type={type}
onClick={onClick}
className="componentButton"
data-testid={testId}
data-testid={`componentButton ${testId}`}
disabled={disabled}
aria-busy={isLoading}
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/input/Input.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.component_input {
input[data-testid^='component_input'] {
width: 90%;
padding: 0.5rem 1rem;
border: 1px solid #ccc;
Expand Down
3 changes: 1 addition & 2 deletions src/components/common/input/Input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ const Input = ({
value={value}
onChange={onChange}
disabled={disabled}
className="component_input"
data-testid={testId}
data-testid={`component_input ${testId}`}
></input>
</>
)
Expand Down
1 change: 0 additions & 1 deletion src/components/common/modal/Modal.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ div[data-testid='modal_component'] {
display: flex;
flex-direction: column;
width: 80%;
/* min-height: 60%; */
max-height: 90%;
background-color: #f2f2f2;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
Expand Down
12 changes: 9 additions & 3 deletions src/components/filterSection/FilterSection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ describe('FilterSection Component Tests', () => {
})

// FilterSection elements:
filterByTitleInput = screen.getByTestId('filter_title_input')
filterbyAuthorsInput = screen.getByTestId('filter_author_input')
clearAllFiltersBtn = screen.getByTestId('filter_clear_btn')
filterByTitleInput = screen.getByTestId((id) =>
id.includes('filter_title_input')
)
filterbyAuthorsInput = screen.getByTestId((id) =>
id.includes('filter_author_input')
)
clearAllFiltersBtn = screen.getByTestId((id) =>
id.includes('filter_clear_btn')
)
})

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ form[data-testid='manualAddBook_form'] {
padding: 1rem;
}

div[data-testid='manualAddBook_inputs_wrapper'] {
div[data-testid*='manualAddBook_inputs_wrapper'] {
display: flex;
flex-direction: column;
align-items: center;
Expand Down
12 changes: 9 additions & 3 deletions src/components/manualAddBookSection/ManualAddBookSection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ describe('ManualAddBookSection Component Tests', () => {
})

// ManualAddBookSection elements:
titleInput = screen.getByTestId('manualAddBook_input_title')
authorsInput = screen.getByTestId('manualAddBook_input_author')
submitBookBtn = screen.getByTestId('manualAddBook_submit_btn')
titleInput = screen.getByTestId((id) =>
id.includes('manualAddBook_input_title')
)
authorsInput = screen.getByTestId((id) =>
id.includes('manualAddBook_input_author')
)
submitBookBtn = screen.getByTestId((id) =>
id.includes('manualAddBook_submit_btn')
)
bookListComponent = screen.getByTestId('bookList_section')
})

Expand Down
2 changes: 1 addition & 1 deletion src/components/searchBookSection/SearchBookSection.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ form[data-testid='search_form'] {
padding: 1rem;
}

div[data-testid='search_input_wrapper'] {
div[data-testid*='search_input_wrapper'] {
display: flex;
flex-direction: column;
align-items: center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ div[data-testid='modal_add_book_wrapper'] {
justify-content: flex-start;
}

button[data-testid='modal_add_book_btn'] {
button[data-testid*='modal_add_book_btn'] {
margin: 0;
}

0 comments on commit fcc5938

Please sign in to comment.