diff --git a/src/acronym/index.spec.jsx b/src/acronym/index.spec.jsx index 062a3bd..a8d4d05 100644 --- a/src/acronym/index.spec.jsx +++ b/src/acronym/index.spec.jsx @@ -3,11 +3,35 @@ import { render } from 'enzyme'; import Acronym from './'; import dictionary from '@ukhomeoffice/asl-dictionary'; -describe('', () => { - 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({key}); - 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({key}); + 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({key}); + expect(wrapper.attr('title')).toBe(definition); expect(wrapper.text()).toBe(key); expect(wrapper.get(0).tagName).toBe('abbr'); });