Skip to content

Commit

Permalink
[ASL-4279] Update test to account for plurals
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-horton-ho-sas committed Nov 21, 2023
1 parent 56bb06a commit b7bda30
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/acronym/index.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,35 @@ import { render } from 'enzyme';
import Acronym from './';
import dictionary from '@ukhomeoffice/asl-dictionary';

describe('<Acronym />', () => {
Object.keys(dictionary).forEach(key => {
describe('Acronym component', () => {
Object.entries(dictionary)
.filter(([,definition]) => typeof definition === "string")
.forEach(([key, definition]) => {
test(`handles input ${key}`, () => {
const wrapper = render(<Acronym>{key}</Acronym>);
expect(wrapper.attr('title')).toBe(dictionary[key]);
expect(wrapper.attr('title')).toBe(definition);
expect(wrapper.text()).toBe(key);
expect(wrapper.get(0).tagName).toBe('abbr');
});
});

Object.entries(dictionary.plural)
.filter(([,definition]) => typeof definition === "string")
.forEach(([key, definition]) => {
test(`handles input ${key} and outputs a plural definition`, () => {
const wrapper = render(<Acronym usePlural>{key}</Acronym>);
expect(wrapper.attr('title')).toBe(definition);
expect(wrapper.text()).toBe(key);
expect(wrapper.get(0).tagName).toBe('abbr');
});
});

Object.entries(dictionary)
.filter(([key,definition]) => typeof definition === "string" && dictionary.plural[key] === undefined)
.forEach(([key, definition]) => {
test(`handles input ${key} and fallsback to singular when no plural defined`, () => {
const wrapper = render(<Acronym usePlural>{key}</Acronym>);
expect(wrapper.attr('title')).toBe(definition);
expect(wrapper.text()).toBe(key);
expect(wrapper.get(0).tagName).toBe('abbr');
});
Expand Down

0 comments on commit b7bda30

Please sign in to comment.