Skip to content

Commit 67523a4

Browse files
committed
test(extension): await persisted attachment cleanup
1 parent f7f479c commit 67523a4

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

‎apps/sim/scripts/test-browser-extension-e2e.ts‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const chatResponses: {
8686
error?: string
8787
}[] = []
8888
const uploadRequests: { event: string; stage: string; method: string; status?: number }[] = []
89+
const draftRemovalReceipts: { scope: string; phase: string; matches: number }[] = []
8990
const responseDiagnostics: Promise<void>[] = []
9091
const chatTurns = new Map<string, number>()
9192
const chatAttempts: {
@@ -830,9 +831,35 @@ try {
830831
).toHaveCount(0)
831832
assert.equal(uploadAttempts, 0)
832833
await browserContext.unroute(uploadEndpoint, interceptUpload)
833-
await attachScreenshot(app.getByRole('main'), scope)
834+
const recoveryKey = await attachScreenshot(app.getByRole('main'), scope)
834835
await screenshot(`pending-capture-drop-${scope}-recovered`)
835836
await app.getByRole('button', { name: `Remove ${name}`, exact: true }).click()
837+
await expect(app.getByRole('button', { name: `Remove ${name}`, exact: true })).toHaveCount(0)
838+
const persistedMatches = async () => {
839+
const stored: unknown = await app.evaluate(() =>
840+
JSON.parse(localStorage.getItem('mothership-drafts:v1') ?? '{}')
841+
)
842+
const drafts = toRecord(toRecord(toRecord(stored).state).drafts)
843+
return Object.values(drafts).filter((draft) => {
844+
const files = toRecord(draft).fileAttachments
845+
return Array.isArray(files) && files.some((file) => toRecord(file).key === recoveryKey)
846+
}).length
847+
}
848+
draftRemovalReceipts.push({
849+
scope,
850+
phase: 'after-ui-removal',
851+
matches: await persistedMatches(),
852+
})
853+
await expect
854+
.poll(persistedMatches, {
855+
message: `${scope}: removed recovery file leaves persisted drafts`,
856+
})
857+
.toBe(0)
858+
draftRemovalReceipts.push({
859+
scope,
860+
phase: 'before-tab-close',
861+
matches: await persistedMatches(),
862+
})
836863
assert.equal(submitted.length, 1, `${scope}: recovering drops duplicated the turn`)
837864
} finally {
838865
await app
@@ -2084,6 +2111,10 @@ try {
20842111
await navigate(`${base.origin}/extension/${org ? `o/${organizationId}` : alphaId}`)
20852112
const greeting = frame().getByRole('heading', { name: 'How can I help?', exact: true })
20862113
await expect(greeting).toBeVisible()
2114+
await expect(
2115+
frame().getByRole('button', { name: /^Remove (?!page context$)/ }),
2116+
`${surface}: screenshot scenario starts without a previous file draft`
2117+
).toHaveCount(0)
20872118
let release = () => {}
20882119
const gate = new Promise<void>((resolve) => {
20892120
release = resolve
@@ -2984,6 +3015,7 @@ try {
29843015
chatAttempts,
29853016
dropReceipts,
29863017
uploadRequests,
3018+
draftRemovalReceipts,
29873019
},
29883020
null,
29893021
2

0 commit comments

Comments
 (0)