Skip to content

Add unit tests for captureSavedViewData and createViewState#168

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/create-tests-for-saved-views-react
Draft

Add unit tests for captureSavedViewData and createViewState#168
Copilot wants to merge 3 commits intomasterfrom
copilot/create-tests-for-saved-views-react

Conversation

Copy link

Copilot AI commented Feb 9, 2026

Added comprehensive test coverage for captureSavedViewData and createViewState functions in saved-views-react, following patterns from itwin-saved-views-utilities repository.

Changes

Test Files Created:

  • captureSavedViewData.test.ts - 17 tests covering 3D/2D/Sheet view capture, extension handlers, angle conversion, and edge cases
  • createViewState.test.ts - 24 tests covering view state creation from different data types, visibility settings, and API variants
  • testUtilities.ts - Reusable mocks for IModelConnection, ViewState, and Viewport

Test Coverage:

  • captureSavedViewData.ts: 87.3% statements, 66.23% branches
  • createViewState.ts: 83.62% statements, 64.15% branches
  • All 41 tests passing

Key Test Scenarios:

  • View data extraction from spatial, drawing, and sheet views
  • Extension handler behavior (emphasis elements, per-model category visibility)
  • Model and category visibility settings application
  • ViewState creation with various configuration options
  • Blank iModel and empty default view handling

Tests validate the extraction functions (extractViewDetails3d, extractViewDetails2d) that share similar implementation with itwin-saved-views-utilities.

Example test structure:

it("should capture spatial view data correctly", async () => {
  const iModel = createMockIModelConnection();
  const viewState = createMockSpatialViewState();
  const viewport = createMockViewport(viewState, iModel);

  const result = await captureSavedViewData({ viewport });

  expect(result.viewData.type).toBe("iTwin3d");
  expect(result.viewData.origin).toEqual([0, 0, 0]);
  expect(result.viewData.categories?.enabled).toContain("0x10");
});

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • fonts.googleapis.com
    • Triggering command: /opt/hostedtoolcache/node/24.13.0/x64/bin/node /opt/hostedtoolcache/node/24.13.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/saved-views/saved-views/node_modules/.pnpm/vitest@4.0.16_@types+node@22.13.5_happy-dom@20.1.0_sass@1.85.0_tsx@4.19.3_yaml@2.7.0/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/saved-views/saved-views/node_modules/.pnpm/vitest@4.0.16_@types+node@22.13.5_happy-dom@20.1.0_sass@1.85.0_tsx@4.19.3_yaml@2.7.0/node_modules/vitest/dist/workers/forks.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Create tests for saved-views-react</issue_title>
<issue_description>Need to create react component tests for saved-views-react. Make sure to test the captureSavedViewData and the createViewState. Those tests may be similar to the tests found in the itwin-saved-views-utilities repo, in the src/tests folder, as the extractViewDetails3d functions in saved-views-react and itwin-saved-views-utilities are very similar. The extractViewDetails2d and extractViewDetails functions in those respective repos are also very similar.

Also analyze the test coverage for these newly created tests. Show the test coverage.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@changeset-bot
Copy link

changeset-bot bot commented Feb 9, 2026

⚠️ No Changeset found

Latest commit: c43a7d4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI and others added 2 commits February 9, 2026 23:18
Co-authored-by: hnn0003 <18196761+hnn0003@users.noreply.github.com>
Co-authored-by: hnn0003 <18196761+hnn0003@users.noreply.github.com>
Copilot AI changed the title [WIP] Create tests for saved views react component Add unit tests for captureSavedViewData and createViewState Feb 9, 2026
Copilot AI requested a review from hnn0003 February 9, 2026 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create tests for saved-views-react

2 participants