validation.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. casper.test.begin('Validation', 9, function (test) {
  2. casper
  3. .start('./fixtures/validation.html')
  4. .then(function () {
  5. test.assertElementCount('.valid', 0)
  6. this.sendKeys('input[name="name"]', 'haha')
  7. })
  8. .then(function () {
  9. test.assertElementCount('.valid', 1)
  10. this.sendKeys('input[name="email"]', 'hello')
  11. })
  12. .then(function () {
  13. // email should be invalid
  14. test.assertElementCount('.valid', 1)
  15. this.sendKeys('input[name="email"]', 'heo@bar.com', { reset: true })
  16. })
  17. .then(function () {
  18. // email should be valid now
  19. test.assertField('email', 'heo@bar.com')
  20. test.assertElementCount('.valid', 2)
  21. })
  22. // test edit/insertion when there are filters
  23. .thenEvaluate(function () {
  24. document.querySelector('input[name="email"]').setSelectionRange(2,2)
  25. })
  26. .then(function () {
  27. this.sendKeys('input[name="email"]', 'll')
  28. })
  29. .then(function () {
  30. test.assertElementCount('.valid', 2)
  31. test.assertField('email', 'hello@bar.com')
  32. })
  33. .thenClick('#go')
  34. .then(function () {
  35. test.assertElementCount('.user', 1)
  36. test.assertSelectorHasText('.user', 'haha hello@bar.com')
  37. })
  38. .run(function () {
  39. test.done()
  40. })
  41. })