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

[NHS.UK v4] Ensure that all React components are compliant with nhsuk-frontend #68

Open
Tomdango opened this issue Jan 27, 2021 · 1 comment
Labels
chore A boring task, but one that needs doing nonetheless.

Comments

@Tomdango
Copy link
Collaborator

After the upgrade work has been completed, the components in the React components require checking against the nunjucks macros within nhsuk-frontend to make sure that we haven't deviated away from the nhsuk-frontend framework.

@Tomdango Tomdango added the chore A boring task, but one that needs doing nonetheless. label Jan 27, 2021
@jenbutongit
Copy link

Hi @Tomdango - this is a requirement I need to fill too. I wonder if it's worth you suggesting to the team at nhsuk-frontend to implement something like this: https://github.com/alphagov/govuk-frontend/blob/master/package/govuk/components/back-link/fixtures.json

It's essentially just a collection of options in -> html out. Fixtures are used for engineers who aren't using njks (maybe another templating language, or react etc) but can still ensure parity with the njks package.

function BridgeComponent({ href, children, attributes }: props) {
  return (
    <BackLink href={href} {...attributes}>
      {children}
    </BackLink>
  );
}
describe('fixtures', () => {
  fixtures.forEach((fixture, i) => {
    const { options } = fixture;
    const { href, attributes } = options;
    const inner = options.text ?? options.html;
    it(`fixtures - ${i}`, () => {
      const component = shallow(
        <BridgeComponent href={href} attributes={attributes}>
          {inner}
        </BridgeComponent>,
      ).dive();
      expect(component.html()).toContainHTML(fixture.html);
    });
  });
});

BridgeComponent wraps up the component under test so it matches more closely to the njks api, so the options can just be passed in as a prop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore A boring task, but one that needs doing nonetheless.
Projects
None yet
Development

No branches or pull requests

2 participants