-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: [#175419820] Restore screen brightness (#2728)
* [#175419820] Refactored the components in a more functional style. Added Async useEffects to save and restore brightness on navigation focus * [#175419820] Handled the hardware backpress case. Refactored to improve performances on event DidFocus * [#175419820] Tested UseLayoutEffect for responsivenes * [#175419820] Refactored FiscalCodeLandscapeOverlay * [#175419820] Added test * [#175419820] Switched to async effect. Removed component state variable inititalBrightness * [#175419820] Removed useless alert * [#175419820] Solution with a brightness varible locally scoped to effect * [#175419820] Removed debug printings * [#175419820] Relaxed test Co-authored-by: Giovanni Mancini <g.mancini.0gmail.com> Co-authored-by: Matteo Boschi <[email protected]>
- Loading branch information
1 parent
f4b64ca
commit 385a3b5
Showing
3 changed files
with
303 additions
and
212 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
88 changes: 88 additions & 0 deletions
88
ts/components/__tests__/FiscalCodeLandscapeOverlay.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,88 @@ | ||
import configureMockStore from "redux-mock-store"; | ||
import { render, waitFor } from "@testing-library/react-native"; | ||
import { Provider } from "react-redux"; | ||
import * as React from "react"; | ||
import { tryCatch } from "fp-ts/lib/TaskEither"; | ||
|
||
import FiscalCodeLandscapeOverlay, { | ||
Props as FiscalCodeProps | ||
} from "../FiscalCodeLandscapeOverlay"; | ||
import { FiscalCode } from "../../../definitions/backend/FiscalCode"; | ||
import { EmailAddress } from "../../../definitions/backend/EmailAddress"; | ||
import { GlobalState } from "../../store/reducers/types"; | ||
import { applicationChangeState } from "../../store/actions/application"; | ||
import { appReducer } from "../../store/reducers"; | ||
import * as myBrightness from "../../utils/brightness"; | ||
import { PreferredLanguageEnum } from ".../../../definitions/backend/PreferredLanguage"; | ||
|
||
jest.mock("react-native-share", () => jest.fn()); | ||
|
||
describe("Test How Fiscal Code Overlay gets rendered on lifetime methods", () => { | ||
afterAll(() => jest.resetAllMocks()); | ||
|
||
const myProps: FiscalCodeProps = { | ||
onCancel: jest.fn(), | ||
profile: { | ||
accepted_tos_version: 3, | ||
blocked_inbox_or_channels: {}, | ||
email: "[email protected]" as EmailAddress, | ||
family_name: "Rossi", | ||
fiscal_code: "ZXCVBN66Z66K666Q" as FiscalCode, | ||
has_profile: true, | ||
is_email_enabled: false, | ||
is_email_validated: true, | ||
is_inbox_enabled: true, | ||
is_webhook_enabled: true, | ||
name: "Mario", | ||
preferred_languages: ["it_IT"] as Array<PreferredLanguageEnum>, | ||
version: 7 | ||
}, | ||
municipality: { | ||
error: { | ||
name: "myError", | ||
message: "myMessage" | ||
}, | ||
kind: "PotNoneError" | ||
}, | ||
showBackSide: false | ||
}; | ||
|
||
it("Should call getBrightness and setBrightness", async () => { | ||
const getSpy = jest.spyOn(myBrightness, "getBrightness").mockReturnValue( | ||
tryCatch( | ||
() => new Promise(() => 0), | ||
reason => new Error(String(reason)) | ||
) | ||
); | ||
|
||
const mockStoreFactory = configureMockStore<GlobalState>(); | ||
|
||
const globalState: GlobalState = appReducer( | ||
undefined, | ||
applicationChangeState("active") | ||
); | ||
|
||
const myStore = mockStoreFactory({ | ||
...globalState, | ||
// While the component under test is disconnected from the store, some | ||
// inner components import ConnectionBar which is connected | ||
network: { isConnected: true, actionQueue: [] } | ||
} as GlobalState); | ||
|
||
const component = render( | ||
<Provider store={myStore}> | ||
<FiscalCodeLandscapeOverlay {...myProps} /> | ||
</Provider> | ||
); | ||
|
||
const myButton = component.queryByA11yLabel("Chiudi"); | ||
|
||
component.unmount(); | ||
await waitFor(() => expect(myButton).toBeNull(), { | ||
timeout: 10000 | ||
}); | ||
|
||
// Read the brightness | ||
expect(getSpy).toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.