Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor View Tests #1564

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

thecoolwinter
Copy link
Collaborator

@thecoolwinter thecoolwinter commented Jan 15, 2024

Description

Creates tests for the editor view, this is a prerequisite PR for the fix for #1545. This also adds back a few tests that were previously removed, and adds content to the CodeEditUITests target. I've also added a few helper functions for future UI tests that may require snapshot testing or a test workspace to use.

This PR now removes the UITests target. This should be added back in the future when a solution can be found for our test runner. That future PR can be considered a completion of this PR, but this one still solves a major issue with our tests right now.

It's also important to note the separation between tests. There's tests for the editor view in both the CodeEditTests target and the CodeEditUITests target. The CodeEditTests target performs tests that can be done without user interaction. For example, creating an editor layout with a certain selection or split layout is done in this target. However for testing the focus button and that focusing a tab correctly displays in a workspace environment, the CodeEditUITests target is used as it can perform interaction.

I've also added small helpers in the CodeEditUITests target to do two things:
- Disable sandboxing in the UI Testing app (to allow snapshots to be saved and accessed)
- Create a consistent screenshot of an element query (often the snapshot method returns inconsistently sized images that appear exactly the same but are different).

Also in this PR:

  • Misc additions to various components to add accessibility identifiers to hopefully improve UI Testing readability in the future. These (for the most part) are not visible to the end user. With the exception of a few elements that needed an accessibility label.
  • Created an extension on CommandLine for checking if the app is being run in debug mode. These checks are only enabled in a debug build. These options should be used in interactive UI tests when they're added back.
  • While making that extension, moved some code into an extension from AppDelegate to clean it up.
  • Added back WelcomeModule tests

A note about the previous draft status

Instead of waiting for a (as of writing) 3 year old PR to be merged into the snapshot testing library, I've written a small wrapper that generates a consistent image for an NSView or SwiftUI View regardless of what resolution a machine is running on. This results in snapshots that are 1/2 the quality as they were before, but will be deterministic moving forward.

Related Issues

Checklist

  • I read and understood the contributing guide as well as the code of conduct
  • The issues this PR addresses are related to each other
  • My changes generate no new warnings
  • My code builds and runs on my machine
  • My changes are all related to the related issue above
  • I documented my code

Screenshots

No UI Changes

@thecoolwinter thecoolwinter marked this pull request as draft January 15, 2024 06:03
@thecoolwinter
Copy link
Collaborator Author

After further investigation, there's some issues with snapshotting NSViews with SwiftUI views. The reason tests are failing right now on this PR is the test runner runs at a different resolution than my machine. To fix this we need a different method for snapshotting NSViews. Either this could be merged into swift-snapshot-testing (or something like it) or we fork that repository and add the necessary requirements for our tests.

@thecoolwinter thecoolwinter added the help wanted Extra attention is needed label Jan 16, 2024
@thecoolwinter thecoolwinter removed the help wanted Extra attention is needed label May 1, 2024
@thecoolwinter
Copy link
Collaborator Author

Got a few tests passing 💪 I'll be able to pick this up in a few days

@thecoolwinter thecoolwinter added the help wanted Extra attention is needed label May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant