Skip to content

Commit 34dccb7

Browse files
committed
Fix integration tests
1 parent ef790a1 commit 34dccb7

File tree

2 files changed

+75
-7
lines changed

2 files changed

+75
-7
lines changed

app/gui/integration-test/dashboard/actions/api.ts

+71-4
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const INITIAL_CALLS_OBJECT = {
103103
updateDirectory: array<
104104
{ directoryId: backend.DirectoryId } & backend.UpdateDirectoryRequestBody
105105
>(),
106-
deleteAsset: array<{ assetId: backend.AssetId }>(),
106+
deleteAsset: array<{ assetId: backend.AssetId; force: boolean }>(),
107107
undoDeleteAsset: array<{ assetId: backend.AssetId }>(),
108108
createUser: array<backend.CreateUserRequestBody>(),
109109
createUserGroup: array<backend.CreateUserGroupRequestBody>(),
@@ -283,6 +283,17 @@ async function mockApiInternal({ page, setupAPI }: MockParams) {
283283
return !alreadyDeleted
284284
}
285285

286+
const forceDeleteAsset = (assetId: backend.AssetId) => {
287+
const hasAsset = assetMap.has(assetId)
288+
deletedAssets.delete(assetId)
289+
assetMap.delete(assetId)
290+
assets.splice(
291+
assets.findIndex((asset) => asset.id === assetId),
292+
1,
293+
)
294+
return hasAsset
295+
}
296+
286297
const undeleteAsset = (assetId: backend.AssetId) => {
287298
const wasDeleted = deletedAssets.has(assetId)
288299
deletedAssets.delete(assetId)
@@ -487,7 +498,7 @@ async function mockApiInternal({ page, setupAPI }: MockParams) {
487498
description: rest.description ?? '',
488499
labels: [],
489500
parentId: defaultDirectoryId,
490-
permissions: [],
501+
permissions: [createUserPermission(defaultUser, permissions.PermissionAction.own)],
491502
parentsPath: '',
492503
virtualParentsPath: '',
493504
},
@@ -517,6 +528,48 @@ async function mockApiInternal({ page, setupAPI }: MockParams) {
517528
return secret
518529
}
519530

531+
const createDatalink = (rest: Partial<backend.DatalinkAsset>): backend.DatalinkAsset => {
532+
const datalink = object.merge(
533+
{
534+
type: backend.AssetType.datalink,
535+
id: backend.DatalinkId('datalink-' + uniqueString.uniqueString()),
536+
projectState: null,
537+
extension: null,
538+
title: rest.title ?? '',
539+
modifiedAt: dateTime.toRfc3339(new Date()),
540+
description: rest.description ?? '',
541+
labels: [],
542+
parentId: defaultDirectoryId,
543+
permissions: [createUserPermission(defaultUser, permissions.PermissionAction.own)],
544+
parentsPath: '',
545+
virtualParentsPath: '',
546+
},
547+
rest,
548+
)
549+
550+
Object.defineProperty(datalink, 'toJSON', {
551+
value: function toJSON() {
552+
const { parentsPath: _, virtualParentsPath: __, ...rest } = this
553+
554+
return {
555+
...rest,
556+
parentsPath: this.parentsPath,
557+
virtualParentsPath: this.virtualParentsPath,
558+
}
559+
},
560+
})
561+
562+
Object.defineProperty(datalink, 'parentsPath', {
563+
get: () => getParentPath(datalink.parentId),
564+
})
565+
566+
Object.defineProperty(datalink, 'virtualParentsPath', {
567+
get: () => getVirtualParentPath(datalink.parentId, datalink.title),
568+
})
569+
570+
return datalink
571+
}
572+
520573
const createLabel = (value: string, color: backend.LChColor): backend.Label => ({
521574
id: backend.TagId('tag-' + uniqueString.uniqueString()),
522575
value: backend.LabelName(value),
@@ -539,6 +592,10 @@ async function mockApiInternal({ page, setupAPI }: MockParams) {
539592
return addAsset(createSecret(rest))
540593
}
541594

595+
const addDatalink = (rest: Partial<backend.DatalinkAsset> = {}) => {
596+
return addAsset(createDatalink(rest))
597+
}
598+
542599
const addLabel = (value: string, color: backend.LChColor) => {
543600
const label = createLabel(value, color)
544601
labels.push(label)
@@ -1109,6 +1166,7 @@ async function mockApiInternal({ page, setupAPI }: MockParams) {
11091166
})
11101167

11111168
await delete_(remoteBackendPaths.deleteAssetPath(GLOB_ASSET_ID), async (route, request) => {
1169+
const force = new URL(request.url()).searchParams.get('force') === 'true'
11121170
const maybeId = request.url().match(/[/]assets[/]([^?]+)/)?.[1]
11131171

11141172
if (!maybeId) return
@@ -1117,9 +1175,13 @@ async function mockApiInternal({ page, setupAPI }: MockParams) {
11171175
// `DirectoryId` to make TypeScript happy.
11181176
const assetId = decodeURIComponent(maybeId) as backend.DirectoryId
11191177

1120-
called('deleteAsset', { assetId })
1178+
called('deleteAsset', { assetId, force })
11211179

1122-
deleteAsset(assetId)
1180+
if (force) {
1181+
forceDeleteAsset(assetId)
1182+
} else {
1183+
deleteAsset(assetId)
1184+
}
11231185

11241186
await route.fulfill({ status: HTTP_STATUS_NO_CONTENT })
11251187
})
@@ -1365,6 +1427,9 @@ async function mockApiInternal({ page, setupAPI }: MockParams) {
13651427
defaultUser,
13661428
defaultUserId,
13671429
rootDirectoryId: defaultDirectoryId,
1430+
get assetCount() {
1431+
return assetMap.size
1432+
},
13681433
goOffline: () => {
13691434
isOnline = false
13701435
},
@@ -1395,10 +1460,12 @@ async function mockApiInternal({ page, setupAPI }: MockParams) {
13951460
createProject,
13961461
createFile,
13971462
createSecret,
1463+
createDatalink,
13981464
addDirectory,
13991465
addProject,
14001466
addFile,
14011467
addSecret,
1468+
addDatalink,
14021469
createLabel,
14031470
addLabel,
14041471
setLabels,

app/gui/integration-test/dashboard/delete.spec.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ test('clear trash', ({ page }) =>
6666
api.addProject()
6767
api.addFile()
6868
api.addSecret()
69+
api.addDatalink()
6970
},
7071
})
7172
.driveTable.withRows(async (rows) => {
72-
await expect(rows).toHaveCount(6)
73+
await expect(rows).toHaveCount(7)
7374
})
7475
.driveTable.withRows(async (rows, _nonRows, _context, page) => {
7576
const mod = await modModifier(page)
@@ -84,7 +85,7 @@ test('clear trash', ({ page }) =>
8485
.driveTable.expectPlaceholderRow()
8586
.goToCategory.trash()
8687
.driveTable.withRows(async (rows) => {
87-
await expect(rows).toHaveCount(6)
88+
await expect(rows).toHaveCount(7)
8889
})
8990
.clearTrash()
9091
.driveTable.expectTrashPlaceholderRow()
@@ -95,5 +96,5 @@ test('clear trash', ({ page }) =>
9596
})
9697
.close()
9798
.driveTable.withRows(async (rows) => {
98-
await expect(rows).toHaveCount(1)
99+
await expect(rows).toHaveCount(0)
99100
}))

0 commit comments

Comments
 (0)