@geode/opengeodeweb-front 12.2.0-rc.3 → 12.2.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,11 +40,18 @@ function mapRect(rect: Rect, latestImage: DrawableImage, canvasRect: DOMRect): R
40
40
  };
41
41
  }
42
42
 
43
- function sampleMinBrightness(
43
+ // Darkest and brightest pixels under the rect: dark text has to stay readable over the first, light text over
44
+ // The second
45
+ interface BrightnessRange {
46
+ darkest: number;
47
+ brightest: number;
48
+ }
49
+
50
+ function sampleBrightnessRange(
44
51
  ctx: CanvasRenderingContext2D,
45
52
  image: DrawableImage,
46
53
  relRect: RelativeRect,
47
- ): number {
54
+ ): BrightnessRange {
48
55
  ctx.drawImage(
49
56
  image,
50
57
  Math.max(0, relRect.relX),
@@ -57,14 +64,14 @@ function sampleMinBrightness(
57
64
  SAMPLE_SIZE,
58
65
  );
59
66
  const { data } = ctx.getImageData(0, 0, SAMPLE_SIZE, SAMPLE_SIZE);
60
- let minBrightness = 1;
67
+ let darkest = 1;
68
+ let brightest = 0;
61
69
  for (let i = 0; i < TOTAL_CHANNELS; i += RGBA_CHANNELS) {
62
70
  const brightness = ((data[i] ?? 0) + (data[i + 1] ?? 0) + (data[i + 2] ?? 0)) / (3 * RGB_MAX);
63
- if (brightness < minBrightness) {
64
- minBrightness = brightness;
65
- }
71
+ darkest = Math.min(darkest, brightness);
72
+ brightest = Math.max(brightest, brightness);
66
73
  }
67
- return minBrightness;
74
+ return { darkest, brightest };
68
75
  }
69
76
 
70
77
  // Brightness of the scene background a reset viewer draws, for as long as no viewer image can be sampled
@@ -73,11 +80,16 @@ function defaultBackgroundBrightness(): number {
73
80
  return (red + green + blue) / (3 * RGB_MAX);
74
81
  }
75
82
 
76
- function computeAverageBrightness(rect: Rect, options: BrightnessOptions): number {
83
+ function defaultBackgroundRange(): BrightnessRange {
84
+ const brightness = defaultBackgroundBrightness();
85
+ return { darkest: brightness, brightest: brightness };
86
+ }
87
+
88
+ function computeBrightnessRange(rect: Rect, options: BrightnessOptions): BrightnessRange {
77
89
  const { latestImage, offscreenCtx, offscreenCanvas } = options;
78
90
  const { genericRenderWindow } = useHybridViewerCore();
79
91
  if (!latestImage || !offscreenCtx || !offscreenCanvas || !genericRenderWindow.value) {
80
- return defaultBackgroundBrightness();
92
+ return defaultBackgroundRange();
81
93
  }
82
94
  // oxlint-disable-next-line no-unsafe-assignment -- vtk.js has no types for getApiSpecificRenderWindow(); narrowed below.
83
95
  const webGLRenderWindow = genericRenderWindow.value.getApiSpecificRenderWindow();
@@ -87,21 +99,21 @@ function computeAverageBrightness(rect: Rect, options: BrightnessOptions): numbe
87
99
  };
88
100
  const canvas = apiSpecificRenderWindow.getCanvas();
89
101
  if (canvas === undefined || canvas === null) {
90
- return defaultBackgroundBrightness();
102
+ return defaultBackgroundRange();
91
103
  }
92
104
  if (rect.width <= 0 || rect.height <= 0) {
93
- return defaultBackgroundBrightness();
105
+ return defaultBackgroundRange();
94
106
  }
95
107
  const relRect = mapRect(rect, latestImage, canvas.getBoundingClientRect());
96
108
  if (relRect.relW <= 0 || relRect.relH <= 0) {
97
- return defaultBackgroundBrightness();
109
+ return defaultBackgroundRange();
98
110
  }
99
111
  offscreenCanvas.width = SAMPLE_SIZE;
100
112
  offscreenCanvas.height = SAMPLE_SIZE;
101
113
  try {
102
- return sampleMinBrightness(offscreenCtx, latestImage, relRect);
114
+ return sampleBrightnessRange(offscreenCtx, latestImage, relRect);
103
115
  } catch {
104
- return defaultBackgroundBrightness();
116
+ return defaultBackgroundRange();
105
117
  }
106
118
  }
107
119
  function createOffscreenCanvas(): HTMLCanvasElement | undefined {
@@ -113,7 +125,7 @@ function createOffscreenCanvas(): HTMLCanvasElement | undefined {
113
125
 
114
126
  function useHybridViewerBrightness(): {
115
127
  latestImage: Ref<DrawableImage | undefined>;
116
- getAverageBrightness: (rect: Rect) => number;
128
+ getBrightnessRange: (rect: Rect) => BrightnessRange;
117
129
  } {
118
130
  const latestImage = ref<DrawableImage | undefined>(undefined);
119
131
  const offscreenCanvas: HTMLCanvasElement | undefined = createOffscreenCanvas();
@@ -122,8 +134,8 @@ function useHybridViewerBrightness(): {
122
134
  willReadFrequently: true,
123
135
  }) ?? undefined)
124
136
  : undefined;
125
- function getAverageBrightness(rect: Rect): number {
126
- return computeAverageBrightness(rect, {
137
+ function getBrightnessRange(rect: Rect): BrightnessRange {
138
+ return computeBrightnessRange(rect, {
127
139
  latestImage: latestImage.value,
128
140
  offscreenCtx,
129
141
  offscreenCanvas,
@@ -131,7 +143,12 @@ function useHybridViewerBrightness(): {
131
143
  }
132
144
  return {
133
145
  latestImage,
134
- getAverageBrightness,
146
+ getBrightnessRange,
135
147
  };
136
148
  }
137
- export { computeAverageBrightness, defaultBackgroundBrightness, useHybridViewerBrightness };
149
+ export {
150
+ type BrightnessRange,
151
+ computeBrightnessRange,
152
+ defaultBackgroundBrightness,
153
+ useHybridViewerBrightness,
154
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geode/opengeodeweb-front",
3
- "version": "12.2.0-rc.3",
3
+ "version": "12.2.0-rc.4",
4
4
  "description": "OpenSource Vue/Nuxt/Pinia/Vuetify framework for web applications",
5
5
  "homepage": "https://github.com/Geode-solutions/OpenGeodeWeb-Front",
6
6
  "bugs": {
@@ -62,6 +62,10 @@ async function toggleSearchObjects(window: Page): Promise<void> {
62
62
 
63
63
  async function fillSearchQuery(window: Page, query: string, tree: Locator): Promise<void> {
64
64
  const searchInput = tree.getByTestId("searchObjectsInput").locator("input");
65
+ // An empty search folds back once the toolbar is left: open it again
66
+ if (!(await searchInput.isVisible())) {
67
+ await tree.getByTestId("searchObjectsButton").click();
68
+ }
65
69
  await searchInput.fill(query);
66
70
  await moveMouseOutOfTheWay(window);
67
71
  await waitForActionSettled(window);
@@ -0,0 +1,78 @@
1
+ import type { Locator, Page } from "@playwright/test";
2
+ import { getModelComponentsObjectTree } from "./model_components_object_tree";
3
+ import { moveMouseOutOfTheWay } from "#browser_helpers/app_interaction";
4
+ import { waitForActionSettled } from "#browser_helpers/wait_for_action_settled";
5
+
6
+ // The model trees in the activity bar: a button per open model tree, and one for them all
7
+ const DRAG_STEPS = 10;
8
+
9
+ function getModelTreeToggles(window: Page): Locator {
10
+ return window.getByTestId("modelTreeToggle");
11
+ }
12
+
13
+ function getModelTreeRows(window: Page): Locator {
14
+ return getModelComponentsObjectTree(window).getByTestId("treeRowWrapper");
15
+ }
16
+
17
+ async function clickModelTreeBarButton(window: Page, locator: Locator): Promise<void> {
18
+ await locator.click();
19
+ await moveMouseOutOfTheWay(window);
20
+ await waitForActionSettled(window);
21
+ }
22
+
23
+ // The colors of the model trees, in the order of their panels and of their buttons in the activity bar
24
+ async function getModelTreePanelColors(window: Page): Promise<string[]> {
25
+ const colors = await window.locator(".tree-box").evaluateAll((boxes) =>
26
+ boxes
27
+ .map((box) => {
28
+ if (box instanceof HTMLElement) {
29
+ return box.style.getPropertyValue("--tree-box-accent");
30
+ }
31
+ return "";
32
+ })
33
+ .filter((color) => color !== ""),
34
+ );
35
+ return colors;
36
+ }
37
+
38
+ async function getModelTreeButtonColors(window: Page): Promise<string[]> {
39
+ const colors = await getModelTreeToggles(window).evaluateAll((toggles) =>
40
+ toggles.map((toggle) => {
41
+ if (toggle instanceof HTMLElement) {
42
+ return toggle.style.getPropertyValue("--model-tree-color");
43
+ }
44
+ return "";
45
+ }),
46
+ );
47
+ return colors;
48
+ }
49
+
50
+ // Drags a model button over another one with the mouse, as the native drag and drop needs
51
+ async function dragModelTreeButton(
52
+ window: Page,
53
+ fromIndex: number,
54
+ toIndex: number,
55
+ ): Promise<void> {
56
+ const source = await getModelTreeToggles(window).nth(fromIndex).boundingBox();
57
+ const target = await getModelTreeToggles(window).nth(toIndex).boundingBox();
58
+ if (source === null || target === null) {
59
+ throw new Error("The model buttons are not displayed.");
60
+ }
61
+ await window.mouse.move(source.x + source.width / 2, source.y + source.height / 2);
62
+ await window.mouse.down();
63
+ await window.mouse.move(target.x + target.width / 2, target.y + target.height / 2, {
64
+ steps: DRAG_STEPS,
65
+ });
66
+ await window.mouse.up();
67
+ await moveMouseOutOfTheWay(window);
68
+ await waitForActionSettled(window);
69
+ }
70
+
71
+ export {
72
+ clickModelTreeBarButton,
73
+ dragModelTreeButton,
74
+ getModelTreeButtonColors,
75
+ getModelTreePanelColors,
76
+ getModelTreeRows,
77
+ getModelTreeToggles,
78
+ };
@@ -40,7 +40,7 @@ const MUTATION_QUIET_MS = 250;
40
40
  const MUTATION_POLL_INTERVAL_MS = 20;
41
41
 
42
42
  async function waitForDomSettled(window: Page, budgetMs: number): Promise<void> {
43
- await window.evaluate((quietMs: number) => {
43
+ await window.evaluate(() => {
44
44
  globalThis.e2eLastMutationAt = performance.now();
45
45
  if (!globalThis.e2eMutationObserver) {
46
46
  const observer = new MutationObserver(() => {
@@ -49,8 +49,7 @@ async function waitForDomSettled(window: Page, budgetMs: number): Promise<void>
49
49
  observer.observe(document.body, { attributes: true, childList: true, subtree: true });
50
50
  globalThis.e2eMutationObserver = observer;
51
51
  }
52
- void quietMs;
53
- }, MUTATION_QUIET_MS);
52
+ });
54
53
 
55
54
  await window
56
55
  .waitForFunction(
@@ -25,7 +25,8 @@ import type { SuiteRuntime } from "#browser_helpers/suite_runtime";
25
25
  // Constants
26
26
  const structuralModelFilename = "test.og_strm";
27
27
  const collectionTypeRowName = "ModelBoundaries";
28
- const collectionRowName = "019ea684-373";
28
+ // Start of the collection id, still shown once the label is truncated in the middle
29
+ const collectionRowName = "019ea684-37";
29
30
  const vertexAttributeName = "test_vertex";
30
31
 
31
32
  // Shared with the apps built on this layer: each one runs it with its own test fixture and data loader
@@ -7,6 +7,7 @@ import { expect } from "@playwright/test";
7
7
  import {
8
8
  checkFilterCategory,
9
9
  copyTreeRowId,
10
+ expandGeodeObjectTypeInTree,
10
11
  fillSearchQuery,
11
12
  getTreeRowId,
12
13
  hideObjectInTree,
@@ -88,6 +89,8 @@ function registerTests({ test, loadTestDatas }: SuiteRuntime): void {
88
89
 
89
90
  test("search by id", async ({ window, screenshotMask }) => {
90
91
  const mainObjectTree = getMainObjectTree(window);
92
+ // Clearing the search folded the groups back as they were before it
93
+ await expandGeodeObjectTypeInTree(window, brepGeodeObjectType, mainObjectTree);
91
94
  const brepLabel = mainObjectTree
92
95
  .locator('[data-testid^="treeRow-"]', { hasText: "test" })
93
96
  .first();
@@ -0,0 +1,125 @@
1
+ // Third party imports
2
+ import { expect } from "@playwright/test";
3
+
4
+ // Local imports
5
+ import {
6
+ brepGeodeObjectType,
7
+ defaultDataName,
8
+ structuralModelGeodeObjectType,
9
+ } from "#browser_helpers/constants";
10
+ import {
11
+ clickModelTreeBarButton,
12
+ dragModelTreeButton,
13
+ getModelTreeButtonColors,
14
+ getModelTreePanelColors,
15
+ getModelTreeRows,
16
+ getModelTreeToggles,
17
+ } from "#browser_helpers/object_trees/model_tree_bar";
18
+ import {
19
+ collapseMainObjectTreeGroup,
20
+ expandMainObjectTree,
21
+ getMainObjectTree,
22
+ } from "#browser_helpers/object_trees/main_object_tree";
23
+ import {
24
+ expandMeshComponentType,
25
+ getModelComponentsObjectTree,
26
+ openModelComponentsTree,
27
+ } from "#browser_helpers/object_trees/model_components_object_tree";
28
+ import { fillSearchQuery } from "#browser_helpers/object_trees/common";
29
+ import { moveMouseOutOfTheWay } from "#browser_helpers/app_interaction";
30
+
31
+ import type { SuiteRuntime } from "#browser_helpers/suite_runtime";
32
+
33
+ // Constants
34
+ const brepFilename = "test.og_brep";
35
+ const structuralModelFilename = "test.og_strm";
36
+
37
+ // Shared with the apps built on this layer: each one runs it with its own test fixture and data loader
38
+ function registerTests({ test, loadTestDatas }: SuiteRuntime): void {
39
+ test.describe.configure({ mode: "serial" });
40
+
41
+ let surfaceRows = 0;
42
+
43
+ test("open a model tree with its surfaces expanded", async ({ window }) => {
44
+ test.slow();
45
+ await loadTestDatas(window, [brepFilename]);
46
+ await loadTestDatas(window, [structuralModelFilename]);
47
+ await expandMainObjectTree(window);
48
+ await openModelComponentsTree(window, brepGeodeObjectType, defaultDataName);
49
+ await expandMeshComponentType(window, "Surfaces");
50
+ await moveMouseOutOfTheWay(window);
51
+ surfaceRows = await getModelTreeRows(window).count();
52
+ await expect(getModelTreeToggles(window)).toHaveCount(1);
53
+ });
54
+
55
+ test("collapse the model tree from its button", async ({ window }) => {
56
+ await clickModelTreeBarButton(window, window.getByTestId("toggleModelTreeButton"));
57
+ await expect(getModelComponentsObjectTree(window)).toHaveCount(0);
58
+ await expect(getModelTreeToggles(window)).toHaveCount(1);
59
+ });
60
+
61
+ test("show the model tree again with its state", async ({ window }) => {
62
+ await clickModelTreeBarButton(window, window.getByTestId("toggleModelTreeButton"));
63
+ await expect(getModelComponentsObjectTree(window)).toHaveCount(1);
64
+ await expect(getModelTreeRows(window)).toHaveCount(surfaceRows);
65
+ });
66
+
67
+ test("open a second model tree", async ({ window }) => {
68
+ await openModelComponentsTree(window, structuralModelGeodeObjectType, defaultDataName);
69
+ await expect(getModelComponentsObjectTree(window)).toHaveCount(2);
70
+ await expect(window.getByTestId("toggleAllModelTreesButton")).toBeVisible();
71
+ });
72
+
73
+ test("collapse all the model trees", async ({ window }) => {
74
+ await clickModelTreeBarButton(window, window.getByTestId("toggleAllModelTreesButton"));
75
+ await expect(getModelComponentsObjectTree(window)).toHaveCount(0);
76
+ });
77
+
78
+ test("show all the model trees", async ({ window }) => {
79
+ await clickModelTreeBarButton(window, window.getByTestId("toggleAllModelTreesButton"));
80
+ await expect(getModelComponentsObjectTree(window)).toHaveCount(2);
81
+ });
82
+
83
+ test("reorder the model trees from their buttons", async ({ window }) => {
84
+ const before = await getModelTreePanelColors(window);
85
+ await dragModelTreeButton(window, 1, 0);
86
+ await expect
87
+ .poll(async () => {
88
+ const colors = await getModelTreePanelColors(window);
89
+ return colors;
90
+ })
91
+ .toStrictEqual(before.toReversed());
92
+ expect(await getModelTreeButtonColors(window)).toStrictEqual(before.toReversed());
93
+ });
94
+
95
+ test("the search takes the keyboard as it opens", async ({ window }) => {
96
+ const mainObjectTree = getMainObjectTree(window);
97
+ await collapseMainObjectTreeGroup(window, brepGeodeObjectType);
98
+ await mainObjectTree.getByTestId("searchObjectsButton").click();
99
+ for (const key of ["t", "e", "s"]) {
100
+ // oxlint-disable-next-line no-await-in-loop -- one key after the other
101
+ await window.keyboard.press(key);
102
+ }
103
+ await expect(mainObjectTree.getByTestId("searchObjectsInput").locator("input")).toHaveValue(
104
+ "tes",
105
+ );
106
+ });
107
+
108
+ test("clearing the search folds the groups back", async ({ window }) => {
109
+ const mainObjectTree = getMainObjectTree(window);
110
+ await fillSearchQuery(window, "", mainObjectTree);
111
+ await expect(
112
+ mainObjectTree.getByTestId("treeRowWrapper").filter({ hasText: defaultDataName }),
113
+ ).toHaveCount(1);
114
+ });
115
+
116
+ test("leaving an empty search folds it back", async ({ window }) => {
117
+ const searchInput = getMainObjectTree(window)
118
+ .getByTestId("searchObjectsInput")
119
+ .locator("input");
120
+ await searchInput.blur();
121
+ await expect(searchInput).toBeHidden();
122
+ });
123
+ }
124
+
125
+ export { registerTests };