This package contains integration tests so that we can properly check the partials exported from ncids-css.
- Run
pnpm run startto run Storybook locally
- Install Docker Desktop
- Ensure Docker Desktop is running
- Open a command prompt
- cd into the
testing/ncids-css-testingfolder - Run
pnpm run startto start the Storybook server - Run
pnpm run backstop:testto run tests locally with Storybook started - Run
pnpm run backstop:openReportto open last test report. - Stop the Storybook server when finished.
- Every test must have an associated Story in
testing/ncids-css/testing/stories/ - For each component, create a new directory using the BEM block name, following rules from The Way
- For each variant, create a new
<variant>.stories.jsxand optionally<variant>.scssfiles - Create a primary story file with its BEM block name containing
- Default export, defining any custom metadata
- Exports for all variant stories
- See an example of the primary story file for more information
- Create a new scenario file, or add to an existing one, in
stories/components/<your-component>/<your-component>.scenarios.js- In each scenario add the following:
storyId- the storybook Id. This will be used to build the URLlabel- Label scenario with<component> <variant> <interaction>- any additional backstopjs options for a test (e.g. selectors)
- In each scenario add the following:
- Run
pnpm run backstop:testto test the new scenarios - Run
pnpm run backstop:referencewith Storybook started to create reference files for new scenarios
These are components we are not addressing yet and need to republish, which are the components under ncids-css/uswds-packages. The idea behind these components is that they are being republished as-is, but do need to be "acceptable" within our theme settings and do need regression tests.
Additionally, the folder structure should parallel the USWDS structure under their packages folder. This helps with identifying changed when upgrading to new versions of the USWDS.
For the purposes of this content the word package refers to a folder under uswds/packages, component refers to a package that starts with usa-, i.e. a USWDS component. We do not see stories for packages starting with uswds-, but this could change in the future.
Copying the USWDS stories over are not exactly the same, but here are some rough steps.
-
Create a folder under
stories/uswds-nativewith the same name as the component underuswds/packages. -
Add an empty src folder.
-
Copy over the
src/contentfolder if it exists. This is usually JSON that gets bound with the twig template to make the html. -
Copy over all
src/**/*.twigfiles, maintaining any folder structures -
Copy over all
src/**/*.stories.jsfiles. Stories.js files are not only direct descendants ofsrc -
Create an
index.scssfile in thesrcfolder with:@use "styles/ncids"; @forward "<COMPONENT_NAME_HERE>";
-
Edit each
*.stories.jsfile to do the following, understanding these are things that differ the most.-
Add the following before any imports
import React from 'react'; import { TestCase } from '../../../../components/test-case';
-
Add the following after all the imports
import css from './index.scss';
-
Modify the title of the
export default {to start withUSWDS/. -
Modify any story exports to use our
<TestCase>component. Story exports look likeexport const Default = Template.bind({});. Where in this exampleDefaultis the "Story" andTemplate.bind({})is the "Template Function". The "Template Function" is a function that optionally takes a JS object and returns an HTML string.- Replace
export const <Story> = <Template Function>;withexport const <Story> = () => <TestCase css={css} html={<Template Function>()} />;- Example
export const Default = Template.bind({});becomesexport const Default = () => <TestCase css={css} html={Template.bind({})()} />; - NOTE: That "Template Function" IS a function, and we need to run it to get the HTML string.
- NOTE: A single
*.stories.jsfile can contain multiple twig templates, so keep that in mind when copy/pasting. These seem to always be namedXxxTemplate.
- Example
- Replace
-
Change how the content is passed to the template. This takes the form of 2 approaches:
- An
argsproperty set on the "Story". (E.g.,Default.args = DefaultContent;)- You just need to pass the
YyyContentvariable onto the "Template Function". e.g.,export const Default = () => <TestCase css={css} html={Template.bind({})(DefaultContent)} />; - Remove the
.argsproperty.
- You just need to pass the
- An
argsTypeproperty. This defines the shape of the object, and the knobs and dials. You need to pass an object to the "Template Function" that matches the shape using the default values.- Change:
To be:Default.args = { restrictedDateStart: { defaultValue: "1995-03-06" }, restrictedDateStart: { defaultValue: "1995-03-15" }, defaultDateStart: { table: {disable: true}, }, defaultDateStart: { table: {disable: true}, } }
export const Default = () => <TestCase css={css} html={Template.bind({})({ restrictedDateStart: "1995-03-06", restrictedDateEnd: "1995-03-15" })} />;
- An
-
Remove the
<story>.argsType -
I would say, leave in the knobs and dials definition in the
export defaultsection. -
Preview the component and add any additional needed imports. The USWDS component package's index.scss only contain what is necessary to show the component. Many times the examples include multiple pieces to show off the components. (This could be that most of the items we are exporting are form pieces)
-
-
To enable javascript, additionally you must:
- Find component export in USWDS, e.g.
usa-in-page-navigationisinPageNavigation - Import uswds component export into the
*.stories.jsfile:
import { <story export here> } from '@uswds-js';
- add import to Story argument:
export default { title: 'USWDS/Components/<Story Title>', args: { behavior: <story export here>, } };
- Find component export in USWDS, e.g.
One final note, some twig templates reference shared templates or other components. We found during the implementation that they sometimes reference components we have excluded, or we did not copy twig for as we have "taken ownership." In some of these cases you might need to tweak things.
A number of stories use templates from the uswds\packages\templates, as well as having stories in that folder. We do not plan on using the stories, but we do want to keep some templates. As such, we need to change out the component templates they are using, specifically with usa-base/includes. This means we need our own versions of those templates. These templates will be stored in @nciocpl/ncids-twig. These templates and in the future, content, can be shared between ncids-js-testing and ncids-css-testing as well.
- Open a command prompt
- cd into the
testing/ncids-css-testingfolder - Run
pnpm run startto start the Storybook server - To update existing files, you must run
npm run backstop:approvewith Storybook started - Review the list of files generated to ensure that it ONLY has modified those you expected.
- Run
pnpm run backstop:testto ensure that the all tests pass. - Stop your Storybook server and commit your changes
- For WSL, preface all
pnpm run backstop:commands withCI=true- e.g.
CI=true pnpm run backstop:reference
- e.g.
BackstopJS ships with scripts that enables several user interaction selectors. These files are located at testing/ncids-css-testing/.backstop/engine-scripts/puppet/. Some of the user actions include:
See Custom scripts to simulate other user actions.
- GitHub Actions will automatically run
pnpm run test:cssfor each push and pull request - Failed jobs will be uploaded as an artifact for review
- Download artifact
- Open html-report/index.html
- Successful jobs will upload the test's
report.jsonfile
- Be sure to link relevant links in PR for designer approval until this process is automated.