forked from pagopa/io-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Firma con IO): [SFEQS-1049] Add documents screen with navigation…
… bar (pagopa#4180) * chore: add reducers and store * feat: add router screen * chore: add right error icon * feat: add doc bar * chore: add pdf component * chore: update navigator and mock * test: documents screen * chore: update naming coherency Co-authored-by: Francesco Persico <[email protected]> * chore: simplified name for actions * refactor: change state name Co-authored-by: Francesco Persico <[email protected]> * test: update with right store name * chore: add fci enabled selector * refactor: name coherency * test: handle signature request by id * test: added for error component * refactor: name selector * chore: add locales for doc bar * fix: wrong path * fix: layout component * test: update * refactor: add useref for pdf ref * refactor: useRef as mutable object * refactor: remove cast Co-authored-by: Danilo Spinelli <[email protected]> * test: update Co-authored-by: Francesco Persico <[email protected]> Co-authored-by: Danilo Spinelli <[email protected]>
- Loading branch information
1 parent
bd78209
commit 6311242
Showing
15 changed files
with
709 additions
and
15 deletions.
There are no files selected for viewing
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,98 @@ | ||
import * as React from "react"; | ||
import { View, StyleSheet } from "react-native"; | ||
import ButtonDefaultOpacity from "../../../components/ButtonDefaultOpacity"; | ||
import IconFont from "../../../components/ui/IconFont"; | ||
import { H4 } from "../../../components/core/typography/H4"; | ||
import { IOColors } from "../../../components/core/variables/IOColors"; | ||
import { WithTestID } from "../../../types/WithTestID"; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
backgroundColor: IOColors.white, | ||
flexDirection: "row", | ||
borderColor: IOColors.bluegreyLight, | ||
justifyContent: "space-between", | ||
paddingTop: 12, | ||
paddingBottom: 12 | ||
}, | ||
shadow: { | ||
// iOS | ||
shadowColor: IOColors.black, | ||
shadowOffset: { | ||
width: 0, | ||
height: 2 | ||
}, | ||
zIndex: 999, | ||
shadowOpacity: 0.2, | ||
shadowRadius: 3, | ||
// Android | ||
elevation: 8, | ||
borderBottomWidth: 0, | ||
position: "relative" | ||
} | ||
}); | ||
|
||
type Props = WithTestID<{ | ||
titleRight: string; | ||
titleLeft: string; | ||
iconRightColor?: string; | ||
iconLeftColor?: string; | ||
onPrevious: () => void; | ||
onNext: () => void; | ||
}>; | ||
|
||
/** | ||
* A component to render a documents navigation bar with two buttons | ||
* @param props | ||
* @returns | ||
*/ | ||
const DocumentsNavigationBar = (props: Props) => ( | ||
<View style={[styles.shadow, styles.container]}> | ||
{/* button left */} | ||
<ButtonDefaultOpacity | ||
onPress={props.onPrevious} | ||
transparent={true} | ||
testID={"DocumentsNavigationBarLeftButtonTestID"} | ||
> | ||
<View style={{ flexDirection: "row" }}> | ||
<IconFont | ||
name={"io-back"} | ||
color={props.iconLeftColor ?? IOColors.blue} | ||
accessible={true} | ||
/> | ||
<H4 | ||
style={{ | ||
textAlign: "center" | ||
}} | ||
> | ||
{props.titleLeft} | ||
</H4> | ||
</View> | ||
</ButtonDefaultOpacity> | ||
|
||
{/* button right */} | ||
<ButtonDefaultOpacity | ||
onPress={props.onNext} | ||
transparent={true} | ||
testID={"DocumentsNavigationBarRightButtonTestID"} | ||
> | ||
<View style={{ flexDirection: "row" }}> | ||
<H4 | ||
style={{ | ||
textAlign: "center" | ||
}} | ||
> | ||
{props.titleRight} | ||
</H4> | ||
|
||
<IconFont | ||
name={"io-right"} | ||
color={props.iconRightColor ?? IOColors.blue} | ||
accessible={true} | ||
/> | ||
</View> | ||
</ButtonDefaultOpacity> | ||
</View> | ||
); | ||
|
||
export default DocumentsNavigationBar; |
92 changes: 92 additions & 0 deletions
92
ts/features/fci/components/__tests__/DocumentsNavigationBar.test.tsx
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,92 @@ | ||
import * as React from "react"; | ||
import { fireEvent, render } from "@testing-library/react-native"; | ||
import DocumentsNavigationBar from "../DocumentsNavigationBar"; | ||
import { IOColors } from "../../../../components/core/variables/IOColors"; | ||
|
||
type Props = { | ||
titleRight: string; | ||
titleLeft: string; | ||
iconRightColor?: string; | ||
iconLeftColor?: string; | ||
onPrevious: () => void; | ||
onNext: () => void; | ||
}; | ||
|
||
describe("Test DocumentsNavigationBar component", () => { | ||
it("should render a DocumentsNavigationBar Component with props correctly", () => { | ||
const props = { | ||
titleRight: "Pagina 1 di 2", | ||
titleLeft: "Documento 1 di 2", | ||
iconRightColor: IOColors.blue, | ||
iconLeftColor: IOColors.blue, | ||
onPrevious: jest.fn(), | ||
onNext: jest.fn() | ||
}; | ||
const component = renderComponent({ ...props }); | ||
expect(component).toBeTruthy(); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
it("should render a DocumentsNavigationBar Component with titleRight as 'Page 1 of 2'", () => { | ||
const props = { | ||
titleRight: "Page 1 of 2", | ||
titleLeft: "", | ||
onPrevious: jest.fn(), | ||
onNext: jest.fn() | ||
}; | ||
const component = renderComponent({ ...props }); | ||
expect(component).toBeTruthy(); | ||
expect(component.queryByText("Page 1 of 2")).toBeTruthy(); | ||
}); | ||
it("should render a DocumentsNavigationBar Component with titleLeft as 'Document 1 of 5'", () => { | ||
const props = { | ||
titleRight: "", | ||
titleLeft: "Document 1 of 5", | ||
onPrevious: jest.fn(), | ||
onNext: jest.fn() | ||
}; | ||
const component = renderComponent({ ...props }); | ||
expect(component).toBeTruthy(); | ||
expect(component.queryByText("Document 1 of 5")).toBeTruthy(); | ||
}); | ||
it("should render a DocumentsNavigationBar Component with onPrevious button clickable", () => { | ||
const onPress = jest.fn(); | ||
const props = { | ||
titleRight: "", | ||
titleLeft: "", | ||
onPrevious: onPress, | ||
onNext: jest.fn() | ||
}; | ||
const component = renderComponent({ ...props }); | ||
expect(component).toBeTruthy(); | ||
const leftButton = component.getByTestId( | ||
"DocumentsNavigationBarLeftButtonTestID" | ||
); | ||
expect(leftButton).toBeTruthy(); | ||
expect(leftButton).toBeEnabled(); | ||
fireEvent.press(leftButton); | ||
fireEvent.press(leftButton); | ||
expect(onPress).toHaveBeenCalledTimes(2); | ||
}); | ||
it("should render a DocumentsNavigationBar Component with onNext button clickable", () => { | ||
const onPress = jest.fn(); | ||
const props = { | ||
titleRight: "", | ||
titleLeft: "", | ||
onPrevious: jest.fn(), | ||
onNext: onPress | ||
}; | ||
const component = renderComponent({ ...props }); | ||
expect(component).toBeTruthy(); | ||
const rightButton = component.getByTestId( | ||
"DocumentsNavigationBarRightButtonTestID" | ||
); | ||
expect(rightButton).toBeTruthy(); | ||
expect(rightButton).toBeEnabled(); | ||
fireEvent.press(rightButton); | ||
fireEvent.press(rightButton); | ||
expect(onPress).toHaveBeenCalledTimes(2); | ||
}); | ||
}); | ||
|
||
const renderComponent = (props: Props) => | ||
render(<DocumentsNavigationBar {...props} />); |
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
Oops, something went wrong.