-
Notifications
You must be signed in to change notification settings - Fork 3
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
#276 implement first tests to fe #283
Changes from all commits
aa78790
a62c5d6
8076d72
f1c8e8d
c16050c
0ccda30
18b67d5
ed9fd7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,3 +163,5 @@ export function Search({ isAuthorized }) { | |
</div> | ||
); | ||
} | ||
|
||
export default Search; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
|
||
import CompanyCard from '../components/SearchPage/search_field/companies/CompanyCard'; | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
const company = { | ||
id: 1, | ||
name: 'Testname', | ||
categories: [1, 2], | ||
region: 'Testregion', | ||
founded: 2005, | ||
service_info: 'Testinfo', | ||
address: 'Testadress', | ||
banner_image: '', | ||
}; | ||
|
||
describe('CompanyCard component unit tests', () => { | ||
test('renders years of experiense', () => { | ||
render( | ||
<MemoryRouter> | ||
<CompanyCard isAuthorized={{ isAuth: true }} companyData={company} /> | ||
</MemoryRouter> | ||
); | ||
const divElement = screen.getByText(/18 років досвіду/i, { exact: false }); | ||
expect(divElement).toBeInTheDocument(); | ||
}); | ||
|
||
test('testing stars', () => { | ||
jest.mock('axios'); | ||
const axios = require('axios'); | ||
|
||
() => { | ||
axios.get.mockResolvedValue({ | ||
results: [ | ||
{ | ||
id: 1, | ||
name: 'Testname', | ||
founded: 2005, | ||
service_info: 'Testinfo', | ||
person: 3, | ||
is_registered: true, | ||
is_startup: false, | ||
official_name: null, | ||
region: 'Testregion', | ||
region_display: 'Testregion', | ||
common_info: null, | ||
address: 'Testadress', | ||
categories: [1, 2], | ||
activities: [], | ||
banner_image: null, | ||
is_saved: true, | ||
}, | ||
], | ||
}); | ||
}; | ||
|
||
() => { | ||
axios.post.mockResolvedValue({ | ||
company_pk: 1, | ||
}); | ||
|
||
render( | ||
<MemoryRouter> | ||
<CompanyCard isAuthorized={{ isAuth: true }} companyData={company} /> | ||
</MemoryRouter> | ||
); | ||
expect(screen.getByTestId('star')).toBeInTheDocument(); | ||
expect(axios.post).toBeenCalledWith( | ||
'http://localhost:8000/api/saved-list/', | ||
{ company_pk: 1 } | ||
); | ||
expect(axios.get).toHaveBeenCalledWith( | ||
'http://localhost:8000/api/profiles/?is_saved=True' | ||
); | ||
}; | ||
}); | ||
|
||
test('testing empty stars', () => { | ||
jest.mock('axios'); | ||
const axios = require('axios'); | ||
|
||
() => { | ||
axios.get.mockResolvedValue({ | ||
results: [ | ||
{ | ||
id: 2, | ||
name: 'Test', | ||
founded: 2000, | ||
service_info: 'info', | ||
person: 4, | ||
is_registered: true, | ||
is_startup: false, | ||
official_name: null, | ||
region: 'Testregion', | ||
region_display: 'Testregion', | ||
common_info: null, | ||
address: 'adress', | ||
categories: [2], | ||
activities: [], | ||
banner_image: null, | ||
is_saved: true, | ||
}, | ||
], | ||
}); | ||
}; | ||
|
||
() => { | ||
axios.post.mockResolvedValue({ | ||
company_pk: 1, | ||
}); | ||
|
||
render( | ||
<MemoryRouter> | ||
<CompanyCard isAuthorized={{ isAuth: true }} companyData={company} /> | ||
</MemoryRouter> | ||
); | ||
expect(screen.getByTestId('emptystar')).toBeInTheDocument(); | ||
expect(axios.post).toBeenCalledWith( | ||
'http://localhost:8000/api/saved-list/', | ||
{ company_pk: 1 } | ||
); | ||
expect(axios.get).toHaveBeenCalledWith( | ||
'http://localhost:8000/api/profiles/?is_saved=True' | ||
); | ||
}; | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { render, screen, cleanup } from '@testing-library/react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
|
||
import CookieMod from '../components/cookieacception/CookieMod'; | ||
|
||
afterEach(cleanup); | ||
|
||
describe('CookieMod component unit tests', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add test cases that verify behavior? I mean hiding a modal when agree was clicked There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for feedback. Done |
||
test('renders agree button', () => { | ||
render( | ||
<MemoryRouter> | ||
<CookieMod active={true} /> | ||
</MemoryRouter> | ||
); | ||
const buttonElement = screen.getByText(/Погоджуюсь/i); | ||
expect(buttonElement).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders deny button', () => { | ||
render( | ||
<MemoryRouter> | ||
<CookieMod active={true} /> | ||
</MemoryRouter> | ||
); | ||
const buttonElement = screen.getByText(/Відмовляюсь/i); | ||
expect(buttonElement).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders cookiepolicy link', async () => { | ||
render( | ||
<MemoryRouter> | ||
<CookieMod active={true} /> | ||
</MemoryRouter> | ||
); | ||
|
||
const linkElement = screen.getByText(/про кукі-файли/i); | ||
expect(linkElement).toBeInTheDocument(); | ||
expect(linkElement).toHaveAttribute('href', '/cookies-policy'); | ||
}); | ||
|
||
test('renders hidden cookie modal window', () => { | ||
render( | ||
<MemoryRouter> | ||
<CookieMod active={false} /> | ||
</MemoryRouter> | ||
); | ||
const cookieElement = screen.queryByTestId('cookiemodal', { hidden: true }); | ||
expect(cookieElement).toBeInTheDocument(); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this wrapper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried 'axios.get = jest.fn().mockResolvedValue({ ...' but it doesn't work(( The only way I've found was this wrapper