This repository has been archived by the owner on Mar 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement profile reset (#2811)
- Loading branch information
Showing
18 changed files
with
323 additions
and
67 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
41 changes: 41 additions & 0 deletions
41
src/domains/profile/components/ResetProfile/ResetProfile.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,41 @@ | ||
import { Profile, ProfileSetting } from "@arkecosystem/platform-sdk-profiles"; | ||
import React from "react"; | ||
import { act, env, fireEvent, getDefaultProfileId, render, waitFor } from "utils/testing-library"; | ||
|
||
import { ResetProfile } from "./ResetProfile"; | ||
|
||
let profile: Profile; | ||
|
||
describe("ResetProfile", () => { | ||
beforeAll(() => { | ||
profile = env.profiles().findById(getDefaultProfileId()); | ||
profile.settings().set(ProfileSetting.Theme, "dark"); | ||
env.persist(); | ||
}); | ||
|
||
it("should render", async () => { | ||
const { getByTestId, asFragment } = render(<ResetProfile isOpen profile={profile} />); | ||
|
||
await waitFor(() => expect(getByTestId("modal__inner")).toBeTruthy()); | ||
expect(getByTestId("ResetProfile__submit-button")).toBeInTheDocument(); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
it("should reset profile", async () => { | ||
const onReset = jest.fn(); | ||
|
||
const { getByTestId } = render(<ResetProfile isOpen profile={profile} onReset={onReset} />); | ||
|
||
const theme = profile.settings().get(ProfileSetting.Theme); | ||
|
||
await waitFor(() => expect(getByTestId("modal__inner")).toBeTruthy()); | ||
|
||
act(() => { | ||
fireEvent.click(getByTestId("ResetProfile__submit-button")); | ||
}); | ||
|
||
await waitFor(() => expect(profile.settings().get(ProfileSetting.Theme)).not.toBe(theme)); | ||
|
||
expect(onReset).toHaveBeenCalled(); | ||
}); | ||
}); |
60 changes: 60 additions & 0 deletions
60
src/domains/profile/components/ResetProfile/ResetProfile.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,60 @@ | ||
import { Profile } from "@arkecosystem/platform-sdk-profiles"; | ||
import { images } from "app/assets/images"; | ||
import { Button } from "app/components/Button"; | ||
import { Icon } from "app/components/Icon"; | ||
import { Modal } from "app/components/Modal"; | ||
import { useEnvironmentContext } from "app/contexts"; | ||
import { toasts } from "app/services"; | ||
import React from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
const DeleteBanner = images.common.DeleteBanner; | ||
|
||
type ResetProfileProps = { | ||
isOpen: boolean; | ||
profile: Profile; | ||
onClose?: any; | ||
onCancel?: any; | ||
onReset?: any; | ||
}; | ||
|
||
export const ResetProfile = ({ isOpen, profile, onClose, onCancel, onReset }: ResetProfileProps) => { | ||
const { t } = useTranslation(); | ||
|
||
const { persist } = useEnvironmentContext(); | ||
|
||
const handleReset = async () => { | ||
profile.flush(); | ||
|
||
await persist(); | ||
|
||
toasts.success(t("PROFILE.MODAL_RESET_PROFILE.SUCCESS")); | ||
|
||
onReset?.(); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
title={t("PROFILE.MODAL_RESET_PROFILE.TITLE")} | ||
image={<DeleteBanner className="w-3/5 m-auto my-8" />} | ||
description={t("PROFILE.MODAL_RESET_PROFILE.DESCRIPTION")} | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
> | ||
<div className="flex justify-end mt-8 space-x-3"> | ||
<Button variant="plain" onClick={onCancel} data-testid="ResetProfile__cancel-button"> | ||
{t("COMMON.CANCEL")} | ||
</Button> | ||
|
||
<Button type="submit" onClick={handleReset} data-testid="ResetProfile__submit-button"> | ||
<Icon name="Reset" /> | ||
<span>{t("COMMON.RESET_DATA")}</span> | ||
</Button> | ||
</div> | ||
</Modal> | ||
); | ||
}; | ||
|
||
ResetProfile.defaultProps = { | ||
isOpen: false, | ||
}; |
93 changes: 93 additions & 0 deletions
93
src/domains/profile/components/ResetProfile/__snapshots__/ResetProfile.test.tsx.snap
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,93 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ResetProfile should render 1`] = ` | ||
<DocumentFragment> | ||
<div | ||
class="fixed inset-0 z-50 w-full h-full overflow-y-scroll" | ||
> | ||
<div | ||
class="fixed z-50 w-full h-full bg-black opacity-50" | ||
data-testid="modal__overlay" | ||
/> | ||
<div | ||
class="sc-AxiKw cTRlJa absolute top-0 left-0 right-0 z-50 flex flex-col p-10 mx-auto mt-24 mb-24 overflow-hidden rounded-xl bg-theme-background" | ||
data-testid="modal__inner" | ||
> | ||
<div | ||
class="absolute top-0 right-0 z-50 mt-5 mr-5 rounded bg-theme-primary-100 hover:text-white hover:bg-theme-neutral-900" | ||
> | ||
<button | ||
class="sc-AxjAm goVygI w-11 h-11" | ||
color="primary" | ||
data-testid="modal__close-btn" | ||
type="button" | ||
> | ||
<div | ||
class="sc-AxirZ fFqjhX" | ||
height="14" | ||
width="14" | ||
> | ||
<svg> | ||
cross-slim.svg | ||
</svg> | ||
</div> | ||
</button> | ||
</div> | ||
<div | ||
class="relative" | ||
> | ||
<h2 | ||
class="mb-0 text-3xl font-bold" | ||
> | ||
Reset Profile Data | ||
</h2> | ||
<div | ||
class="flex-1" | ||
> | ||
<svg | ||
class="w-3/5 m-auto my-8" | ||
> | ||
delete-banner.svg | ||
</svg> | ||
<div | ||
class="mt-1 text-theme-neutral-dark" | ||
> | ||
Do you really want to reset this profile? Once reset, you will not be able to restore it. | ||
</div> | ||
<div | ||
class="flex justify-end mt-8 space-x-3" | ||
> | ||
<button | ||
class="sc-AxjAm fPpool" | ||
color="primary" | ||
data-testid="ResetProfile__cancel-button" | ||
type="button" | ||
> | ||
Cancel | ||
</button> | ||
<button | ||
class="sc-AxjAm kbZyZT" | ||
color="primary" | ||
data-testid="ResetProfile__submit-button" | ||
type="submit" | ||
> | ||
<div | ||
class="sc-AxirZ iQaTP" | ||
height="1em" | ||
width="1em" | ||
> | ||
<svg> | ||
reset.svg | ||
</svg> | ||
</div> | ||
<span> | ||
Reset Data | ||
</span> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</DocumentFragment> | ||
`; |
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 @@ | ||
export * from "./ResetProfile"; |
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,20 @@ | ||
import { Selector } from "testcafe"; | ||
|
||
import { buildTranslations } from "../../../app/i18n/helpers"; | ||
import { createFixture } from "../../../utils/e2e-utils"; | ||
import { goToSettings } from "./common"; | ||
|
||
const translations = buildTranslations(); | ||
|
||
createFixture(`Reset profile`).beforeEach(async (t) => await goToSettings(t)); | ||
|
||
test("should reset profile", async (t) => { | ||
const name = await Selector("input[name=name]").value; | ||
const automaticSignOutPeriod = await Selector("input[name=automaticSignOutPeriod]").value; | ||
|
||
await t.click(Selector("button").withText(translations.COMMON.RESET_DATA)); | ||
|
||
// TODO: uncomment when rerender is implemented | ||
// await t.expect(Selector("input[name=name]").value).eql(name); | ||
// await t.expect(Selector("input[name=automaticSignOutPeriod]").value).notEql(automaticSignOutPeriod); | ||
}); |
Oops, something went wrong.