Skip to content

Commit

Permalink
rewrite collapse unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S committed Apr 3, 2019
1 parent 711a0c5 commit 6d30072
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build/build-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion js/index.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion js/index.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 5 additions & 5 deletions js/src/collapse.js → js/src/collapse/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
* ------------------------------------------------------------------------
Expand Down
58 changes: 58 additions & 0 deletions js/src/collapse/collapse.spec.js
Original file line number Diff line number Diff line change
@@ -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 = '<div></div>'

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 = '<div class="show"></div>'

const collapseEl = fixtureEl.querySelector('.show')
const collapse = new Collapse(collapseEl, {
toggle: false
})

spyOn(collapse, 'hide')

collapse.toggle()

expect(collapse.hide).toHaveBeenCalled()
})
})
})

0 comments on commit 6d30072

Please sign in to comment.