This commit is contained in:
ammarahm-ed
2022-09-22 13:44:12 +05:00
4 changed files with 27 additions and 29 deletions

View File

@@ -261,3 +261,18 @@ test("editing a note and toggling read-only mode should show updated content", a
`readonly-edited-note.txt`
);
});
test("creating a new note and toggling read-only mode should not empty editor content", async ({
page
}) => {
const app = new AppModel(page);
await app.goto();
const notes = await app.goToNotes();
const note = await notes.createNote(NOTE);
await note?.properties.readonly();
expect(await note?.properties.isReadonly()).toBeTruthy();
expect(await notes.editor.getContent("text")).not.toHaveLength(0);
expect(await notes.editor.getContent("text")).toBe(NOTE.content);
});

View File

@@ -32,7 +32,7 @@ const config: PlaywrightTestConfig = {
testDir: "__e2e__",
// Each test is given 30 seconds
timeout: IS_CI ? 30000 : 15000,
timeout: 30000,
workers: IS_CI ? 2 : 2,
reporter: "list",
retries: IS_CI ? 1 : 0,

View File

@@ -73,7 +73,6 @@ export default function EditorManager({
// update.
const [timestamp, setTimestamp] = useState<number>(0);
const content = useRef<string>("");
const previewSession = useRef<PreviewSession>();
const [dropRef, overlayRef] = useDragOverlay();
const editorInstance = useEditorInstance();
@@ -116,12 +115,7 @@ export default function EditorManager({
const openSession = useCallback(async (noteId: string | number) => {
await editorstore.get().openSession(noteId);
const { getSessionContent } = editorstore.get();
const sessionContent = await getSessionContent();
previewSession.current = undefined;
content.current = sessionContent?.data;
setTimestamp(Date.now());
}, []);
@@ -132,7 +126,7 @@ export default function EditorManager({
previewSession.current.content,
true
);
} else if (noteId && content.current) {
} else if (noteId && editorstore.get().session.content) {
await db.attachments?.downloadImages(noteId);
}
}, [noteId]);
@@ -143,7 +137,6 @@ export default function EditorManager({
(async function () {
await editorstore.newSession(nonce);
content.current = "";
setTimestamp(Date.now());
})();
}, [isNewSession, nonce]);
@@ -175,7 +168,10 @@ export default function EditorManager({
)}
<Editor
nonce={timestamp}
content={content.current}
content={
previewSession.current?.content?.data ||
editorstore.get().session?.content?.data
}
options={{
readonly: isReadonly || isPreviewSession,
onRequestFocus: () => toggleProperties(false),
@@ -186,8 +182,6 @@ export default function EditorManager({
{arePropertiesVisible && (
<Properties
onOpenPreviewSession={async (session: PreviewSession) => {
const { content: sessionContent } = session;
content.current = sessionContent.data;
previewSession.current = session;
setTimestamp(Date.now());
}}

View File

@@ -134,11 +134,13 @@ class EditorStore extends BaseStore {
if (note.conflicted)
return hashNavigate(`/notes/${noteId}/conflict`, { replace: true });
const content = await db.content.raw(note.contentId);
this.set((state) => {
const defaultSession = getDefaultSession(note.dateEdited);
state.session = {
...defaultSession,
...note,
content,
state: SESSION_STATES.new,
attachmentsLength: db.attachments.ofNote(note.id, "all")?.length || 0
};
@@ -194,11 +196,14 @@ class EditorStore extends BaseStore {
attachmentStore.refresh();
}
if (session.content) {
this.get().session.content = session.content;
}
this.set((state) => {
if (!!state.session.id && state.session.id !== note.id) return;
for (let key in session) {
if (key === "content" && !state.session.locked) continue;
if (key === "content") continue;
state.session[key] = session[key];
}
@@ -266,18 +271,6 @@ class EditorStore extends BaseStore {
return this.saveSession(noteId, { sessionId, content });
};
getSessionContent = async () => {
const session = this.get().session;
switch (session.sessionType) {
case "default":
return await db.content.raw(session.contentId);
case "locked":
return session.content;
default:
return;
}
};
setTag = (tag) => {
return this._setTag(tag);
};
@@ -338,7 +331,3 @@ class EditorStore extends BaseStore {
*/
const [useStore, store] = createStore(EditorStore);
export { useStore, store, SESSION_STATES };
function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}