Skip to content

Commit 479917e

Browse files
committed
test: move state panel locating logic to page objects; add simple checks for values
I implemented it like this: returning a mapping of all such values, as it was easier than finding the neighbour/parent elements of a name with a certain text. My initial idea was to have `expression(expr)` and to work with each of those. TODO(in the longterm future): eventually ensure state-panel-0 used or parametrize TODO: what about non atom/non expanded values? currently limited to simple cases
1 parent 43582f1 commit 479917e

File tree

4 files changed

+70
-6
lines changed

4 files changed

+70
-6
lines changed

src/frontend/ui/state.nim

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,3 @@ method onCompleteMove*(self: StateComponent, response: MoveState) {.async.} =
188188

189189
self.completeMoveIndex += 1
190190
self.data.redraw()
191-

src/frontend/ui/value.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,8 @@ proc atomValueView(self: ValueComponent, valueText: string, expression: cstring,
673673
if not self.uiExpanded(value, expression) or not self.charts.hasKey(expression):
674674
span(class = "value-expanded-text"):
675675
text htmlText
676-
span(class = "value-type"):
677-
text(value.typ.langType)
676+
span(class = "value-type"):
677+
text(value.typ.langType)
678678
else:
679679
switchChartKindView(self.charts[expression])
680680

ui-tests/tests/noir/state.spec.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
readyOnEntryTest as readyOnEntry,
55
ctRun,
66
} from "../lib/ct_helpers";
7+
import { StatePanel } from "../page_objects/state";
78

89
ctRun("noir_example/");
910

@@ -14,7 +15,18 @@ ctRun("noir_example/");
1415

1516
test("state panel loaded initially", async () => {
1617
await readyOnEntry();
17-
await expect(page.locator("#code-state-line-0")).toContainText(
18-
"17 | println(",
19-
);
18+
const statePanel = new StatePanel(page);
19+
await expect(statePanel.codeStateLine()).toContainText("17 | println(");
20+
});
21+
22+
test("state panel supports integer values", async () => {
23+
// await readyOnEntry();
24+
const statePanel = new StatePanel(page);
25+
26+
const values = await statePanel.values();
27+
expect(values.x.text).toBe("0");
28+
expect(values.x.typeText).toBe("Field");
29+
30+
expect(values.y.text).toBe("1");
31+
expect(values.y.typeText).toBe("Field");
2032
});
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* eslint-disable @typescript-eslint/no-magic-numbers */
2+
3+
import type { Locator, Page } from "@playwright/test";
4+
// import { wait, CodetracerTestError } from "../lib/ct_helpers";
5+
6+
export interface StatePanelNamedValue {
7+
text: string;
8+
typeText: string;
9+
}
10+
11+
// TODO: work with specific state panel?
12+
// for now this is assuming a single state panel and
13+
// using global locators
14+
export class StatePanel {
15+
readonly page: Page;
16+
17+
public constructor(page: Page) {
18+
this.page = page;
19+
}
20+
21+
codeStateLine(): Locator {
22+
// TODO: specific state panel? this is a global selector
23+
return this.page.locator("#code-state-line-0");
24+
}
25+
26+
async values(name: string): Promise<Record<string, StatePanelNamedValue>> {
27+
// TODO: what about non-atom/non-expanded?
28+
const valueLocators = await this.page
29+
.locator(".value-expanded-atom-parent")
30+
.all();
31+
32+
const values = {};
33+
for (const valueLocator of valueLocators) {
34+
const rawExpr =
35+
(await valueLocator.locator(".value-name").textContent()) ?? "";
36+
37+
const expr = rawExpr.endsWith(": ")
38+
? rawExpr.slice(0, rawExpr.length - 2)
39+
: "";
40+
41+
if (expr.length > 0) {
42+
values[expr] = {
43+
text: await valueLocator
44+
.locator(".value-expanded-text")
45+
.textContent(),
46+
typeText: await valueLocator.locator(".value-type").textContent(),
47+
};
48+
}
49+
}
50+
51+
return values;
52+
}
53+
}

0 commit comments

Comments
 (0)