Smalltalk createPackage: 'Silk-Tests'! DOMiteTest subclass: #SilkInheritedTest instanceVariableNames: '' package: 'Silk-Tests'! !SilkInheritedTest methodsFor: 'fixture'! testedClass ^ Silk ! ! TestCase subclass: #SilkTest instanceVariableNames: 'fixtureDiv' package: 'Silk-Tests'! !SilkTest methodsFor: 'fixture'! assertBodyEndsWith: aString | sanitizedBody sanitizedAssertion | sanitizedBody := document body innerHTML replace: '\s*' with: ''. sanitizedAssertion := aString replace: '\s*' with: ''. self assert: sanitizedBody size >= sanitizedAssertion size. self assert: (sanitizedBody last: sanitizedAssertion size) equals: sanitizedAssertion ! setUp fixtureDiv := document createElement: 'div'. document body appendChild: fixtureDiv. fixtureDiv setAttribute: 'id' to: 'fixture'. fixtureDiv innerHTML: 'sentinel' ! tearDown | lastChild | lastChild := document body lastChild. self assert: lastChild equals: fixtureDiv. document body removeChild: lastChild ! ! !SilkTest methodsFor: 'testing'! testInsertTable | d tbl | d := 'html body div#fixture' asSilk. tbl := d TABLE. tbl TR TD: 'A'; TD: 'B'; TD: 'C'. tbl TR TD: 'D'; TD: 'E'; TD: 'F'. self assertBodyEndsWith: '>sentinel
ABC
DEF
' ! testNestedDIVsWithAttributes "demonstrates how DIVs are nested and given attributes" | s | s := '#fixture' asSilk. s := s DIV << ('id' -> 'container') << ('class' -> 'mySilkContainerClass'). s DIV << ('id' -> 'contentarea') << 'here comes the content'. s := s DIV << ('id' -> 'toolbar') << ('class' -> 'myToolbarClass'). (s BUTTON: 'do something') on: 'click' bind: [Transcript show: 'button pressed']. self assertBodyEndsWith: '>sentinel
here comes the content
' ! testOnClickEvent "#on:bind" | s para | s := '#fixture' asSilk. para := s P: 'DOM'. self timeout: 100. (self async: [para on: 'click' bind: ["Test successful" self finished]. '#fixture p' asJQuery trigger: 'click'. ]) fork ! !