Antondomashnev / FBSnapshotsViewer

A mac os application that shows the failing snapshot tests from FBSnapshotTestCase
MIT License
224 stars 15 forks source link

Tests fail when macOS set to Dark mode #77

Open babbage opened 5 years ago

babbage commented 5 years ago

The current tests for Dark mode settings in FBSnapshotsViewer are flawed. The test "when settings doesn't contain AppleInterfaceStyle key" always fails on a macOS Mojave machine that is in Dark mode.

This is because Dark mode is set in Apple Global Defaults. The way to override these Global Defaults normally is to set the preferred value for an app in NSUserDefaults.

This override does not work for Dark Mode, however, since Dark Mode is defined by either the key "AppleInterfaceStyle" with a value of "Dark", or the absence of the key "AppleInterfaceStyle". It is therefore not possible to override a system global default that is set to dark through NSUserDefaults, because when you remove the key "AppleInterfaceStyle" from NSUserDefaults the global value is again exposed.

I believe it would be possible to modify FBSnapshotsViewer to recognise a value of "Light" for the key "AppleInterfaceStyle" in NSUserDefaults, which would then enable a configuration of this test that could pass on a machine set to Dark Mode. This could then be overridden in test setup in order to enable both current tests to pass. However, thought I'd post this as an issue for comment before submitting/merging a pull request to do this.