aboutsummaryrefslogtreecommitdiffstats
path: root/devtest/src/main/java/com/google/gwt/query/client/DevTestRunner.java
blob: 47da99e9c81dfb9a40939d9c044feef9457023c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * Copyright 2009 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.query.client;

import static com.google.gwt.query.client.GQuery.$;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.Event;

/**
 * This module is thought to emulate a test environment similar to
 * GWTTestCase, but running it in development mode.
 * 
 * The main goal of it is to execute tests in a faster way, because you only need
 * to push reload in your browser.
 * 
 * @author manolo
 * 
 */
public class DevTestRunner extends MyTestCase implements EntryPoint {

  public void onModuleLoad() {
    try {
      gwtSetUp();
      
      testIssue23();

      $(e).after("<div>OK</div>");
    } catch (Exception ex) {
      ex.printStackTrace();
      $(e).after("<div>ERROR: " + ex.getMessage() + "</div>");
    }
  }
  
  int done = 0;
  
  public void testIssue23() {
    $(e).html("<table><tr><td><input type='radio' name='n' value='v1'>1</input><input type='radio' name='n' value='v2' checked='checked'>2</input></td><td><button>Click</button></tr><td></table>");
    $("button").click(new Function() {
      public boolean f(Event e) {
        $("table > tbody > tr > td > input:checked").each(new Function() {
          public void f(Element e) {
            done ++;
          }
        });
        return true;
      }
    });
    done = 0;
    $("button").click();
    assertEquals(1,done);
  }
  
  public void testDomManip() {
    String content = "<span class='branchA'><span class='target'>branchA target</span></span>"
      + "<span class='branchB'><span class='target'>branchB target</span></span>";
    
    $(e).html("");
    $(e).append(content);
    assertEquals(4, $("span", e).size());
    assertEquals(2, $("span.target", e).size());
    assertHtmlEquals(content, $(e).html());
  }
  
}