-
-
Notifications
You must be signed in to change notification settings - Fork 79k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
691 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,5 +44,5 @@ Thumbs.db | |
*.komodoproject | ||
|
||
# Folders to ignore | ||
/js/coverage/ | ||
/coverage/ | ||
/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"root": true, | ||
"extends": [ | ||
"../../.eslintrc.json" | ||
], | ||
"overrides": [ | ||
{ | ||
"files": ["**/*.spec.js"], | ||
"env": { | ||
"jasmine": true | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import Alert from './alert' | ||
import { makeArray, getTransitionDurationFromElement } from '../util/index' | ||
|
||
/** Test helpers */ | ||
import { getFixture, clearFixture } from '../../tests/helpers/fixture' | ||
|
||
describe('Alert', () => { | ||
let fixtureEl | ||
|
||
beforeAll(() => { | ||
fixtureEl = getFixture() | ||
}) | ||
|
||
afterEach(() => { | ||
clearFixture() | ||
}) | ||
|
||
it('should return version', () => { | ||
expect(typeof Alert.VERSION).toEqual('string') | ||
}) | ||
|
||
describe('data-api', () => { | ||
it('should close an alert without instanciate it manually', () => { | ||
fixtureEl.innerHTML = [ | ||
'<div class="alert">', | ||
' <button type="button" data-dismiss="alert">x</button>', | ||
'</div>' | ||
].join('') | ||
|
||
const button = document.querySelector('button') | ||
|
||
button.click() | ||
expect(makeArray(document.querySelectorAll('.alert')).length).toEqual(0) | ||
}) | ||
|
||
it('should close an alert without instanciate it manually with the parent selector', () => { | ||
fixtureEl.innerHTML = [ | ||
'<div class="alert">', | ||
' <button type="button" data-target=".alert" data-dismiss="alert">x</button>', | ||
'</div>' | ||
].join('') | ||
|
||
const button = document.querySelector('button') | ||
|
||
button.click() | ||
expect(makeArray(document.querySelectorAll('.alert')).length).toEqual(0) | ||
}) | ||
}) | ||
|
||
describe('close', () => { | ||
it('should close an alert', done => { | ||
const spy = jasmine.createSpy('spy', getTransitionDurationFromElement) | ||
fixtureEl.innerHTML = '<div class="alert"></div>' | ||
|
||
const alertEl = document.querySelector('.alert') | ||
const alert = new Alert(alertEl) | ||
|
||
alertEl.addEventListener('closed.bs.alert', () => { | ||
expect(makeArray(document.querySelectorAll('.alert')).length).toEqual(0) | ||
expect(spy).not.toHaveBeenCalled() | ||
done() | ||
}) | ||
|
||
alert.close() | ||
}) | ||
|
||
it('should close alert with fade class', done => { | ||
fixtureEl.innerHTML = '<div class="alert fade"></div>' | ||
|
||
const alertEl = document.querySelector('.alert') | ||
const alert = new Alert(alertEl) | ||
|
||
alertEl.addEventListener('transitionend', () => { | ||
expect().nothing() | ||
}) | ||
|
||
alertEl.addEventListener('closed.bs.alert', () => { | ||
expect(makeArray(document.querySelectorAll('.alert')).length).toEqual(0) | ||
done() | ||
}) | ||
|
||
alert.close() | ||
}) | ||
|
||
it('should not remove alert if close event is prevented', done => { | ||
fixtureEl.innerHTML = '<div class="alert"></div>' | ||
|
||
const alertEl = document.querySelector('.alert') | ||
const alert = new Alert(alertEl) | ||
|
||
const endTest = () => { | ||
setTimeout(() => { | ||
expect(alert._removeElement).not.toHaveBeenCalled() | ||
done() | ||
}, 10) | ||
} | ||
|
||
spyOn(alert, '_removeElement') | ||
|
||
alertEl.addEventListener('close.bs.alert', event => { | ||
event.preventDefault() | ||
endTest() | ||
}) | ||
|
||
alertEl.addEventListener('closed.bs.alert', () => { | ||
endTest() | ||
}) | ||
|
||
alert.close() | ||
}) | ||
}) | ||
|
||
describe('dispose', () => { | ||
it('should dispose an alert', () => { | ||
fixtureEl.innerHTML = '<div class="alert"></div>' | ||
|
||
const alertEl = document.querySelector('.alert') | ||
const alert = new Alert(alertEl) | ||
|
||
expect(Alert._getInstance(alertEl)).toBeDefined() | ||
|
||
alert.dispose() | ||
|
||
expect(Alert._getInstance(alertEl)).toBeNull() | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.