import 'mocha' ; import { expect } from 'chai' ; import { NonCollapsing , hasDirective } from '@/presentation/components/Scripts/View/Cards/NonCollapsingDirective' ; const expectedAttributeName = 'data-interaction-does-not-collapse' ; describe ( 'NonCollapsingDirective' , ( ) => { describe ( 'NonCollapsing' , ( ) => { it ( 'adds expected attribute to the element when inserted' , ( ) => { const element = getElementMock ( ) ; NonCollapsing . inserted ( element , undefined , undefined , undefined ) ; expect ( element . hasAttribute ( expectedAttributeName ) ) ; } ) ; } ) ; describe ( 'hasDirective' , ( ) => { it ( 'returns true if the element has expected attribute' , ( ) => { const element = getElementMock ( ) ; element . setAttribute ( expectedAttributeName , undefined ) ; const actual = hasDirective ( element ) ; expect ( actual ) . to . equal ( true ) ; } ) ; it ( 'returns true if the element has a parent with expected attribute' , ( ) => { const parent = getElementMock ( ) ; const element = getElementMock ( ) ; parent . appendChild ( element ) ; element . setAttribute ( expectedAttributeName , undefined ) ; const actual = hasDirective ( element ) ; expect ( actual ) . to . equal ( true ) ; } ) ; it ( 'returns false if nor the element or its parent has expected attribute' , ( ) => { const element = getElementMock ( ) ; const actual = hasDirective ( element ) ; expect ( actual ) . to . equal ( false ) ; } ) ; } ) ; } ) ; function getElementMock ( ) { const element = document . createElement ( 'div' ) ; return element ; }