diff --git a/build/build-plugins.js b/build/build-plugins.js index bee6aa51fffd..cc9226c00094 100644 --- a/build/build-plugins.js +++ b/build/build-plugins.js @@ -34,7 +34,7 @@ const bsPlugins = { Alert: path.resolve(__dirname, '../js/src/alert/alert.js'), Button: path.resolve(__dirname, '../js/src/button/button.js'), Carousel: path.resolve(__dirname, '../js/src/carousel/carousel.js'), - Collapse: path.resolve(__dirname, '../js/src/collapse.js'), + Collapse: path.resolve(__dirname, '../js/src/collapse/collapse.js'), Dropdown: path.resolve(__dirname, '../js/src/dropdown.js'), Modal: path.resolve(__dirname, '../js/src/modal.js'), Popover: path.resolve(__dirname, '../js/src/popover.js'), diff --git a/js/index.esm.js b/js/index.esm.js index 4f5058560da7..bb8b7509e656 100644 --- a/js/index.esm.js +++ b/js/index.esm.js @@ -8,7 +8,7 @@ import Alert from './src/alert/alert' import Button from './src/button/button' import Carousel from './src/carousel/carousel' -import Collapse from './src/collapse' +import Collapse from './src/collapse/collapse' import Dropdown from './src/dropdown' import Modal from './src/modal' import Popover from './src/popover' diff --git a/js/index.umd.js b/js/index.umd.js index f3b81377e5a6..56f1a32a7db3 100644 --- a/js/index.umd.js +++ b/js/index.umd.js @@ -8,7 +8,7 @@ import Alert from './src/alert/alert' import Button from './src/button/button' import Carousel from './src/carousel/carousel' -import Collapse from './src/collapse' +import Collapse from './src/collapse/collapse' import Dropdown from './src/dropdown' import Modal from './src/modal' import Popover from './src/popover' diff --git a/js/src/collapse.js b/js/src/collapse/collapse.js similarity index 98% rename from js/src/collapse.js rename to js/src/collapse/collapse.js index 372869b6923e..9cf4f8ece0bf 100644 --- a/js/src/collapse.js +++ b/js/src/collapse/collapse.js @@ -15,11 +15,11 @@ import { makeArray, reflow, typeCheckConfig -} from './util/index' -import Data from './dom/data' -import EventHandler from './dom/eventHandler' -import Manipulator from './dom/manipulator' -import SelectorEngine from './dom/selectorEngine' +} from '../util/index' +import Data from '../dom/data' +import EventHandler from '../dom/eventHandler' +import Manipulator from '../dom/manipulator' +import SelectorEngine from '../dom/selectorEngine' /** * ------------------------------------------------------------------------ diff --git a/js/src/collapse/collapse.spec.js b/js/src/collapse/collapse.spec.js new file mode 100644 index 000000000000..e5ace76e67de --- /dev/null +++ b/js/src/collapse/collapse.spec.js @@ -0,0 +1,58 @@ +import Collapse from './collapse' + +/** Test helpers */ +import { getFixture, clearFixture } from '../../tests/helpers/fixture' + +describe('Collapse', () => { + let fixtureEl + + beforeAll(() => { + fixtureEl = getFixture() + }) + + afterEach(() => { + clearFixture() + }) + + describe('VERSION', () => { + it('should return plugin version', () => { + expect(Collapse.VERSION).toEqual(jasmine.any(String)) + }) + }) + + describe('Default', () => { + it('should return plugin default config', () => { + expect(Collapse.Default).toEqual(jasmine.any(Object)) + }) + }) + + describe('toggle', () => { + it('should call show method if show class is not present', () => { + fixtureEl.innerHTML = '
' + + const collapseEl = fixtureEl.querySelector('div') + const collapse = new Collapse(collapseEl) + + spyOn(collapse, 'show') + + collapse.toggle() + + expect(collapse.show).toHaveBeenCalled() + }) + + it('should call hide method if show class is present', () => { + fixtureEl.innerHTML = '
' + + const collapseEl = fixtureEl.querySelector('.show') + const collapse = new Collapse(collapseEl, { + toggle: false + }) + + spyOn(collapse, 'hide') + + collapse.toggle() + + expect(collapse.hide).toHaveBeenCalled() + }) + }) +})