-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0303d2
commit dfb0d15
Showing
19 changed files
with
183 additions
and
23 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ const general = { | |
yes: `Yes`, | ||
no: `No`, | ||
currency: '$', | ||
logout: 'Logout', | ||
}; | ||
|
||
export default general; |
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ const general = { | |
yes: 'Sim', | ||
no: 'Não', | ||
currency: 'R$', | ||
logout: 'Desconectar', | ||
}; | ||
|
||
export default general; |
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,35 @@ | ||
|
||
import * as reactNavigation from '@react-navigation/native'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
|
||
import { translate } from '@locales'; | ||
import { useRouteMock } from 'src/__tests__/navigation-mocks'; | ||
|
||
import useScreenSettings from '../useScreenSettings'; | ||
|
||
jest.mock('@react-navigation/native'); | ||
|
||
describe('useScreenSettings', () => { | ||
const routeSpy = jest.spyOn(reactNavigation, 'useRoute'); | ||
|
||
// should return the screen name as New Item and the addition icon | ||
test('deve retornar o nome da tela como novo item e o icone de adição', () => { | ||
routeSpy.mockReturnValue({ ...useRouteMock, params: {} }); | ||
|
||
const { result } = renderHook(useScreenSettings); | ||
|
||
expect(result.current.screenTitle).toEqual(translate('productItems.newItem')); | ||
expect(result.current.fabIcon).toEqual('plus'); | ||
}); | ||
|
||
// if the screen receive a productItem on params, should return the screen name as Edit Item and a check icon | ||
test('caso a tela receba um productItem como paramêtro, deve retornar o nome da tela como editar item e o icone de check', () => { | ||
routeSpy.mockReturnValue({ ...useRouteMock, params: { productItem: { id: '1234' } } }); | ||
|
||
const { result } = renderHook(useScreenSettings); | ||
|
||
expect(result.current.screenTitle).toEqual(translate('productItems.editItem')); | ||
expect(result.current.fabIcon).toEqual('check'); | ||
}); | ||
|
||
}); |
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,32 @@ | ||
import { RouteProp, useRoute } from '@react-navigation/native'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { translate } from '@locales'; | ||
import { ProductNavigatorParamsList } from '@navigator/product-navigator'; | ||
|
||
type Route = RouteProp<ProductNavigatorParamsList, 'NewListItem'>; | ||
|
||
const useScreenSettings = () => { | ||
const [screenTitle, setScreenTitle] = useState( | ||
translate('productItems.newItem'), | ||
); | ||
|
||
const [fabIcon, setFabIcon] = useState('plus'); | ||
|
||
const route = useRoute<Route>(); | ||
const hasParams = !!route.params.productItem; | ||
|
||
useEffect(() => { | ||
if (hasParams) { | ||
setScreenTitle(translate('productItems.editItem')); | ||
setFabIcon('check'); | ||
} | ||
}, [hasParams]); | ||
|
||
return { | ||
screenTitle, | ||
fabIcon, | ||
}; | ||
}; | ||
|
||
export default useScreenSettings; |
35 changes: 35 additions & 0 deletions
35
src/routes/product-list/new-list/__tests__/useScreenSettings.test.ts
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,35 @@ | ||
|
||
import * as reactNavigation from '@react-navigation/native'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
|
||
import { translate } from '@locales'; | ||
import { useRouteMock } from 'src/__tests__/navigation-mocks'; | ||
|
||
import useScreenSettings from '../useScreenSettings'; | ||
|
||
jest.mock('@react-navigation/native'); | ||
|
||
describe('useScreenSettings', () => { | ||
const routeSpy = jest.spyOn(reactNavigation, 'useRoute'); | ||
|
||
// should return the screen name as New List and the addition icon | ||
test('deve retornar o nome da tela como nova lista e o icone de adição', () => { | ||
routeSpy.mockReturnValue({ ...useRouteMock, params: {} }); | ||
|
||
const { result } = renderHook(useScreenSettings); | ||
|
||
expect(result.current.screenTitle).toEqual(translate('productLists.newList')); | ||
expect(result.current.fabIcon).toEqual('plus'); | ||
}); | ||
|
||
// if the screen receive a productList on params, should return the screen name as Edit List and the check icon | ||
test('caso a tela receba um productList como paramêtro, deve retornar o nome da tela como editar lista e o icone de check', () => { | ||
routeSpy.mockReturnValue({ ...useRouteMock, params: { productList: { id: '1234' } } }); | ||
|
||
const { result } = renderHook(useScreenSettings); | ||
|
||
expect(result.current.screenTitle).toEqual(translate('productLists.editList')); | ||
expect(result.current.fabIcon).toEqual('check'); | ||
}); | ||
|
||
}); |
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,32 @@ | ||
import { RouteProp, useRoute } from '@react-navigation/native'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { translate } from '@locales'; | ||
import { ProductNavigatorParamsList } from '@navigator/product-navigator'; | ||
|
||
type Route = RouteProp<ProductNavigatorParamsList, 'NewList'>; | ||
|
||
const useScreenSettings = () => { | ||
const [screenTitle, setScreenTitle] = useState( | ||
translate('productLists.newList'), | ||
); | ||
|
||
const [fabIcon, setFabIcon] = useState('plus'); | ||
|
||
const route = useRoute<Route>(); | ||
const hasParams = !!route.params.productList; | ||
|
||
useEffect(() => { | ||
if (hasParams) { | ||
setScreenTitle(translate('productLists.editList')); | ||
setFabIcon('check'); | ||
} | ||
}, [hasParams]); | ||
|
||
return { | ||
screenTitle, | ||
fabIcon, | ||
}; | ||
}; | ||
|
||
export default useScreenSettings; |