-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from kristerkari/bugfix/change-type
Handle input type change after page load, fixes #30
- Loading branch information
Showing
4 changed files
with
236 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,6 @@ | |
} else { | ||
element.type = "text"; | ||
} | ||
data.setTypeAttr(element, "password"); | ||
} | ||
|
||
element.value = val; | ||
|
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,199 @@ | ||
describe("changing element type", function() { | ||
"use strict"; | ||
|
||
beforeEach(helpers.initialSetup); | ||
|
||
if (helpers.canActuallyChangeType) { | ||
|
||
describe("when input type can be changed", function() { | ||
|
||
beforeEach(function() { | ||
helpers.spyOnCanChangeToTypeAndReturn(true); | ||
helpers.spyOnNativeSupportAndReturn(false); | ||
}); | ||
|
||
describe("when a password input with placeholder exists on the page", function() { | ||
var element; | ||
|
||
beforeEach(function(done) { | ||
element = helpers.createInputElement(true, "password"); | ||
setTimeout(done, helpers.loopDurationForTests); | ||
placekeeper.priv.__init(); | ||
}); | ||
|
||
afterEach(function() { | ||
element.parentNode.removeChild(element); | ||
}); | ||
|
||
describe("and when its type is changed to text with a data attribute", function() { | ||
|
||
beforeEach(function(done) { | ||
element.setAttribute("data-placeholder-type", "text"); | ||
setTimeout(done, helpers.loopDurationForTests); | ||
}); | ||
|
||
it("should have one input on the page", function() { | ||
expect(document.getElementsByTagName("input").length).toEqual(1); | ||
}); | ||
|
||
it("should have element type set to text", function() { | ||
expect(element.type).toEqual("text"); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
describe("when a text input with placeholder exists on the page", function() { | ||
var element; | ||
|
||
beforeEach(function(done) { | ||
element = helpers.createInputElement(true); | ||
setTimeout(done, helpers.loopDurationForTests); | ||
placekeeper.priv.__init(); | ||
}); | ||
|
||
afterEach(function() { | ||
element.parentNode.removeChild(element); | ||
}); | ||
|
||
describe("and when its type is changed to password", function() { | ||
|
||
beforeEach(function(done) { | ||
element.type = "password"; | ||
setTimeout(done, helpers.loopDurationForTests); | ||
}); | ||
|
||
it("should have one input on the page", function() { | ||
expect(document.getElementsByTagName("input").length).toEqual(1); | ||
}); | ||
|
||
it("should have element type set to text (so that placeholder is visible)", function() { | ||
expect(element.type).toEqual("text"); | ||
}); | ||
|
||
/* This test is failing | ||
TODO: find out why | ||
describe("and when the element is focused", function() { | ||
beforeEach(function(done) { | ||
helpers.retryFocus(element, function() { | ||
setTimeout(done, helpers.loopDurationForTests); | ||
}); | ||
}); | ||
it("should have element type set to password", function() { | ||
expect(element.type).toEqual("password"); | ||
}); | ||
}); | ||
*/ | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
describe("when input type can not be changed", function() { | ||
|
||
beforeEach(function() { | ||
helpers.spyOnCanChangeToTypeAndReturn(false); | ||
helpers.spyOnNativeSupportAndReturn(false); | ||
}); | ||
|
||
describe("when a password input with placeholder exists on the page", function() { | ||
var element; | ||
|
||
beforeEach(function(done) { | ||
element = helpers.createInputElement(true, "password"); | ||
setTimeout(function() { | ||
element = document.getElementById("elem"); | ||
done(); | ||
}, helpers.loopDurationForTests); | ||
placekeeper.priv.__init(); | ||
}); | ||
|
||
afterEach(function() { | ||
element.parentNode.removeChild(element); | ||
}); | ||
|
||
describe("and when its type is changed to text with a data attribute", function() { | ||
|
||
beforeEach(function(done) { | ||
element.setAttribute("data-placeholder-type", "text"); | ||
setTimeout(function() { | ||
element = document.getElementById("elem"); | ||
done(); | ||
}, helpers.loopDurationForTests); | ||
}); | ||
|
||
it("should have one input on the page", function() { | ||
expect(document.getElementsByTagName("input").length).toEqual(1); | ||
}); | ||
|
||
it("should have element type set to text", function() { | ||
expect(element.type).toEqual("text"); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
describe("when a text input with placeholder exists on the page", function() { | ||
var element; | ||
|
||
beforeEach(function(done) { | ||
element = helpers.createInputElement(true); | ||
placekeeper.priv.__init(); | ||
setTimeout(done, helpers.loopDurationForTests); | ||
}); | ||
|
||
afterEach(function() { | ||
element.parentNode.removeChild(element); | ||
}); | ||
|
||
describe("and when its type is changed to password", function() { | ||
|
||
beforeEach(function(done) { | ||
element.type = "password"; | ||
setTimeout(function() { | ||
element = document.getElementById("elem"); | ||
done(); | ||
}, helpers.loopDurationForTests); | ||
}); | ||
|
||
it("should have two inputs on the page", function() { | ||
expect(document.getElementsByTagName("input").length).toEqual(2); | ||
}); | ||
|
||
it("should have element type set to text", function() { | ||
expect(element.type).toEqual("text"); | ||
}); | ||
|
||
describe("and when the element is focused", function() { | ||
|
||
beforeEach(function(done) { | ||
helpers.retryFocus(element, function() { | ||
setTimeout(function() { | ||
element = document.getElementById("elem"); | ||
done(); | ||
}, helpers.loopDurationForTests); | ||
}); | ||
}); | ||
|
||
it("should have element type set to password", function() { | ||
expect(element.type).toEqual("password"); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
} | ||
|
||
}); |