-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
8 changed files
with
126 additions
and
107 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
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,103 @@ | ||
var customInputFile = [ | ||
'<div class="custom-file">', | ||
' <input type="file" class="custom-file-input">', | ||
' <label class="custom-file-label">Choose file</label>', | ||
'</div>', | ||
].join('') | ||
|
||
describe('index.js', function () { | ||
var input | ||
var mochaFixtureDiv | ||
|
||
before(function () { | ||
mochaFixtureDiv = document.getElementById('mocha-fixture') | ||
}) | ||
|
||
beforeEach(function() { | ||
mochaFixtureDiv.innerHTML = customInputFile | ||
input = document.querySelector('input') | ||
}) | ||
|
||
afterEach(function () { | ||
mochaFixtureDiv.innerHTML = '' | ||
}) | ||
|
||
describe('init', function () { | ||
it('should add bsCustomFileInput property', function () { | ||
bsCustomFileInput.init() | ||
|
||
expect(input.bsCustomFileInput).not.undefined | ||
}) | ||
|
||
it('should store default text', function () { | ||
bsCustomFileInput.init() | ||
|
||
var label = document.querySelector('.custom-file-label') | ||
|
||
expect(input.bsCustomFileInput.defaultText).equal(label.innerHTML) | ||
}) | ||
|
||
it('should add listener to the given input', function () { | ||
var spy = sinon.spy(input, 'addEventListener') | ||
|
||
bsCustomFileInput.init() | ||
|
||
expect(spy.called).equal(true) | ||
}) | ||
|
||
it('should add an event listener on forms', function () { | ||
var form = document.createElement('form') | ||
form.innerHTML = customInputFile | ||
|
||
mochaFixtureDiv.appendChild(form) | ||
|
||
var spy = sinon.spy(form, 'addEventListener') | ||
|
||
bsCustomFileInput.init() | ||
|
||
expect(spy.called).to.be.true | ||
}) | ||
|
||
it('should select only my custom input selector', function () { | ||
mochaFixtureDiv.innerHTML = [ | ||
'<input type="file" id="test" />', | ||
customInputFile, | ||
].join('') | ||
|
||
bsCustomFileInput.init('#test') | ||
|
||
var testInput = document.getElementById('test') | ||
var otherInput = document.querySelector('.custom-file input[type="file"]') | ||
|
||
expect(testInput.bsCustomFileInput).not.undefined | ||
expect(otherInput.bsCustomFileInput).undefined | ||
}) | ||
}) | ||
|
||
describe('destroy', function () { | ||
it('should remove bsCustomFileInput property', function () { | ||
bsCustomFileInput.init() | ||
bsCustomFileInput.destroy() | ||
|
||
expect(input.bsCustomFileInput).to.undefined | ||
}) | ||
|
||
it('should remove event listener on forms', function () { | ||
var form = document.createElement('form') | ||
form.innerHTML = [ | ||
'<div class="custom-file">', | ||
' <input type="file" class="custom-file-input">', | ||
'</div>', | ||
].join('') | ||
|
||
mochaFixtureDiv.appendChild(form) | ||
|
||
var spy = sinon.spy(form, 'removeEventListener') | ||
|
||
bsCustomFileInput.init() | ||
bsCustomFileInput.destroy() | ||
|
||
expect(spy.called).to.be.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
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