Просмотр исходного кода

functional test for nested sd-repeat

Evan You 12 лет назад
Родитель
Сommit
016842cf48
2 измененных файлов с 83 добавлено и 0 удалено
  1. 39 0
      test/functional/fixtures/nested-repeat.html
  2. 44 0
      test/functional/specs/nested-repeat.js

+ 39 - 0
test/functional/fixtures/nested-repeat.html

@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html lang="en">
+    <head>
+        <title>Nested repeat</title>
+        <meta charset="utf-8">
+        <script src="../../../dist/seed.js"></script>
+    </head>
+    <body>
+        <div id="test">
+            <ul>
+                <li sd-repeat="item : items" sd-class="'list-' + $index">
+                    <ul>
+                        <li sd-repeat="subitem : item.items" sd-class="'list-' + $index">
+                            {{$parent.$index + '.' + $index + ' : ' + item.title + '<-' + subitem.title}}
+                        </li>
+                    </ul>
+                </li>
+            </ul>
+            <button id="b0" sd-on="click: items[0].title = 'hi'">1</button>
+            <button id="b1" sd-on="click: items[1].title = 'hi'">2</button>
+            <button id="b0-0" sd-on="click: items[0].items[0].title = 'hi'">1.1</button>
+            <button id="b0-1" sd-on="click: items[0].items[1].title = 'hi'">1.2</button>
+            <button id="b1-0" sd-on="click: items[1].items[0].title = 'hi'">2.1</button>
+            <button id="b1-1" sd-on="click: items[1].items[1].title = 'hi'">2.2</button>
+        </div>
+        <script>
+        var items = [
+            { title: 0, items: [{title:0}, {title:1}] },
+            { title: 1, items: [{title:0}, {title:1}] }
+        ]
+        new Seed({
+            el: '#test',
+            scope: {
+                items: items
+            }
+        })
+        </script>
+    </body>
+</html>

+ 44 - 0
test/functional/specs/nested-repeat.js

@@ -0,0 +1,44 @@
+casper.test.begin('Nested Repeat', 12, function (test) {
+    
+    casper
+    .start('./fixtures/nested-repeat.html', function () {
+
+        var i, j
+
+        for (i = 0; i < 2; i++) {
+            for (j = 0; j < 2; j++) {
+                test.assertSelectorHasText(
+                    '.list-' + i + ' .list-' + j,
+                    i + '.' + j + ' : ' + i + '<-' + j
+                )
+            }
+        }
+
+        this.click('#b0')
+        this.click('#b1')
+
+        for (i = 0; i < 2; i++) {
+            for (j = 0; j < 2; j++) {
+                test.assertSelectorHasText(
+                    '.list-' + i + ' .list-' + j,
+                    i + '.' + j + ' : hi<-' + j
+                )
+            }
+        }
+
+        for (i = 0; i < 2; i++) {
+            for (j = 0; j < 2; j++) {
+                this.click('#b' + i + '-' + j)
+                test.assertSelectorHasText(
+                    '.list-' + i + ' .list-' + j,
+                    i + '.' + j + ' : hi<-hi'
+                )
+            }
+        }
+
+    })
+    .run(function () {
+        test.done()
+    })
+
+})