generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #283 from ita-social-projects/#276ImplementFirstTe…
…stsToFE #276 implement first tests to fe
- Loading branch information
Showing
12 changed files
with
4,649 additions
and
2,446 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
|
@@ -163,3 +163,5 @@ export function Search({ isAuthorized }) { | |
</div> | ||
); | ||
} | ||
|
||
export default Search; |
This file contains 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 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 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 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 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,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' | ||
); | ||
}; | ||
}); | ||
}); |
This file contains 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,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', () => { | ||
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(); | ||
}); | ||
}); |
Oops, something went wrong.