From b7bda305612e9a0f23c35a99a0fd4c33845d84e3 Mon Sep 17 00:00:00 2001 From: Jeffrey Horton Date: Tue, 21 Nov 2023 12:07:10 +0000 Subject: [PATCH] [ASL-4279] Update test to account for plurals --- src/acronym/index.spec.jsx | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/acronym/index.spec.jsx b/src/acronym/index.spec.jsx index 062a3bd9..a8d4d05f 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'); });