From dd956be595a500b2fd654faa9c88700851057eb1 Mon Sep 17 00:00:00 2001 From: Ans Date: Wed, 6 Nov 2024 21:06:24 -0500 Subject: [PATCH] Add behavior specs --- cliff.toml | 2 +- .../src/utilities/atomic-helpers.spec.js | 4 +-- .../src/utilities/behavior/behavior.spec.js | 36 +++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 packages/cfpb-design-system/src/utilities/behavior/behavior.spec.js diff --git a/cliff.toml b/cliff.toml index a06ea1dadb..9e2ff468c1 100644 --- a/cliff.toml +++ b/cliff.toml @@ -18,7 +18,7 @@ body = """ {% if previous.version %}\ ## [{{ version | trim_start_matches(pat="v") }}](/compare/{{ previous.version }}..{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} {% else %}\ - ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(timezone="America/New_York", format="%Y-%m-%d") }} {% endif %}\ {% else %}\ ## [unreleased] diff --git a/packages/cfpb-design-system/src/utilities/atomic-helpers.spec.js b/packages/cfpb-design-system/src/utilities/atomic-helpers.spec.js index d813cf38f7..bc085ffdbb 100644 --- a/packages/cfpb-design-system/src/utilities/atomic-helpers.spec.js +++ b/packages/cfpb-design-system/src/utilities/atomic-helpers.spec.js @@ -57,7 +57,7 @@ describe('atomic-helpers', () => { 'Check that element is a DOM node with ' + `class ".${testClass}"`; /** - * + * Mock error function. */ function errFunc() { checkDom(null, testClass); @@ -68,7 +68,7 @@ describe('atomic-helpers', () => { it('should throw an error if element class not found', () => { const errMsg = 'mock-class not found on or in passed DOM node.'; /** - * + * Mock error function. */ function errFunc() { checkDom(componentDom, 'mock-class'); diff --git a/packages/cfpb-design-system/src/utilities/behavior/behavior.spec.js b/packages/cfpb-design-system/src/utilities/behavior/behavior.spec.js new file mode 100644 index 0000000000..592bf9a353 --- /dev/null +++ b/packages/cfpb-design-system/src/utilities/behavior/behavior.spec.js @@ -0,0 +1,36 @@ +import { checkBehaviorDom, behaviorFind } from './behavior.js'; + +let containerDom; + +const HTML_SNIPPET = ` +
+
+`; + +describe('behaviors', () => { + beforeEach(() => { + document.body.innerHTML = HTML_SNIPPET; + containerDom = document.querySelector('#container'); + }); + + describe('.checkBehaviorDom()', () => { + it('should return an HTML element', () => { + expect( + checkBehaviorDom( + containerDom, + 'behavior_flyout-menu_content', + ).getAttribute('data-js-hook'), + ).toBe('behavior_flyout-menu_content'); + }); + }); + + describe('.behaviorFind()', () => { + it('should return an array with two items when selectors are found', () => { + const result = behaviorFind('flyout-menu', containerDom); + expect(result).toBeInstanceOf(NodeList); + expect(result.length).toBe(2); + }); + }); +});