transition.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. casper.test.begin('CSS Transition', 37, function (test) {
  2. var minWait = 50,
  3. transDuration = 200
  4. casper
  5. .start('./fixtures/transition.html', function () {
  6. test.assertElementCount('.test', 3)
  7. test.assertVisible('.test.if')
  8. test.assertNotVisible('.test[data-id="1"]')
  9. })
  10. .thenClick('.button-0')
  11. .wait(minWait, function () {
  12. test.assertVisible('.test[data-id="1"]')
  13. })
  14. .thenClick('.button-1')
  15. .wait(minWait, function () {
  16. test.assertElementCount('.test.v-leave', 1)
  17. })
  18. .wait(transDuration, function () {
  19. test.assertElementCount('.test.v-leave', 0)
  20. test.assertNotVisible('.test[data-id="1"]')
  21. })
  22. .thenClick('.button-2')
  23. .wait(minWait, function () {
  24. test.assertElementCount('.test.v-leave', 1)
  25. })
  26. .wait(transDuration, function () {
  27. test.assertElementCount('.test.v-leave', 0)
  28. test.assertNotVisible('.test[data-id="1"]')
  29. test.assertNotVisible('.test[data-id="2"]')
  30. })
  31. .thenClick('.push')
  32. .wait(minWait, function () {
  33. test.assertVisible('.test[data-id="3"]')
  34. })
  35. .thenClick('.pop')
  36. .thenClick('.pop')
  37. .wait(minWait, function () {
  38. test.assertElementCount('.test.v-leave', 2)
  39. })
  40. .wait(transDuration, function () {
  41. test.assertNotVisible('.test.if')
  42. test.assertNotVisible('.test[data-id="1"]')
  43. })
  44. .thenClick('.splice')
  45. .wait(minWait, function () {
  46. test.assertVisible('.test[data-id="99"]')
  47. })
  48. // test Array swapping with transition
  49. .thenEvaluate(function () {
  50. test.items = [{a:1}, {a:2}, {a:3}, {a:4}, {a:5}]
  51. })
  52. .wait(minWait, function () {
  53. test.assertVisible('.test.if')
  54. test.assertElementCount('.test', 7)
  55. test.assertElementCount('.test[data-id="99"].v-leave', 1)
  56. test.assertNotVisible('.test[data-id="1"]')
  57. test.assertNotVisible('.test[data-id="2"]')
  58. test.assertVisible('.test[data-id="3"]')
  59. test.assertVisible('.test[data-id="4"]')
  60. test.assertVisible('.test[data-id="5"]')
  61. })
  62. .wait(transDuration, function () {
  63. // old one should be removed now
  64. test.assertElementCount('.test', 6)
  65. test.assertElementCount('.test.v-leave', 0)
  66. test.assertElementCount('.test[data-id="99"]', 0)
  67. })
  68. // test Array diffing with transition
  69. .thenEvaluate(function () {
  70. test.items = [test.items[4], {a:6}, test.items[2], {a:7}, test.items[0]]
  71. })
  72. .wait(minWait, function () {
  73. // reusing 3 existing, one of the destroyed (a=2) is hidden, so only 1 item should be leaving
  74. test.assertElementCount('.test.v-leave', 1)
  75. // only 2 new items should be in the DOM, the hidden element is removed immediately
  76. // so should have 5 + 1 + 1 = 7 items
  77. test.assertElementCount('.test', 7)
  78. })
  79. .wait(transDuration, function () {
  80. test.assertElementCount('.test.v-leave', 0)
  81. test.assertElementCount('.test', 6)
  82. test.assertSelectorHasText('li.test:nth-child(1)', '5')
  83. test.assertSelectorHasText('li.test:nth-child(2)', '6')
  84. test.assertSelectorHasText('li.test:nth-child(3)', '3')
  85. test.assertSelectorHasText('li.test:nth-child(4)', '7')
  86. test.assertSelectorHasText('li.test:nth-child(5)', '1')
  87. test.assertNotVisible('li.test:nth-child(5)')
  88. })
  89. .run(function () {
  90. test.done()
  91. })
  92. })