expression.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* global normal, attrs */
  2. casper.test.begin('Expression', 21, function (test) {
  3. casper
  4. .start('./fixtures/expression.html')
  5. .then(function () {
  6. test.assertSelectorHasText('#normal p', 'Hello World!')
  7. test.assertSelectorHasText('#lazy p', 'Hi Ho!')
  8. test.assertField('one', 'Hello')
  9. test.assertField('two', 'World')
  10. test.assertField('three', 'Hi')
  11. test.assertField('four', 'Ho')
  12. // attrs
  13. test.assertEval(function () {
  14. return document.getElementById('attrs').dataset.test === 'hi ho ha'
  15. })
  16. })
  17. .thenEvaluate(function () {
  18. // setting value
  19. normal.one = 'Hola'
  20. })
  21. .then(function () {
  22. test.assertSelectorHasText('#normal p', 'Hola World!')
  23. test.assertField('one', 'Hola')
  24. })
  25. .thenEvaluate(function () {
  26. // setting nested value
  27. normal.two.three = 'Casper'
  28. })
  29. .then(function () {
  30. test.assertSelectorHasText('#normal p', 'Hola Casper!')
  31. test.assertField('two', 'Casper')
  32. })
  33. .then(function () {
  34. // lazy input
  35. this.fill('#form', {
  36. three: 'three',
  37. four: 'four'
  38. })
  39. })
  40. .then(function () {
  41. test.assertSelectorHasText('#lazy p', 'three four!')
  42. })
  43. .then(function () {
  44. // normal input
  45. this.sendKeys('#one', 'Bye')
  46. })
  47. .then(function () {
  48. test.assertSelectorHasText('#normal p', 'Bye Casper!')
  49. })
  50. // v-on with expression
  51. .thenClick('#normal button', function () {
  52. test.assertField('one', 'clicked')
  53. test.assertSelectorHasText('#normal p', 'clicked Casper!')
  54. })
  55. // v-on with expression
  56. .thenClick('#lazy button', function () {
  57. test.assertField('four', 'clicked')
  58. test.assertSelectorHasText('#lazy p', 'three clicked!')
  59. })
  60. // conditional expression
  61. // e.g. ok ? yesMSg : noMsg
  62. // make sure all three are captured as dependency
  63. .then(function () {
  64. test.assertSelectorHasText('#conditional p', 'YES')
  65. })
  66. .thenClick('#conditional .toggle', function () {
  67. test.assertSelectorHasText('#conditional p', 'NO')
  68. })
  69. .thenClick('#conditional .change', function () {
  70. test.assertSelectorHasText('#conditional p', 'Nah')
  71. })
  72. .thenEvaluate(function () {
  73. attrs.msg = 'hoho'
  74. })
  75. .then(function () {
  76. test.assertEval(function () {
  77. return document.getElementById('attrs').dataset.test === 'hi hoho ha'
  78. })
  79. })
  80. .run(function () {
  81. test.done()
  82. })
  83. })