mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-16 19:57:52 +01:00
* test: intialize testing environment * test: add an example test for reference * test: add simple navigation test * some initial tests * some changes * name and other small changes * permanently delete a note * permanenlt delete a note * test: improve test readability I have added different id builders for building test ids. They make the tests more readable and fluent. * test lock a note * test add a note to notebook * test favorite a note * test pin a note * test: further improve test readability basically I refactored some frequently performed actions into helper functions * test: check for presence of toast * test: properly test pinned note * test: increase tests reliability * test: fix all tests * perf: load 2co script & fonts when needed * ci: initialize e2e gh test runner * ci: do not run npm ci * test: fix lock note test for all browsers * ci: fix playwright tests * ci: fix yaml syntax error * ci: no need to use custom ssh-agent action for eslint * test: improve lock a note test * ci: add GH_DEPLOY_KEY env in eslint.yml * test: check for state: "visible" in isPresent * test: do not check for toast in lock a note test * test: log crypto error to console * test: skip "lock a note" test for now until further investigation * ci: only run tests on firefox & chromium * fix: fix useMediaQuery for WebKit browsers * ci: try webkit once again * properties tests * test tag a color /properties * test: run some tests sequentially and independently * test: reenable all tests * fix: user only able to type on character in title box * test: skip lock/unlock tests in CI * test edit a notebook * test: fix all tests * test: fix and add more notebook tests * test: do not only run edit topics test * test: make sure all notes tests pass * test: skip add note to notebook tests for now * test: make sure all tests pass Co-authored-by: alihamuh <alihamuh@gmail.com>
102 lines
2.7 KiB
JavaScript
102 lines
2.7 KiB
JavaScript
import React, { useState, useRef, useCallback } from "react";
|
|
import { Box, Text, Flex } from "rebass";
|
|
import { Input } from "@rebass/forms";
|
|
import Dialog, { showDialog } from "./dialog";
|
|
import * as Icon from "../icons";
|
|
|
|
function PasswordDialog(props) {
|
|
const [isWrong, setIsWrong] = useState(false);
|
|
const passwordRef = useRef();
|
|
const submit = useCallback(async () => {
|
|
const password = passwordRef.current.value;
|
|
if (await props.validate(password)) {
|
|
props.onDone();
|
|
} else {
|
|
setIsWrong(true);
|
|
passwordRef.current.focus();
|
|
}
|
|
}, [setIsWrong, props]);
|
|
return (
|
|
<Dialog
|
|
isOpen={true}
|
|
title={props.title}
|
|
description={props.subtitle}
|
|
icon={props.icon}
|
|
positiveButton={{
|
|
text: props.positiveButtonText,
|
|
onClick: submit,
|
|
}}
|
|
negativeButton={{ text: "Cancel", onClick: props.onCancel }}
|
|
>
|
|
<Box my={1}>
|
|
<Input
|
|
data-test-id="dialog-vault-pass"
|
|
ref={passwordRef}
|
|
autoFocus
|
|
variant={isWrong ? "error" : "input"}
|
|
type="password"
|
|
placeholder="Enter vault password"
|
|
onKeyUp={async (e) => {
|
|
if (e.key === "Enter") {
|
|
await submit();
|
|
} else {
|
|
setIsWrong(false);
|
|
}
|
|
}}
|
|
/>
|
|
{isWrong && (
|
|
<Flex alignItems="center" color="error" mt={2}>
|
|
<Icon.Alert size={16} color="error" />
|
|
<Text ml={1} fontSize={"subBody"}>
|
|
Wrong password
|
|
</Text>
|
|
</Flex>
|
|
)}
|
|
</Box>
|
|
</Dialog>
|
|
);
|
|
}
|
|
|
|
function getDialogData(type) {
|
|
switch (type) {
|
|
case "create_vault":
|
|
return {
|
|
title: "Create Your Vault",
|
|
subtitle: "Your vault will encrypt everything locally.",
|
|
icon: Icon.Vault,
|
|
positiveButtonText: "Create my vault",
|
|
};
|
|
case "unlock_vault":
|
|
return {
|
|
title: "Unlock your Vault",
|
|
subtitle: "Your vault will remain unlocked for 30 minutes.",
|
|
icon: Icon.Unlock,
|
|
positiveButtonText: "Unlock my vault",
|
|
};
|
|
case "unlock_note":
|
|
return {
|
|
title: "Unlock your Note",
|
|
subtitle: "Unlocking will make this note openly available.",
|
|
icon: Icon.Unlock,
|
|
positiveButtonText: "Unlock this note",
|
|
};
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
|
|
export function showPasswordDialog(type, validate) {
|
|
const { title, subtitle, icon, positiveButtonText } = getDialogData(type);
|
|
return showDialog((perform) => (
|
|
<PasswordDialog
|
|
title={title}
|
|
subtitle={subtitle}
|
|
icon={icon}
|
|
positiveButtonText={positiveButtonText}
|
|
onCancel={() => perform(false)}
|
|
validate={validate}
|
|
onDone={() => perform(true)}
|
|
/>
|
|
));
|
|
}
|