Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • web-et-numerique/factory/llle_project/ecolyo
1 result
Select Git revision
Show changes
Showing
with 320 additions and 532 deletions
import { IconButton, Tab } from '@material-ui/core'
import EcogestureTabsView from 'components/Ecogesture/EcogestureTabsView'
import { Season } from 'enums'
import { mount } from 'enzyme'
import toJson from 'enzyme-to-json'
import React from 'react'
......@@ -12,32 +11,23 @@ import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
import EcogestureEmptyList from './EcogestureEmptyList/EcogestureEmptyList'
import EcogestureInitModal from './EcogestureInitModal/EcogestureInitModal'
jest.mock('cozy-ui/transpiled/react/I18n', () => ({
useI18n: jest.fn(() => ({
t: (str: string) => str,
})),
}))
const mockGetAllEcogestures = jest.fn()
const mockGetEcogestureListByProfile = jest.fn()
const mockInitEcogesture = jest.fn()
const mockGetEcogestureListByProfile = jest.fn().mockResolvedValue([])
const mockInitEcogesture = jest.fn().mockResolvedValue(mockedEcogesturesData)
jest.mock('services/ecogesture.service', () => {
return jest.fn(() => {
return {
getAllEcogestures: mockGetAllEcogestures,
getEcogestureListByProfile: mockGetEcogestureListByProfile,
initEcogesture: mockInitEcogesture,
}
})
return jest.fn(() => ({
getAllEcogestures: mockGetAllEcogestures,
getEcogestureListByProfile: mockGetEcogestureListByProfile,
initEcogesture: mockInitEcogesture,
}))
})
const mockGetProfile = jest.fn()
const mockUpdateProfile = jest.fn()
jest.mock('services/profile.service', () => {
return jest.fn(() => {
return {
getProfile: mockGetProfile,
updateProfile: mockUpdateProfile,
}
})
return jest.fn(() => ({
getProfile: mockGetProfile,
updateProfile: mockUpdateProfile,
}))
})
jest.mock('components/Header/CozyBar', () => 'mock-cozybar')
......@@ -47,37 +37,17 @@ jest.mock(
() => 'mock-ecogesturelist'
)
jest.mock('components/Content/Content', () => 'mock-content')
const mockGetSeason = jest.fn()
jest.mock('utils/utils', () => {
return {
getSeason: jest.fn(() => {
return mockGetSeason
}),
}
})
const mockedNavigate = jest.fn()
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useLocation: () => {
return {
search: '',
}
},
useNavigate: () => mockedNavigate,
useLocation: () => ({
search: '',
}),
useNavigate: () => jest.fn(),
}))
describe('EcogestureView component', () => {
const store = createMockEcolyoStore()
beforeEach(() => {
store.clearActions()
mockGetSeason.mockClear()
mockGetAllEcogestures.mockClear()
mockGetEcogestureListByProfile.mockClear()
mockInitEcogesture.mockResolvedValue(mockedEcogesturesData)
mockGetSeason.mockReturnValue(Season.WINTER)
mockGetEcogestureListByProfile.mockResolvedValue([])
})
it('should be rendered correctly', async () => {
const wrapper = mount(
......
......@@ -3,12 +3,6 @@ import { mount } from 'enzyme'
import toJson from 'enzyme-to-json'
import React from 'react'
jest.mock('cozy-ui/transpiled/react/I18n', () => ({
useI18n: jest.fn(() => ({
t: (str: string) => str,
})),
}))
describe('EfficiencyRating component', () => {
it('should be rendered correctly', () => {
const wrapper = mount(<EfficiencyRating result={3} />)
......
......@@ -8,11 +8,6 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store'
import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
import SingleEcogestureView from './SingleEcogestureView'
jest.mock('cozy-ui/transpiled/react/I18n', () => ({
useI18n: jest.fn(() => ({
t: (str: string) => str,
})),
}))
const mockedNavigate = jest.fn()
jest.mock('react-router-dom', () => ({
......@@ -24,34 +19,22 @@ jest.mock('react-router-dom', () => ({
state: { selectionCompleted: true },
}),
}))
const mockImportIconById = jest.fn()
jest.mock('utils/utils', () => {
return {
importIconById: () => mockImportIconById,
}
})
jest.mock(
'components/Ecogesture/EfficiencyRating/EfficiencyRating',
() => () => <div id="EfficiencyRating" />
() => 'mock-EfficiencyRating'
)
jest.mock('components/Header/Header', () => () => <div id="Header" />)
jest.mock('components/Header/CozyBar', () => () => <div id="CozyBar" />)
jest.mock('components/Loader/Loader', () => () => <div id="spinner" />)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
jest.mock('components/Content/Content', () => (props: any) => (
<div id="content">{props.children}</div>
))
jest.mock('components/Header/CozyBar', () => 'mock-cozybar')
jest.mock('components/Header/Header', () => 'mock-header')
jest.mock('components/Content/Content', () => 'mock-content')
const mockGetEcogesturesByIds = jest.fn()
const mockUpdateEcogesture = jest.fn()
jest.mock('services/ecogesture.service', () => {
return jest.fn(() => {
return {
getEcogesturesByIds: mockGetEcogesturesByIds,
updateEcogesture: mockUpdateEcogesture,
}
})
return jest.fn(() => ({
getEcogesturesByIds: mockGetEcogesturesByIds,
updateEcogesture: mockUpdateEcogesture,
}))
})
describe('SingleEcogesture component', () => {
......@@ -69,7 +52,7 @@ describe('SingleEcogesture component', () => {
it('should change doing status', async () => {
mockGetEcogesturesByIds.mockResolvedValue([mockedEcogesturesData[0]])
mockImportIconById.mockReturnValue('')
const updatedEcogesture = { ...mockedEcogesturesData[0], doing: true }
mockUpdateEcogesture.mockResolvedValueOnce(updatedEcogesture)
const wrapper = mount(
......@@ -84,7 +67,7 @@ describe('SingleEcogesture component', () => {
})
it('should change objective status', async () => {
mockGetEcogesturesByIds.mockResolvedValue([mockedEcogesturesData[0]])
mockImportIconById.mockReturnValue('icontest')
const updatedEcogesture = { ...mockedEcogesturesData[0], objective: true }
mockUpdateEcogesture.mockResolvedValueOnce(updatedEcogesture)
......@@ -100,7 +83,6 @@ describe('SingleEcogesture component', () => {
})
it('should toggle more details', async () => {
mockGetEcogesturesByIds.mockResolvedValue([mockedEcogesturesData[0]])
mockImportIconById.mockReturnValue(undefined)
const wrapper = mount(
<Provider store={store}>
......
......@@ -8,20 +8,9 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store'
import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
import EcogestureFormEquipment from './EcogestureFormEquipment'
jest.mock('cozy-ui/transpiled/react/I18n', () => ({
useI18n: jest.fn(() => ({
t: (str: string) => str,
})),
}))
const mockSetPreviousStep = jest.fn()
const mockSetNextStep = jest.fn()
const mockHistoryPush = jest.fn()
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => ({
push: mockHistoryPush,
}),
}))
jest.mock('../EquipmentIcon/EquipmentIcon', () => 'mock-equipment-icon')
describe('EcogestureFormEquipment component', () => {
......
......@@ -11,17 +11,6 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store'
import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
import EcogestureFormSingleChoice from './EcogestureFormSingleChoice'
jest.mock('cozy-ui/transpiled/react/I18n', () => ({
useI18n: jest.fn(() => ({
t: (str: string) => str,
})),
}))
const mockedNavigate = jest.fn()
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => mockedNavigate,
}))
jest.mock(
'components/EcogestureForm/EcogestureLaunchFormModal/EcogestureLaunchFormModal',
() => 'mock-ecogesturelaunchmodal'
......@@ -31,9 +20,6 @@ const mockHandleNextStep = jest.fn()
const mockHandlePreviousStep = jest.fn()
describe('EcogestureFormSingleChoice component', () => {
const store = createMockEcolyoStore()
beforeEach(() => {
store.clearActions()
})
it('should be rendered correctly', async () => {
const wrapper = mount(
......
......@@ -10,12 +10,6 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store'
import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
import EcogestureFormView from './EcogestureFormView'
jest.mock('cozy-ui/transpiled/react/I18n', () => ({
useI18n: jest.fn(() => ({
t: (str: string) => str,
})),
}))
jest.mock('components/Header/CozyBar', () => 'mock-cozybar')
jest.mock('components/Header/Header', () => 'mock-header')
jest.mock(
......@@ -28,18 +22,15 @@ const mockedNavigate = jest.fn()
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => mockedNavigate,
useLocation: () => {
return {
search: '',
}
},
useLocation: () => ({
search: '',
}),
}))
describe('EcogestureFormView component', () => {
const store = createMockEcolyoStore()
beforeEach(() => {
store.clearActions()
mockAppDispatch.mockClear()
jest.clearAllMocks()
})
it('should be rendered correctly', async () => {
......
......@@ -4,12 +4,6 @@ import toJson from 'enzyme-to-json'
import React from 'react'
import EcogestureLaunchFormModal from './EcogestureLaunchFormModal'
jest.mock('cozy-ui/transpiled/react/I18n', () => ({
useI18n: jest.fn(() => ({
t: (str: string) => str,
})),
}))
const mockHandleClose = jest.fn()
describe('EcogestureLaunchFormModal component', () => {
it('should be rendered correctly', () => {
......
......@@ -6,22 +6,8 @@ import React from 'react'
import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
import EquipmentIcon from './EquipmentIcon'
jest.mock('cozy-ui/transpiled/react/I18n', () => ({
useI18n: jest.fn(() => ({
t: (str: string) => str,
})),
}))
const mockImportIconById = jest.fn()
jest.mock('utils/utils', () => {
return {
importIconById: jest.fn(() => {
return mockImportIconById
}),
}
})
describe('EcogestureFormSingleChoice component', () => {
it('should be rendered correctly', async () => {
mockImportIconById.mockReturnValue('')
const wrapper = mount(
<EquipmentIcon equipment={EquipmentType.BOILER} isChecked={false} />
)
......@@ -29,7 +15,6 @@ describe('EcogestureFormSingleChoice component', () => {
expect(toJson(wrapper)).toMatchSnapshot()
})
it('should render checked icon', async () => {
mockImportIconById.mockReturnValue('')
const wrapper = mount(
<EquipmentIcon equipment={EquipmentType.BOILER} isChecked={true} />
)
......
......@@ -10,7 +10,7 @@ exports[`EcogestureFormSingleChoice component should be rendered correctly 1`] =
>
<Icon
className="equipmentIcon "
icon=""
icon="test-file-stub"
size={40}
spin={false}
>
......@@ -27,7 +27,7 @@ exports[`EcogestureFormSingleChoice component should be rendered correctly 1`] =
width={40}
>
<use
xlinkHref="#"
xlinkHref="#test-file-stub"
/>
</svg>
</Component>
......
......@@ -6,29 +6,10 @@ import { mockedEcogesturesData } from 'tests/__mocks__/ecogesturesData.mock'
import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
import EcogestureSelectionDetail from './EcogestureSelectionDetail'
jest.mock('cozy-ui/transpiled/react/I18n', () => ({
useI18n: jest.fn(() => ({
t: (str: string) => str,
})),
}))
const mockImportIconById = jest.fn()
jest.mock('utils/utils', () => {
return {
importIconById: jest.fn(() => {
return mockImportIconById
}),
}
})
const mockValidate = jest.fn()
describe('EcogestureSelectionDetail component', () => {
beforeEach(() => {
mockImportIconById.mockClear()
mockValidate.mockClear()
})
it('should be rendered correctly', async () => {
mockImportIconById.mockReturnValueOnce('testIcon')
const wrapper = mount(
<EcogestureSelectionDetail
ecogesture={mockedEcogesturesData[0]}
......@@ -41,7 +22,6 @@ describe('EcogestureSelectionDetail component', () => {
})
it('should call validate with objective to true', async () => {
mockImportIconById.mockReturnValueOnce('testIcon')
const wrapper = mount(
<EcogestureSelectionDetail
ecogesture={mockedEcogesturesData[0]}
......@@ -55,7 +35,6 @@ describe('EcogestureSelectionDetail component', () => {
})
it('should call validate with doing to true', async () => {
mockImportIconById.mockReturnValueOnce('testIcon')
const wrapper = mount(
<EcogestureSelectionDetail
ecogesture={mockedEcogesturesData[0]}
......@@ -69,7 +48,6 @@ describe('EcogestureSelectionDetail component', () => {
})
it('should call validate with objective and doing to false', async () => {
mockImportIconById.mockReturnValueOnce('testIcon')
const wrapper = mount(
<EcogestureSelectionDetail
ecogesture={mockedEcogesturesData[0]}
......
......@@ -46,13 +46,13 @@ exports[`EcogestureSelectionDetail component should be rendered correctly 1`] =
>
<StyledIcon
className="icon"
icon="testIcon"
icon="test-file-stub"
size={240}
>
<Icon
aria-hidden={true}
className="icon"
icon="testIcon"
icon="test-file-stub"
size={240}
spin={false}
>
......@@ -71,7 +71,7 @@ exports[`EcogestureSelectionDetail component should be rendered correctly 1`] =
width={240}
>
<use
xlinkHref="#testIcon"
xlinkHref="#test-file-stub"
/>
</svg>
</Component>
......
......@@ -4,11 +4,6 @@ import toJson from 'enzyme-to-json'
import React from 'react'
import EcogestureSelectionEnd from './EcogestureSelectionEnd'
jest.mock('cozy-ui/transpiled/react/I18n', () => ({
useI18n: jest.fn(() => ({
t: (str: string) => str,
})),
}))
const mockedNavigate = jest.fn()
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
......@@ -17,7 +12,7 @@ jest.mock('react-router-dom', () => ({
describe('EcogestureSelectionEnd component', () => {
beforeEach(() => {
mockedNavigate.mockClear()
jest.clearAllMocks()
})
it('should be rendered correctly', () => {
......
......@@ -4,12 +4,6 @@ import toJson from 'enzyme-to-json'
import React from 'react'
import EcogestureSelectionModal from './EcogestureSelectionModal'
jest.mock('cozy-ui/transpiled/react/I18n', () => ({
useI18n: jest.fn(() => ({
t: (str: string) => str,
})),
}))
const mockHandleClose = jest.fn()
describe('EcogestureInitModal component', () => {
it('should be rendered correctly', () => {
......
......@@ -4,11 +4,6 @@ import toJson from 'enzyme-to-json'
import React from 'react'
import EcogestureSelectionRestart from './EcogestureSelectionRestart'
jest.mock('cozy-ui/transpiled/react/I18n', () => ({
useI18n: jest.fn(() => ({
t: (str: string) => str,
})),
}))
const mockedNavigate = jest.fn()
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
......@@ -17,11 +12,6 @@ jest.mock('react-router-dom', () => ({
const mockRestart = jest.fn()
describe('EcogestureSelectionRestart component', () => {
beforeEach(() => {
mockedNavigate.mockClear()
mockRestart.mockClear()
})
it('should be rendered correctly', () => {
const wrapper = mount(
<EcogestureSelectionRestart listLength={10} restart={mockRestart} />
......
......@@ -3,43 +3,16 @@ import { mount } from 'enzyme'
import toJson from 'enzyme-to-json'
import React from 'react'
import { Provider } from 'react-redux'
import mockClient from 'tests/__mocks__/client'
import { mockedEcogesturesData } from 'tests/__mocks__/ecogesturesData.mock'
import { createMockEcolyoStore } from 'tests/__mocks__/store'
import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
import EcogestureSelectionView from './EcogestureSelectionView'
jest.mock('cozy-ui/transpiled/react/I18n', () => ({
useI18n: jest.fn(() => ({
t: (str: string) => str,
})),
}))
jest.mock('cozy-client', () => {
return {
useClient: jest.fn(() => {
return mockClient
}),
}
})
const mockHistoryGoBack = jest.fn()
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useLocation: () => {
return {
search: '',
}
},
useNavigate: () => ({
push: mockHistoryGoBack,
}),
}))
const mockGetEcogestureListByProfile = jest.fn()
jest.mock('services/ecogesture.service', () => {
return jest.fn(() => {
return {
getEcogestureListByProfile: mockGetEcogestureListByProfile,
}
})
return jest.fn(() => ({
getEcogestureListByProfile: mockGetEcogestureListByProfile,
}))
})
jest.mock('components/Header/CozyBar', () => 'mock-cozybar')
......@@ -65,8 +38,7 @@ jest.mock(
describe('EcogestureSelection component', () => {
const store = createMockEcolyoStore()
beforeEach(() => {
store.clearActions()
mockGetEcogestureListByProfile.mockClear()
jest.clearAllMocks()
})
it('should be rendered correctly', async () => {
......
......@@ -2,18 +2,6 @@ import ExplorationError from 'components/Exploration/ExplorationError'
import { shallow } from 'enzyme'
import React from 'react'
jest.mock('cozy-ui/transpiled/react/I18n', () => ({
useI18n: jest.fn(() => ({
t: (str: string) => str,
})),
}))
const mockedNavigate = jest.fn()
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => mockedNavigate,
}))
describe('ExplorationError component', () => {
it('should be rendered correctly', () => {
const component = shallow(<ExplorationError />).getElement
......
......@@ -7,17 +7,6 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store'
import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
import ExplorationFinished from './ExplorationFinished'
jest.mock('cozy-ui/transpiled/react/I18n', () => ({
useI18n: jest.fn(() => ({
t: (str: string) => str,
})),
}))
const mockedNavigate = jest.fn()
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => mockedNavigate,
}))
describe('ExplorationFinished', () => {
const store = createMockEcolyoStore()
it('should be rendered correctly', () => {
......
......@@ -5,31 +5,15 @@ import { Provider } from 'react-redux'
import { createMockEcolyoStore } from 'tests/__mocks__/store'
import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
jest.mock('cozy-ui/transpiled/react/I18n', () => ({
useI18n: jest.fn(() => ({
t: (str: string) => str,
})),
}))
const mockUserChallengeUpdateFlag = jest.fn()
const mockIsChallengeDone = jest.fn()
jest.mock('services/challenge.service', () => {
return jest.fn(() => {
return {
updateUserChallenge: mockUserChallengeUpdateFlag,
isChallengeDone: mockIsChallengeDone,
}
})
return jest.fn(() => ({
updateUserChallenge: mockUserChallengeUpdateFlag,
isChallengeDone: mockIsChallengeDone,
}))
})
const mockHistoryPush = jest.fn()
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => ({
push: mockHistoryPush,
}),
}))
describe('ExplorationOngoing component', () => {
it('should be rendered correctly', () => {
const store = createMockEcolyoStore()
......
......@@ -10,17 +10,6 @@ import ExplorationFinished from './ExplorationFinished'
import ExplorationOngoing from './ExplorationOngoing'
import ExplorationView from './ExplorationView'
jest.mock('cozy-ui/transpiled/react/I18n', () => ({
useI18n: jest.fn(() => ({
t: (str: string) => str,
})),
}))
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => jest.fn(),
}))
jest.mock('components/Header/CozyBar', () => 'mock-cozybar')
jest.mock('components/Header/Header', () => 'mock-header')
jest.mock('components/Content/Content', () => 'mock-content')
......