Silk-Tests.st 2.2 KB

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