Silk-Tests.st 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. Smalltalk createPackage: 'Silk-Tests'!
  2. (Smalltalk packageAt: 'Silk-Tests') imports: {'amber/jquery/Wrappers-JQuery'}!
  3. DOMiteTest subclass: #SilkInheritedTest
  4. instanceVariableNames: ''
  5. package: 'Silk-Tests'!
  6. !SilkInheritedTest methodsFor: 'fixture'!
  7. testedClass
  8. ^ Silk
  9. ! !
  10. TestCase subclass: #SilkTest
  11. instanceVariableNames: 'fixtureDiv'
  12. package: 'Silk-Tests'!
  13. !SilkTest methodsFor: 'fixture'!
  14. assertBodyEndsWith: aString
  15. | sanitizedBody sanitizedAssertion |
  16. sanitizedBody := document body innerHTML replace: '\s*' with: ''.
  17. sanitizedAssertion := aString replace: '\s*' with: ''.
  18. self assert: sanitizedBody size >= sanitizedAssertion size.
  19. self
  20. assert: (sanitizedBody last: sanitizedAssertion size)
  21. equals: sanitizedAssertion
  22. !
  23. setUp
  24. fixtureDiv := document createElement: 'div'.
  25. document body appendChild: fixtureDiv.
  26. fixtureDiv setAttribute: 'id' to: 'fixture'.
  27. fixtureDiv innerHTML: 'sentinel'
  28. !
  29. tearDown
  30. | lastChild |
  31. lastChild := document body lastChild.
  32. self assert: lastChild equals: fixtureDiv.
  33. document body removeChild: lastChild
  34. ! !
  35. !SilkTest methodsFor: 'testing'!
  36. testInsertTable
  37. | d tbl |
  38. d := 'html body div#fixture' asSilk.
  39. tbl := d TABLE.
  40. tbl TR
  41. TD: 'A';
  42. TD: 'B';
  43. TD: 'C'.
  44. tbl TR
  45. TD: 'D';
  46. TD: 'E';
  47. TD: 'F'.
  48. self assertBodyEndsWith: '>sentinel<table><tr><td>A</td><td>B</td><td>C</td></tr><tr><td>D</td><td>E</td><td>F</td></tr></table></div>'
  49. !
  50. testInsertTable2
  51. | d tbl |
  52. d := 'html body div#fixture' asSilk.
  53. tbl := d TABLE.
  54. tbl TR: {
  55. Silk TD: 'A'.
  56. Silk TD: 'B'.
  57. Silk TD: 'C'};
  58. TR: {
  59. Silk TD: 'D'.
  60. Silk TD: 'E'.
  61. Silk TD: 'F'}.
  62. self assertBodyEndsWith: '>sentinel<table><tr><td>A</td><td>B</td><td>C</td></tr><tr><td>D</td><td>E</td><td>F</td></tr></table></div>'
  63. !
  64. testNestedDIVsWithAttributes
  65. "demonstrates how DIVs are nested and given attributes"
  66. | s |
  67. s := '#fixture' asSilk.
  68. s := s DIV << ('id' -> 'container') << ('class' -> 'mySilkContainerClass').
  69. s DIV << ('id' -> 'contentarea') << 'here comes the content'.
  70. s := s DIV << ('id' -> 'toolbar') << ('class' -> 'myToolbarClass').
  71. (s BUTTON: 'do something') on: 'click' bind: [Transcript show: 'button pressed'].
  72. self assertBodyEndsWith: '>sentinel<div class="mySilkContainerClass" id="container"><div id="contentarea">here comes the content</div><div class="myToolbarClass" id="toolbar"><button>do something</button></div></div></div>'
  73. !
  74. testOnClickEvent
  75. "#on:bind"
  76. | s para |
  77. s := '#fixture' asSilk.
  78. para := s P: 'DOM'.
  79. self timeout: 100.
  80. (self async: [para on: 'click' bind:
  81. ["Test successful" self finished].
  82. '#fixture p' asJQuery trigger: 'click'.
  83. ]) fork
  84. ! !