-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89132ee
commit d9ff080
Showing
5 changed files
with
192 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
e2e-pw/src/oss/specs/groups/nested-dynamic-groups.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
import { test as base } from "src/oss/fixtures"; | ||
import { GridPom } from "src/oss/poms/grid"; | ||
import { ModalPom } from "src/oss/poms/modal"; | ||
import { SidebarPom } from "src/oss/poms/sidebar"; | ||
import { getUniqueDatasetNameWithPrefix } from "src/oss/utils"; | ||
import { createBlankImage } from "src/shared/media-factory/image"; | ||
|
||
const test = base.extend<{ | ||
grid: GridPom; | ||
modal: ModalPom; | ||
sidebar: SidebarPom; | ||
}>({ | ||
grid: async ({ page, eventUtils }, use) => { | ||
await use(new GridPom(page, eventUtils)); | ||
}, | ||
modal: async ({ page, eventUtils }, use) => { | ||
await use(new ModalPom(page, eventUtils)); | ||
}, | ||
sidebar: async ({ page }, use) => { | ||
await use(new SidebarPom(page)); | ||
}, | ||
}); | ||
|
||
const nestedDynamicGroupsDatasetName = getUniqueDatasetNameWithPrefix( | ||
"nested-dynamic-groups" | ||
); | ||
|
||
function* orderGenerator() { | ||
while (true) { | ||
yield 1; | ||
yield 1; | ||
yield 2; | ||
yield 2; | ||
} | ||
} | ||
|
||
const orderGen = orderGenerator(); | ||
|
||
// file format: g{groupNum}sl{sliceName}sc{sceneNum}o{orderNum}.png | ||
const imagePaths = [1, 2, 3, 4] | ||
.map((groupNum, idx) => [ | ||
`g${groupNum}sl1sc${idx > 1 ? "2" : "1"}`, | ||
`g${groupNum}sl2sc${idx > 1 ? "2" : "1"}`, | ||
]) | ||
.flat() | ||
.map((imgName) => `/tmp/${imgName}o${orderGen.next().value}.png`); | ||
|
||
test.beforeAll(async ({ fiftyoneLoader }) => { | ||
// create a dataset with two groups, each with 2 image samples | ||
const imageCreatePromises = imagePaths.map( | ||
async (imgPath) => | ||
await createBlankImage({ | ||
outputPath: imgPath, | ||
width: 100, | ||
height: 100, | ||
watermarkString: imgPath.split("/").pop().split(".")[0], | ||
}) | ||
); | ||
|
||
await Promise.all(imageCreatePromises); | ||
|
||
const pythonCode = ` | ||
import fiftyone as fo | ||
import json | ||
dataset = fo.Dataset("${nestedDynamicGroupsDatasetName}") | ||
dataset.persistent = True | ||
samples = [] | ||
image_paths = ${JSON.stringify(imagePaths)} | ||
for i in range(1, 5): | ||
group = fo.Group() | ||
group_id = i | ||
file1 = image_paths[(group_id - 1) * 2] | ||
file2 = image_paths[(group_id - 1) * 2 + 1] | ||
# extract scene_id from filename | ||
file1_name = file1.split("/").pop().split(".")[0] | ||
file2_name = file2.split("/").pop().split(".")[0] | ||
scene_id = file1_name[-3] | ||
order_id_1 = file1_name[-1] | ||
order_id_2 = file2_name[-1] | ||
s1 = fo.Sample(filepath=file1, group=group.element("1"), scene_key=scene_id, order_key=order_id_1) | ||
s2 = fo.Sample(filepath=file2, group=group.element("2"), scene_key=scene_id, order_key=order_id_2) | ||
samples.extend([s1, s2]) | ||
dataset.add_samples(samples) | ||
`; | ||
await fiftyoneLoader.executePythonCode(pythonCode); | ||
}); | ||
|
||
test.beforeEach(async ({ page, fiftyoneLoader }) => { | ||
await fiftyoneLoader.waitUntilGridVisible( | ||
page, | ||
nestedDynamicGroupsDatasetName | ||
); | ||
}); | ||
|
||
test(`dynamic groups of groups works`, async ({ grid, modal, sidebar }) => { | ||
await grid.assert.isLookerCountEqualTo(4); | ||
await grid.assert.isEntryCountTextEqualTo("4 groups with slice"); | ||
|
||
await sidebar.clickFieldCheckbox("scene_key"); | ||
await sidebar.clickFieldCheckbox("order_key"); | ||
|
||
await grid.assert.nthSampleHasTagValue(0, "order_key", "1"); | ||
await grid.assert.nthSampleHasTagValue(1, "order_key", "2"); | ||
await grid.assert.nthSampleHasTagValue(2, "order_key", "1"); | ||
await grid.assert.nthSampleHasTagValue(3, "order_key", "2"); | ||
|
||
const groupByRefresh = grid.getWaitForGridRefreshPromise(); | ||
await grid.actionsRow.toggleCreateDynamicGroups(); | ||
await grid.actionsRow.groupBy("scene_key", "order_key"); | ||
await groupByRefresh; | ||
|
||
const gridRefreshPromiseSetRenderFramesAsVideo = | ||
grid.getWaitForGridRefreshPromise(); | ||
await grid.actionsRow.toggleDisplayOptions(); | ||
await grid.actionsRow.displayActions.toggleRenderFramesAsVideo(); | ||
await gridRefreshPromiseSetRenderFramesAsVideo; | ||
|
||
await grid.assert.isLookerCountEqualTo(2); | ||
await grid.assert.isEntryCountTextEqualTo("2 groups with slice"); | ||
|
||
await grid.assert.nthSampleHasTagValue(0, "scene_key", "1"); | ||
await grid.assert.nthSampleHasTagValue(1, "scene_key", "2"); | ||
await grid.assert.nthSampleHasTagValue(0, "order_key", "1"); | ||
await grid.assert.nthSampleHasTagValue(1, "order_key", "1"); | ||
|
||
await grid.openFirstSample(); | ||
await modal.waitForSampleLoadDomAttribute(); | ||
|
||
await modal.sidebar.assert.verifySidebarEntryTexts({ | ||
scene_key: "1", | ||
order_key: "1", | ||
}); | ||
await modal.video.playUntilFrames("2 / 2", true); | ||
|
||
await modal.sidebar.assert.verifySidebarEntryTexts({ | ||
scene_key: "1", | ||
order_key: "2", | ||
}); | ||
await modal.navigateNextSample(); | ||
|
||
await modal.sidebar.assert.verifySidebarEntryTexts({ | ||
scene_key: "2", | ||
order_key: "1", | ||
}); | ||
|
||
await modal.video.playUntilFrames("2 / 2", true); | ||
|
||
await modal.sidebar.assert.verifySidebarEntryTexts({ | ||
scene_key: "2", | ||
// todo: investigate why this is failing intermittently :/ | ||
// order_key: "2", | ||
}); | ||
}); |