authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-09-05 01:20:50-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-09-05 01:20:50-07:00
log83a2897ed6c400b3679a37920e964d829094bd43
treefad5007216e764092babcc8ba33f12da29538fc7
parent68aa7aa8305e9dfc0d98543f607d88bd37fb66e2
signature Signed by PGP key B5690EEEBB952194

refactor(mobile): test composer persistence through the live decoder (#10033)


2 files changed, 8 insertions(+), 13 deletions(-)

apps/mobile/src/state/use-composer-drafts.test.ts+8-9
...@@ -159,7 +159,6 @@ import {...@@ -159,7 +159,6 @@ import {
159 copyComposerDraftContentIfEmpty,159 copyComposerDraftContentIfEmpty,
160 copyComposerDraftContentState,160 copyComposerDraftContentState,
161 decodePersistedComposerState,161 decodePersistedComposerState,
162 decodePersistedComposerDrafts,
163 ensureComposerDraftsLoaded,162 ensureComposerDraftsLoaded,
164 type ComposerDraft,163 type ComposerDraft,
165 flushComposerDrafts,164 flushComposerDrafts,
...@@ -252,12 +251,12 @@ describe("mobile composer drafts", () => {...@@ -252,12 +251,12 @@ describe("mobile composer drafts", () => {
252 };251 };
253252
254 expect(253 expect(
255 decodePersistedComposerDrafts({254 decodePersistedComposerState({
256 schemaVersion: 1,255 schemaVersion: 1,
257 drafts: {256 drafts: {
258 "environment-1:thread-1": { text: "Review this file", attachments: [file] },257 "environment-1:thread-1": { text: "Review this file", attachments: [file] },
259 },258 },
260 }),259 }).drafts,
261 ).toEqual({260 ).toEqual({
262 "environment-1:thread-1": { text: "Review this file", attachments: [file] },261 "environment-1:thread-1": { text: "Review this file", attachments: [file] },
263 });262 });
...@@ -987,7 +986,7 @@ describe("mobile composer drafts", () => {...@@ -987,7 +986,7 @@ describe("mobile composer drafts", () => {
987986
988 it("rejects persisted images without image bytes or a file URI", () => {987 it("rejects persisted images without image bytes or a file URI", () => {
989 expect(() =>988 expect(() =>
990 decodePersistedComposerDrafts({989 decodePersistedComposerState({
991 schemaVersion: 1,990 schemaVersion: 1,
992 drafts: {991 drafts: {
993 "environment-1:thread-1": {992 "environment-1:thread-1": {
...@@ -1010,7 +1009,7 @@ describe("mobile composer drafts", () => {...@@ -1010,7 +1009,7 @@ describe("mobile composer drafts", () => {
10101009
1011 it("hydrates selector state even when the message content is empty", () => {1010 it("hydrates selector state even when the message content is empty", () => {
1012 expect(1011 expect(
1013 decodePersistedComposerDrafts({1012 decodePersistedComposerState({
1014 schemaVersion: 1,1013 schemaVersion: 1,
1015 drafts: {1014 drafts: {
1016 "new-task:environment-1:project-1": {1015 "new-task:environment-1:project-1": {
...@@ -1030,7 +1029,7 @@ describe("mobile composer drafts", () => {...@@ -1030,7 +1029,7 @@ describe("mobile composer drafts", () => {
1030 },1029 },
1031 },1030 },
1032 },1031 },
1033 }),1032 }).drafts,
1034 ).toEqual({1033 ).toEqual({
1035 "new-task:environment-1:project-1": {1034 "new-task:environment-1:project-1": {
1036 text: "",1035 text: "",
...@@ -1053,18 +1052,18 @@ describe("mobile composer drafts", () => {...@@ -1053,18 +1052,18 @@ describe("mobile composer drafts", () => {
10531052
1054 it("keeps legacy content-only drafts and rejects invalid selector state", () => {1053 it("keeps legacy content-only drafts and rejects invalid selector state", () => {
1055 expect(1054 expect(
1056 decodePersistedComposerDrafts({1055 decodePersistedComposerState({
1057 schemaVersion: 1,1056 schemaVersion: 1,
1058 drafts: {1057 drafts: {
1059 "environment-1:thread-1": DRAFT,1058 "environment-1:thread-1": DRAFT,
1060 },1059 },
1061 }),1060 }).drafts,
1062 ).toEqual({1061 ).toEqual({
1063 "environment-1:thread-1": DRAFT,1062 "environment-1:thread-1": DRAFT,
1064 });1063 });
10651064
1066 expect(() =>1065 expect(() =>
1067 decodePersistedComposerDrafts({1066 decodePersistedComposerState({
1068 schemaVersion: 1,1067 schemaVersion: 1,
1069 drafts: {1068 drafts: {
1070 "environment-1:thread-1": {1069 "environment-1:thread-1": {
apps/mobile/src/state/use-composer-drafts.ts-4
...@@ -238,10 +238,6 @@ export function decodePersistedComposerState(value: unknown): {...@@ -238,10 +238,6 @@ export function decodePersistedComposerState(value: unknown): {
238 };238 };
239}239}
240240
241export function decodePersistedComposerDrafts(value: unknown): Record<string, ComposerDraft> {
242 return decodePersistedComposerState(value).drafts;
243}
244
245async function getComposerDraftsFile() {241async function getComposerDraftsFile() {
246 const { Directory, File, Paths } = await import("expo-file-system");242 const { Directory, File, Paths } = await import("expo-file-system");
247 const directory = new Directory(Paths.document, COMPOSER_DRAFTS_DIRECTORY);243 const directory = new Directory(Paths.document, COMPOSER_DRAFTS_DIRECTORY);