Skip to content

chore(playwright): combine test configs for themes and modes#29206

Merged
sean-perkins merged 7 commits intonextfrom
sp/test-configs
Mar 28, 2024
Merged

chore(playwright): combine test configs for themes and modes#29206
sean-perkins merged 7 commits intonextfrom
sp/test-configs

Conversation

@sean-perkins
Copy link
Contributor

Issue number: N/A


What is the current behavior?

Developers are not able to easily add the "ionic" theme to existing test cases, without running the test against both iOS and MD mode:

configs({ themes: ['ios', 'md', 'ionic'] })
// Generates 4 test cases
// - iOS theme on iOS mode
// - MD theme on MD mode
// - Ionic theme on iOS mode
// - Ionic theme on MD mode

With the separation of mode into look and feel, the majority of test cases do not require testing the mode behavior and instead only need to test the visual theme that is applied to the component.

What is the new behavior?

  • Removes the themes option from the configs test generator object.
configs({ modes: ['ios', 'md', 'ionic-md'] })
  • Combines theme and mode into the existing modes test generator object
    • The new options are ionic-ios and ionic-md, to run the Ionic theme against the respective mode.
    • This path was preferred to avoid deprecating and migrating all existing tests.

Does this introduce a breaking change?

  • Yes
  • No

Other information

I do not have a strong preference on the semantics of ionic-ios vs. ios-ionic (theme first vs. mode first). If anyone has an opinion or alternative suggestion, please add a comment.

@sean-perkins sean-perkins requested a review from a team as a code owner March 23, 2024 22:56
@sean-perkins sean-perkins requested review from mapsandapps and removed request for a team March 23, 2024 22:56
@github-actions github-actions bot added the package: core @ionic/core package label Mar 23, 2024
@sean-perkins sean-perkins requested a review from a team March 23, 2024 22:56
Copy link
Contributor

@mapsandapps mapsandapps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One idea for a comment. Implementation is good 👍🏻

if (!isModeValidForTheme(mode, theme)) {
return;
}
if (mode === 'ios' || mode === 'md') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we have a comment elsewhere, but it might be nice to note here that we're ignoring the md-ios and ios-md combos for testing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. Also good to document why we are ignoring those combos

if (!isModeValidForTheme(mode, theme)) {
return;
}
if (mode === 'ios' || mode === 'md') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simplify this (GitHub won't let me make a code suggestion because it would go across deleted lines)

processedModes.forEach((mode) => {
    processedDirection.forEach((direction) => {
      processedPalette.forEach((palette) => {
        const [theme, modeName] = mode.split('-');
        configs.push({ direction, palette, mode: (modeName ?? theme) as Mode, theme: theme as Theme });
      });
    });
  });

In both cases we need to iterate over directions and palettes, so having separate code paths here doesn't really save us much work. For the 'ios' and 'md' cases, modeName will be undefined which is why we fall back to theme setting the mode key in the config object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's probably a way to simplify the types, but I didn't spend too much time thinking about that part.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a slightly different approach, curious what you think: eb9f5d6.

I don't think we should suggest a theme can be a mode: (modeName ?? theme) as Mode. A mode can be a theme (for backwards compatibility), but a theme should not be a mode.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main problem here is we don't know if mode contains either a theme and a mode or a combined mode string ahead of time, so the naming in my original approach is confusing.

What you have works, but it's doing an additional indexOf check which will iterate through the mode input more than we need to.

Perhaps we can have something like this:

const [themeOrCombinedMode, modeName]  = mode.split('-');

const parsedTheme = themeOrCombinedMode as Theme;

// If modeName is undefined then we have a combined mode string, so the first variable is actually the mode
const parsedMode = modeName ?? themeOrCombinedMode as Mode;

This approach avoids the additional iteration through the string.

Co-authored-by: Liam DeBeasi <liamdebeasi@users.noreply.github.com>
@sean-perkins sean-perkins merged commit 5234224 into next Mar 28, 2024
@sean-perkins sean-perkins deleted the sp/test-configs branch March 28, 2024 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants