validation.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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', function () {
  34. test.assertElementCount('.user', 1)
  35. test.assertSelectorHasText('.user', 'haha hello@bar.com')
  36. })
  37. .run(function () {
  38. test.done()
  39. })
  40. })