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

Add Percy visual regression testing (VRT) snapshots for all components #8911

Closed
20 of 56 tasks
tay1orjones opened this issue Jun 15, 2021 · 4 comments
Closed
20 of 56 tasks
Labels
Milestone

Comments

@tay1orjones
Copy link
Member

tay1orjones commented Jun 15, 2021

Summary

In #8282 Cypress was set up for e2e testing and also added the Percy integration to facilitate visual regression testing via snapshots taken in the e2e tests. We need to enable a snapshot for each component, this epic/issue is to track the status of adding a single baseline snapshot for each component.

Process

High level steps for each component:

  1. List in a comment below
  2. Open the PR, ensure percy status check UI shows the component has an associated snapshot
    • This may require approval in the Percy UI

Components

@tay1orjones
Copy link
Member Author

Here's a super barebones template I've been starting from when adding a component-test.e2e.js file for a component that doesn't have one already:

/**
 * Copyright IBM Corp. 2016, 2018
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */

import 'carbon-components/scss/components/component/_component.scss';

import React from 'react';
import { mount } from '@cypress/react';
import { Component } from './Component';

describe('Component', () => {
  beforeEach(() => {
    mount(<Component>sample_text</Component>);
  });

  it('should render', () => {
    cy.findByText(/sample_text/).should('be.visible');

    // snapshots should always be taken _after_ an assertion that
    // a element/component should be visible. This is to ensure
    // the DOM has settled and the element has fully loaded.
    cy.percySnapshot();
  });
});

It's helpful to look at the stories to understand common permutations or configurations of the component to get the component into a "default" state for baseline snapshots.

@tay1orjones
Copy link
Member Author

tay1orjones commented Jul 20, 2021

Here's a guide on what I've been doing to add these:

  1. If the component doesn't have an .e2e file, create one with the template from above.
  2. Modify the sass path, validate it's correct
  3. Modify the component import
  4. Render the component into a default state
    • For this I've been looking at the storybook stories and picking out the most general/simple one and essentially copying it over to the test file.
    • Be sure to render all the different component state/display variants (size props, type/kind props, checked, open/close etc)
  5. Remove any unnecessary code relating to the story (bx/prefix code, extraneous components, state wrappers, etc)
  6. Add some type of unique text content to the component so it's easily queryable for interactions
  7. Modify the 'should render' it block with an appropriate query
  8. Add any additional test blocks for component interaction variants (checked, open/closed, etc)
  9. cd into packages/react and run yarn cypress open-ct
    • this will open the cypress gui in a new instance of chrome where you can select and run tests, and view the UI it's snapshotting and testing against.
  10. Make any modifications needed, save and PR 🎉
  11. Ensure percy status check UI shows the component has an associated snapshot. This may require approval in the Percy UI

@tay1orjones
Copy link
Member Author

Helpful links I've referenced along the way:

@tay1orjones tay1orjones added the epic Special label used by ZenHub for epic functionality label Jul 23, 2021
@tay1orjones tay1orjones added planning: umbrella Umbrella issues, surfaced in Projects views and removed epic Special label used by ZenHub for epic functionality labels Dec 10, 2021
@tay1orjones tay1orjones changed the title Add Percy visual regression testing snapshots for all components Add Percy visual regression testing (VRT) snapshots for all components Dec 10, 2021
@tay1orjones tay1orjones added this to the 2022 Q2 milestone Mar 15, 2022
@tay1orjones
Copy link
Member Author

Closing. We've migrated away from cypress to instead use playwright and added baseline VRT snapshots for all components in #11302

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

1 participant