Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/learning-snippets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"@itwin/presentation-frontend": "^5.7.0",
"@itwin/presentation-hierarchies": "^1.7.9",
"@itwin/presentation-shared": "^1.2.8",
"@itwin/presentation-testing": "^5.4.14",
"@itwin/property-grid-react": "workspace:*",
"@itwin/quantity-formatting-react": "workspace:*",
"@itwin/tree-widget-react": "workspace:*",
Expand All @@ -56,12 +55,12 @@
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-react": "^7.37.5",
"eslint-plugin-unused-imports": "^4.3.0",
"fast-xml-parser": "^5.7.0",
"happy-dom": "^20.8.9",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"rimraf": "^6.1.2",
"sass-embedded": "1.98.0",
"test-utilities": "workspace:*",
"typescript": "~5.9.3",
"vitest": "^4.1.2"
},
Expand Down
85 changes: 38 additions & 47 deletions apps/learning-snippets/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions apps/learning-snippets/scripts/linkWorkspaceDeps.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const packages = [
name: "@itwin/quantity-formatting-react",
dir: "quantity-formatting",
},
{
name: "test-utilities",
dir: "test-utilities",
},
];

linkPackages();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { PropertyGridComponent } from "@itwin/property-grid-react";
// __PUBLISH_EXTRACT_END__
import { cleanup, queryByText, render, waitFor } from "@testing-library/react";
import { userEvent } from "@testing-library/user-event";
import { buildIModel, insertPhysicalElement, insertPhysicalModelWithPartition, insertSpatialCategory } from "../../utils/IModelUtils.js";
import { insertPhysicalElement, insertPhysicalModelWithPartition, insertSpatialCategory } from "test-utilities";
import { buildIModel } from "../../utils/IModelUtils.js";
import { initializeLearningSnippetsTests, terminateLearningSnippetsTests } from "../../utils/InitializationUtils.js";
import { PropertyGridTestUtils } from "../../utils/PropertyGridTestUtils.js";

Expand All @@ -36,14 +37,14 @@ describe("Property grid", () => {
});

it("renders context menu item", async () => {
const imodel = await buildIModel(async (builder) => {
const physicalModel = insertPhysicalModelWithPartition({ builder, codeValue: "TestPhysicalModel" });
const category = insertSpatialCategory({ builder, codeValue: "Test SpatialCategory" });
insertPhysicalElement({ builder, modelId: physicalModel.id, categoryId: category.id });
const { imodelConnection, ...keys } = await buildIModel(async (imodel) => {
const physicalModel = insertPhysicalModelWithPartition({ imodel, codeValue: "TestPhysicalModel" });
const category = insertSpatialCategory({ imodel, codeValue: "Test SpatialCategory" });
insertPhysicalElement({ imodel, modelId: physicalModel.id, categoryId: category.id });
return { category };
});
const user = userEvent.setup();
vi.spyOn(UiFramework, "getIModelConnection").mockReturnValue(imodel.imodel);
vi.spyOn(UiFramework, "getIModelConnection").mockReturnValue(imodelConnection);

// __PUBLISH_EXTRACT_START__ PropertyGrid.ExampleContextMenuItem
function ExampleContextMenuItem(props: ContextMenuItemProps) {
Expand All @@ -68,7 +69,7 @@ describe("Property grid", () => {
}
// __PUBLISH_EXTRACT_END__

Presentation.selection.addToSelection("", imodel.imodel, [imodel.category]);
Presentation.selection.addToSelection("", imodelConnection, [keys.category]);

using _ = { [Symbol.dispose]: cleanup };
const { baseElement, getAllByText } = render(<MyPropertyGrid />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { PropertyGridComponent } from "@itwin/property-grid-react";
// __PUBLISH_EXTRACT_END__
import { render, waitFor } from "@testing-library/react";
import { userEvent } from "@testing-library/user-event";
import { buildIModel, insertPhysicalElement, insertPhysicalModelWithPartition, insertSpatialCategory } from "../../utils/IModelUtils.js";
import { insertPhysicalElement, insertPhysicalModelWithPartition, insertSpatialCategory } from "test-utilities";
import { buildIModel } from "../../utils/IModelUtils.js";
import { initializeLearningSnippetsTests, terminateLearningSnippetsTests } from "../../utils/InitializationUtils.js";
import { PropertyGridTestUtils } from "../../utils/PropertyGridTestUtils.js";

Expand All @@ -32,16 +33,14 @@ describe("Property grid", () => {
});

it("renders settings menu item", async () => {
const imodel = (
await buildIModel(async (builder) => {
const physicalModel = insertPhysicalModelWithPartition({ builder, codeValue: "TestPhysicalModel" });
const category = insertSpatialCategory({ builder, codeValue: "Test SpatialCategory" });
insertPhysicalElement({ builder, modelId: physicalModel.id, categoryId: category.id });
return { category };
})
).imodel;
const { imodelConnection } = await buildIModel(async (imodel) => {
const physicalModel = insertPhysicalModelWithPartition({ imodel, codeValue: "TestPhysicalModel" });
const category = insertSpatialCategory({ imodel, codeValue: "Test SpatialCategory" });
insertPhysicalElement({ imodel, modelId: physicalModel.id, categoryId: category.id });
return { category };
});
const user = userEvent.setup();
vi.spyOn(UiFramework, "getIModelConnection").mockReturnValue(imodel);
vi.spyOn(UiFramework, "getIModelConnection").mockReturnValue(imodelConnection);

// __PUBLISH_EXTRACT_START__ PropertyGrid.ExampleSettingsMenuItem
function ExampleSettingsMenuItem() {
Expand Down
29 changes: 15 additions & 14 deletions apps/learning-snippets/src/test/property-grid/Telemetry.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { PropertyGrid, TelemetryContextProvider } from "@itwin/property-grid-rea
// __PUBLISH_EXTRACT_END__
import { act, cleanup, render, waitFor } from "@testing-library/react";
import { userEvent } from "@testing-library/user-event";
import { buildIModel, insertPhysicalElement, insertPhysicalModelWithPartition, insertSpatialCategory } from "../../utils/IModelUtils.js";
import { insertPhysicalElement, insertPhysicalModelWithPartition, insertSpatialCategory } from "test-utilities";
import { buildIModel } from "../../utils/IModelUtils.js";
import { initializeLearningSnippetsTests, terminateLearningSnippetsTests } from "../../utils/InitializationUtils.js";
import { PropertyGridTestUtils } from "../../utils/PropertyGridTestUtils.js";

Expand All @@ -34,13 +35,13 @@ describe("Property grid", () => {
});

it("renders component with feature usage and performance tracking", async () => {
const { imodel, ...keys } = await buildIModel(async (builder) => {
const physicalModel = insertPhysicalModelWithPartition({ builder, codeValue: "TestPhysicalModel" });
const category = insertSpatialCategory({ builder, codeValue: "Test SpatialCategory" });
insertPhysicalElement({ builder, modelId: physicalModel.id, categoryId: category.id });
const { imodelConnection, ...keys } = await buildIModel(async (imodel) => {
const physicalModel = insertPhysicalModelWithPartition({ imodel, codeValue: "TestPhysicalModel" });
const category = insertSpatialCategory({ imodel, codeValue: "Test SpatialCategory" });
insertPhysicalElement({ imodel, modelId: physicalModel.id, categoryId: category.id });
return { category };
});
vi.spyOn(UiFramework, "getIModelConnection").mockReturnValue(imodel);
vi.spyOn(UiFramework, "getIModelConnection").mockReturnValue(imodelConnection);
const logPerformance = vi.fn();
const logUsage = vi.fn();

Expand All @@ -64,7 +65,7 @@ describe("Property grid", () => {
using _ = { [Symbol.dispose]: cleanup };
render(<MyPropertyGrid />);
act(() => {
Presentation.selection.addToSelection("", imodel, [keys.category]);
Presentation.selection.addToSelection("", imodelConnection, [keys.category]);
});
await waitFor(() => {
expect(logUsage).toHaveBeenCalledTimes(3);
Expand All @@ -75,13 +76,13 @@ describe("Property grid", () => {
});

it("renders property grid with telemetry context", async () => {
const { imodel, ...keys } = await buildIModel(async (builder) => {
const physicalModel = insertPhysicalModelWithPartition({ builder, codeValue: "TestPhysicalModel" });
const category = insertSpatialCategory({ builder, codeValue: "Test SpatialCategory" });
insertPhysicalElement({ builder, modelId: physicalModel.id, categoryId: category.id });
const { imodelConnection, ...keys } = await buildIModel(async (imodel) => {
const physicalModel = insertPhysicalModelWithPartition({ imodel, codeValue: "TestPhysicalModel" });
const category = insertSpatialCategory({ imodel, codeValue: "Test SpatialCategory" });
insertPhysicalElement({ imodel, modelId: physicalModel.id, categoryId: category.id });
return { category };
});
vi.spyOn(UiFramework, "getIModelConnection").mockReturnValue(imodel);
vi.spyOn(UiFramework, "getIModelConnection").mockReturnValue(imodelConnection);
const logPerformance = vi.fn();
const logUsage = vi.fn();

Expand All @@ -98,13 +99,13 @@ describe("Property grid", () => {
logUsage(feature);
}}
>
<PropertyGrid imodel={imodel} />
<PropertyGrid imodel={imodelConnection} />
</TelemetryContextProvider>
);
}
// __PUBLISH_EXTRACT_END__

Presentation.selection.addToSelection("", imodel, [keys.category]);
Presentation.selection.addToSelection("", imodelConnection, [keys.category]);

using _ = { [Symbol.dispose]: cleanup };
const user = userEvent.setup();
Expand Down
Loading
Loading