generated from RealDevSquad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 167
Improve Dashboard Page of Status Site #636
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cb24a5d
format code for better responsive design
RitikJaiswal75 e6b4410
add disabled property to search button
RitikJaiswal75 883ae79
fix failing tests for searchbar component
RitikJaiswal75 e903072
add cursor pointer for buttons
RitikJaiswal75 fcef85b
add spacing in non-large desktop view
RitikJaiswal75 ecb40b8
use the disabled sudo selector
RitikJaiswal75 3a44c94
fix the search function being called on blank input and enter key press
RitikJaiswal75 bc762c5
use getByRole instead of test id in testing the components
RitikJaiswal75 608f7e3
add jest spy on the splitNSearch function to properly test it
RitikJaiswal75 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import Searchbar from '@/components/Dashboard/Searchbar'; | ||
| import * as util from '@/utils/splitNSearch'; | ||
| import { fireEvent, render, screen } from '@testing-library/react'; | ||
|
|
||
| describe('test searchbar component', function () { | ||
| beforeEach(() => { | ||
| jest.spyOn(util, 'splitNSearch'); | ||
| }); | ||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
| it('renders searchbar input and a search button', function () { | ||
| render(<Searchbar label="test-label" />); | ||
|
|
||
| const input = screen.getByRole('textbox') as HTMLInputElement; | ||
| const searchBtn = screen.getByRole('button', { | ||
| name: 'Search', | ||
| }) as HTMLButtonElement; | ||
|
|
||
| expect(input).toBeInTheDocument(); | ||
| expect(input).toHaveAttribute('placeholder', 'test-label:'); | ||
| expect(searchBtn).toBeInTheDocument(); | ||
| expect(searchBtn).toHaveTextContent('Search'); | ||
| }); | ||
|
|
||
| it('checks if we can type into the searchbar', function () { | ||
| render(<Searchbar label="test-label" />); | ||
|
|
||
| const input = screen.getByPlaceholderText( | ||
| 'test-label:' | ||
| ) as HTMLInputElement; | ||
|
|
||
| fireEvent.change(input, { target: { value: '123,456' } }); | ||
| expect(input.value).toBe('123,456'); | ||
| }); | ||
|
|
||
| it('tests if the click handler is called', function () { | ||
| render(<Searchbar label="test-label" />); | ||
|
|
||
| const input = screen.getByPlaceholderText( | ||
| 'test-label:' | ||
| ) as HTMLInputElement; | ||
|
|
||
| const searchBtn = screen.getByRole('button', { | ||
| name: 'Search', | ||
| }) as HTMLButtonElement; | ||
|
|
||
| fireEvent.change(input, { target: { value: '123' } }); | ||
| fireEvent.click(searchBtn); | ||
|
|
||
| expect(util.splitNSearch).toBeCalledTimes(1); | ||
| }); | ||
|
|
||
| it('tests if enter key calls search', function () { | ||
| render(<Searchbar label="test-label" />); | ||
|
|
||
| const input = screen.getByPlaceholderText( | ||
| 'test-label:' | ||
| ) as HTMLInputElement; | ||
|
|
||
| fireEvent.change(input, { target: { value: '123' } }); | ||
| fireEvent.keyDown(input, { key: 'Enter', code: 'Enter', charCode: 13 }); | ||
|
|
||
| expect(util.splitNSearch).toBeCalledTimes(1); | ||
| }); | ||
|
|
||
| it('tests other key down events do not call search', function () { | ||
| render(<Searchbar label="test-label" />); | ||
|
|
||
| const input = screen.getByPlaceholderText( | ||
| 'test-label:' | ||
| ) as HTMLInputElement; | ||
|
|
||
| fireEvent.keyDown(input, { key: 'A', code: 'KeyA' }); | ||
|
|
||
| expect(util.splitNSearch).toBeCalledTimes(0); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import DashboardPage from '@/pages/dashboard'; | ||
| import { renderWithRouter } from '@/test_utils/createMockRouter'; | ||
| import { Provider } from 'react-redux'; | ||
| import { store } from '@/app/store'; | ||
| import { fireEvent, screen } from '@testing-library/react'; | ||
|
|
||
| describe('dashboard page test', function () { | ||
| it('checks if the page is rendered with exact components', function () { | ||
| renderWithRouter( | ||
| <Provider store={store()}> | ||
| <DashboardPage /> | ||
| </Provider>, | ||
| { query: { dev: 'true' } } | ||
| ); | ||
|
|
||
| const searchBar = screen.getByRole('textbox'); | ||
| expect(searchBar).toBeInTheDocument(); | ||
|
|
||
| const searchBtn = screen.getByRole('button', { | ||
| name: 'Search', | ||
| }) as HTMLButtonElement; | ||
| expect(searchBtn).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders 404 without passing the feature flag', function () { | ||
| renderWithRouter( | ||
| <Provider store={store()}> | ||
| <DashboardPage /> | ||
| </Provider> | ||
| ); | ||
|
|
||
| const headings = screen.getAllByRole('heading'); | ||
| expect(headings).toHaveLength(1); | ||
| expect(headings[0].innerHTML).toBe('404 - Page Not Found'); | ||
| }); | ||
|
|
||
| it('console logs the value', function () { | ||
| console.log = jest.fn(); | ||
RitikJaiswal75 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| renderWithRouter( | ||
| <Provider store={store()}> | ||
| <DashboardPage /> | ||
| </Provider>, | ||
| { query: { dev: 'true' } } | ||
| ); | ||
|
|
||
| const input = screen.getByRole('textbox') as HTMLInputElement; | ||
| fireEvent.change(input, { target: { value: 'jhon, doe' } }); | ||
|
|
||
| const searchBtn = screen.getByRole('button', { | ||
| name: 'Search', | ||
| }) as HTMLButtonElement; | ||
| fireEvent.click(searchBtn); | ||
|
|
||
| const value = input.value.split(','); | ||
| expect(console.log).toBeCalledWith('Searching', value); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +1,52 @@ | ||
| $base-unit: 4px; | ||
| $base-font-size: 0.3rem; | ||
| $color-blue: #041187; | ||
| $color-red: #e30062; | ||
| $color-green: #85da6b; | ||
| $color-disabled: #e5e7eb; | ||
| $color-disabled: #7c7e82; | ||
| $color-white: #fff; | ||
| $color-black: #000; | ||
| $diff-margin: $base-unit * 15; | ||
| $similar-margin: $base-unit * 8; | ||
| $section-padding-top-bottom: $base-unit * 30; | ||
| $section-padding-left-right: $base-unit * 25; | ||
|
|
||
| .container { | ||
| margin: $diff-margin auto; | ||
| width: 85%; | ||
| } | ||
|
|
||
| .searchLabel { | ||
| font-size: $base-font-size * 5; | ||
| padding-right: $base-unit * 8; | ||
| color: $color-blue; | ||
| margin: 40px auto; | ||
| width: 95%; | ||
| display: flex; | ||
| justify-content: center; | ||
| line-height: 2rem; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .searchBar { | ||
RitikJaiswal75 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| background-color: $color-disabled; | ||
| border-radius: $base-unit * 2; | ||
| border: none; | ||
| width: 80%; | ||
| height: $base-unit * 15; | ||
| font-size: $base-font-size * 5; | ||
| width: 600px; | ||
| font-family: sans-serif; | ||
| margin-right: 8px; | ||
| border-radius: 4px; | ||
| font-size: 1.2rem; | ||
| padding: 0.5rem; | ||
| } | ||
|
|
||
| .searchBtn { | ||
| margin-left: $base-unit * 8; | ||
| .btn { | ||
| background-color: $color-blue; | ||
| border-radius: 4px; | ||
| color: white; | ||
| background-color: $color-blue; | ||
| color: $color-white; | ||
| height: $base-unit * 15; | ||
| border-radius: $base-unit * 2; | ||
| border: none; | ||
| width: $base-unit * 40; | ||
| padding: 12px 60px; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| .btn:disabled { | ||
| color: white; | ||
| background-color: $color-disabled; | ||
| cursor: not-allowed; | ||
| } | ||
|
|
||
| @media only screen and (max-width: 520px) { | ||
| .container { | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| } | ||
| .searchBar { | ||
| width: 95%; | ||
bharati-21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| margin: 4px; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.