From 8ce280219bed68da06f2978c2e1cf2c51cb63d7c Mon Sep 17 00:00:00 2001 From: rmccar <42928680+rmccar@users.noreply.github.com> Date: Thu, 16 Nov 2023 11:28:04 +0000 Subject: [PATCH] Remove onsCollapsible (#2895) --- src/components/collapsible/_macro.njk | 22 ---- src/components/collapsible/_macro.spec.js | 151 ---------------------- src/components/details/_macro.spec.js | 13 +- 3 files changed, 3 insertions(+), 183 deletions(-) delete mode 100644 src/components/collapsible/_macro.njk delete mode 100644 src/components/collapsible/_macro.spec.js diff --git a/src/components/collapsible/_macro.njk b/src/components/collapsible/_macro.njk deleted file mode 100644 index b063772b64..0000000000 --- a/src/components/collapsible/_macro.njk +++ /dev/null @@ -1,22 +0,0 @@ -{# OnsCollapsible has been superceded by onsDetails and will be deprecated in due course. Please upgrade to use onsDetails. Configuration is unchanged, only the component name and classes have changed name. #} -{% macro onsCollapsible(params) %} - {% from "components/details/_macro.njk" import onsDetails %} - - {% set content = caller() if caller else params.content | safe %} - - {{ - onsDetails({ - "id": params.id, - "classes": params.classes, - "attributes": params.attributes, - "headingAttributes": params.headingAttributes, - "contentAttributes": params.contentAttributes, - "title": params.title, - "titleTag": params.titleTag, - "content": content, - "saveState": params.saveState, - "open": params.open - }) - }} - -{% endmacro %} diff --git a/src/components/collapsible/_macro.spec.js b/src/components/collapsible/_macro.spec.js deleted file mode 100644 index 362d6a9cd9..0000000000 --- a/src/components/collapsible/_macro.spec.js +++ /dev/null @@ -1,151 +0,0 @@ -/** @jest-environment jsdom */ - -import * as cheerio from 'cheerio'; - -import axe from '../../tests/helpers/axe'; -import { renderComponent, templateFaker } from '../../tests/helpers/rendering'; - -const EXAMPLE_COLLAPSIBLE_BASIC = { - id: 'collapsible-id', - title: 'Title for collapsible', - content: 'Content for collapsible', -}; - -describe('macro: collapsible', () => { - it('passes jest-axe checks', async () => { - const $ = cheerio.load(renderComponent('collapsible', EXAMPLE_COLLAPSIBLE_BASIC)); - - const results = await axe($.html()); - expect(results).toHaveNoViolations(); - }); - - it('has the provided `id` attribute', () => { - const $ = cheerio.load(renderComponent('collapsible', EXAMPLE_COLLAPSIBLE_BASIC)); - - expect($('.ons-details').attr('id')).toBe('collapsible-id'); - }); - - it('has additionally provided style classes', () => { - const $ = cheerio.load( - renderComponent('collapsible', { - ...EXAMPLE_COLLAPSIBLE_BASIC, - classes: 'extra-class another-extra-class', - }), - ); - - expect($('.ons-details').hasClass('extra-class')).toBe(true); - expect($('.ons-details').hasClass('another-extra-class')).toBe(true); - }); - - it('has provided title text', () => { - const $ = cheerio.load(renderComponent('collapsible', EXAMPLE_COLLAPSIBLE_BASIC)); - - const titleText = $('.ons-details__title') - .first() - .text() - .trim(); - expect(titleText).toBe('Title for collapsible'); - }); - - it('has title with provided tag override', () => { - const $ = cheerio.load( - renderComponent('collapsible', { - ...EXAMPLE_COLLAPSIBLE_BASIC, - titleTag: 'h4', - }), - ); - - const titleTag = $('.ons-details__title')[0].tagName; - expect(titleTag).toBe('h4'); - }); - - it('has provided content text', () => { - const $ = cheerio.load(renderComponent('collapsible', EXAMPLE_COLLAPSIBLE_BASIC)); - - const titleText = $('.ons-details__content') - .text() - .trim(); - expect(titleText).toEqual(expect.stringContaining('Content for collapsible')); - }); - - it('has additionally provided `attributes`', () => { - const $ = cheerio.load( - renderComponent('collapsible', { - ...EXAMPLE_COLLAPSIBLE_BASIC, - attributes: { - a: 123, - b: 456, - }, - }), - ); - expect($('.ons-details').attr('a')).toBe('123'); - expect($('.ons-details').attr('b')).toBe('456'); - }); - - it('has the correct data attribute when `saveState` is provided', () => { - const $ = cheerio.load( - renderComponent('collapsible', { - ...EXAMPLE_COLLAPSIBLE_BASIC, - saveState: true, - }), - ); - expect($('.ons-details').attr('data-save-state')).toBe('true'); - }); - - it('has the correct data attribute when `open` is provided', () => { - const $ = cheerio.load( - renderComponent('collapsible', { - ...EXAMPLE_COLLAPSIBLE_BASIC, - open: true, - }), - ); - expect($('.ons-details').attr('data-open')).toBe('true'); - }); - - it('has additionally provided `headingAttributes`', () => { - const $ = cheerio.load( - renderComponent('collapsible', { - ...EXAMPLE_COLLAPSIBLE_BASIC, - headingAttributes: { - a: 123, - b: 456, - }, - }), - ); - - expect($('.ons-details__heading').attr('a')).toBe('123'); - expect($('.ons-details__heading').attr('b')).toBe('456'); - }); - - it('has additionally provided `contentAttributes`', () => { - const $ = cheerio.load( - renderComponent('collapsible', { - ...EXAMPLE_COLLAPSIBLE_BASIC, - contentAttributes: { - a: 123, - b: 456, - }, - }), - ); - - expect($('.ons-details__content').attr('a')).toBe('123'); - expect($('.ons-details__content').attr('b')).toBe('456'); - }); - - it('has `chevron` icon', () => { - const faker = templateFaker(); - const iconsSpy = faker.spy('icon'); - faker.renderComponent('collapsible', EXAMPLE_COLLAPSIBLE_BASIC); - - expect(iconsSpy.occurrences[0].iconType).toBe('chevron'); - }); - - it('calls with content', () => { - const $ = cheerio.load(renderComponent('collapsible', { EXAMPLE_COLLAPSIBLE_BASIC }, 'Example content...')); - - const content = $('.ons-details__content') - .text() - .trim(); - expect(content).toEqual(expect.stringContaining('Example content...')); - }); -}); diff --git a/src/components/details/_macro.spec.js b/src/components/details/_macro.spec.js index ecea17bebd..ba7dca9ace 100644 --- a/src/components/details/_macro.spec.js +++ b/src/components/details/_macro.spec.js @@ -40,10 +40,7 @@ describe('macro: details', () => { it('has provided title text', () => { const $ = cheerio.load(renderComponent('details', EXAMPLE_DETAILS_BASIC)); - const titleText = $('.ons-details__title') - .first() - .text() - .trim(); + const titleText = $('.ons-details__title').first().text().trim(); expect(titleText).toBe('Title for details'); }); @@ -62,9 +59,7 @@ describe('macro: details', () => { it('has provided content text', () => { const $ = cheerio.load(renderComponent('details', EXAMPLE_DETAILS_BASIC)); - const titleText = $('.ons-details__content') - .text() - .trim(); + const titleText = $('.ons-details__content').text().trim(); expect(titleText).toEqual(expect.stringContaining('Content for details')); }); @@ -143,9 +138,7 @@ describe('macro: details', () => { it('calls with content', () => { const $ = cheerio.load(renderComponent('details', { EXAMPLE_DETAILS_BASIC }, 'Example content...')); - const content = $('.ons-details__content') - .text() - .trim(); + const content = $('.ons-details__content').text().trim(); expect(content).toEqual(expect.stringContaining('Example content...')); }); });