1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > |
---|
2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
---|
3 | <head> |
---|
4 | <meta http-equiv="content-type" content="text/html; charset=UTF-8"> |
---|
5 | <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> |
---|
6 | <link href="qunit.css" rel="stylesheet" type="text/css" /> |
---|
7 | <script src="qunit.js" type="text/javascript"></script> |
---|
8 | |
---|
9 | <script type="text/javascript"> |
---|
10 | (function($) { |
---|
11 | $.namespace = function() { |
---|
12 | /// <summary> |
---|
13 | /// Creates namespaces to be used for scoping variables and classes so that they are not global. Usage: |
---|
14 | /// <pre><code> |
---|
15 | /// $.namespace('Company', 'Company.data'); |
---|
16 | /// </code></pre> |
---|
17 | /// </summary> |
---|
18 | /// <param name="namespace1" type="String"> |
---|
19 | /// </param> |
---|
20 | /// <param name="namespace2" type="String"> |
---|
21 | /// </param> |
---|
22 | /// <param name="etc" type="String"> |
---|
23 | /// </param> |
---|
24 | /// <returns type="" /> |
---|
25 | var a = arguments, o = null, i, j, d, rt; |
---|
26 | for (i = 0; i < a.length; i = i + 1) { |
---|
27 | d = a[i].split("."); |
---|
28 | rt = d[0]; |
---|
29 | eval('if (typeof ' + rt + ' == "undefined"){' + rt + ' = {};} o = ' + rt + ';'); |
---|
30 | for (j = 1; j < d.length; j = j + 1) { |
---|
31 | o[d[j]] = o[d[j]] || {}; |
---|
32 | o = o[d[j]]; |
---|
33 | } |
---|
34 | } |
---|
35 | }; |
---|
36 | |
---|
37 | $.StringFormat = function(text) { |
---|
38 | //http://just3ws.wordpress.com/2007/04/28/javascript-stringformat-method/ |
---|
39 | //check if there are two arguments in the arguments list |
---|
40 | if (arguments.length <= 1) { |
---|
41 | //if there are not 2 or more arguments there’s nothing to replace |
---|
42 | //just return the original text |
---|
43 | return text; |
---|
44 | } |
---|
45 | //decrement to move to the second argument in the array |
---|
46 | var tokenCount = arguments.length - 2; |
---|
47 | for (var token = 0; token <= tokenCount; token = token + 1) { |
---|
48 | //iterate through the tokens and replace their placeholders from the original text in order |
---|
49 | text = text.replace(new RegExp("\\{" + token + "\\}", "gi"), |
---|
50 | arguments[token + 1]); |
---|
51 | |
---|
52 | } |
---|
53 | return text; |
---|
54 | }; |
---|
55 | |
---|
56 | |
---|
57 | })(jQuery); |
---|
58 | $.namespace('MItem'); |
---|
59 | //TODO: this should be in a base class |
---|
60 | MItem = { |
---|
61 | DialogSelector: "#ItemSearch", |
---|
62 | DialogName: "ItemSearch", |
---|
63 | // |
---|
64 | ResultList: function() { |
---|
65 | return $($.StringFormat(".{0}-ResultList", MItem.DialogName), MItem.DialogSelector); |
---|
66 | }, |
---|
67 | ResultListOptions: function() { |
---|
68 | return $(".ItemSearch-ResultList option", MItem.DialogSelector); |
---|
69 | }, |
---|
70 | ResultListSelectedOptions: function() { |
---|
71 | return $($.StringFormat(".{0}-ResultList option:selected", MItem.DialogName), MItem.DialogSelector); |
---|
72 | }, |
---|
73 | ResultListOptionsNotEmpty: function() { |
---|
74 | return $($.StringFormat(".{0}-ResultList option[value!='{1}']", MItem.DialogName, '00000000-0000-0000-0000-000000000000'), MItem.DialogSelector); |
---|
75 | }, |
---|
76 | Messages: function() { |
---|
77 | return $(MItem.DialogSelector + " .ItemSearch-Messages"); |
---|
78 | }, |
---|
79 | // |
---|
80 | Dialog: function() { |
---|
81 | return $(MItem.DialogSelector); |
---|
82 | }, |
---|
83 | SubDropDownRows: function() { |
---|
84 | return $("tr:has(.ItemSearch-Basket),tr:has(.ItemSearch-ItemGroup)", MItem.DialogSelector); |
---|
85 | }, |
---|
86 | ItemSearchSelection: function() { |
---|
87 | return $(MItem.DialogSelector + " .ItemSearch-ItemSearchSelection"); |
---|
88 | } |
---|
89 | }; |
---|
90 | $(function() { |
---|
91 | |
---|
92 | module("Result list"); |
---|
93 | test("ResultList", function() { |
---|
94 | equals(MItem.ResultList().length, 1, "ResultList length"); |
---|
95 | }); |
---|
96 | test("ResultListOptions", function() { |
---|
97 | equals(MItem.ResultListOptions().length, 7, "ResultListOptions length"); |
---|
98 | }); |
---|
99 | test("ResultListSelectedOptions", function() { |
---|
100 | equals(MItem.ResultListSelectedOptions().length, 1, "ResultListSelectedOptions length"); |
---|
101 | }); |
---|
102 | test("ResultListOptionsNotEmpty", function() { |
---|
103 | equals(MItem.ResultListOptionsNotEmpty().length, 6, "ResultListOptionsNotEmpty length"); |
---|
104 | }); |
---|
105 | module("Messages"); |
---|
106 | test("Messages", function() { |
---|
107 | equals(MItem.Messages().length, 1, "Messages length"); |
---|
108 | }); |
---|
109 | module("Dialog"); |
---|
110 | test("Dialog", function() { |
---|
111 | equals(MItem.Dialog().length, 1, "Dialog length"); |
---|
112 | }); |
---|
113 | module("SubDropDowns"); |
---|
114 | test("SubDropDownRows", function() { |
---|
115 | equals(MItem.SubDropDownRows().length, 2, "SubDropDownRows length"); |
---|
116 | }); |
---|
117 | |
---|
118 | }) |
---|
119 | //$("#ItemSearch_Messages").html() |
---|
120 | </script> |
---|
121 | |
---|
122 | </head> |
---|
123 | <body> |
---|
124 | <h1 id="qunit-header"> |
---|
125 | QUnit test</h1> |
---|
126 | <h2 id="qunit-banner"> |
---|
127 | </h2> |
---|
128 | <h2 id="qunit-userAgent"> |
---|
129 | </h2> |
---|
130 | <ol id="qunit-tests"> |
---|
131 | </ol> |
---|
132 | <p id="qunit-testresult" class="result"> |
---|
133 | </p> |
---|
134 | <div id="ItemSearch" title="Urval Varor"> |
---|
135 | <div> |
---|
136 | <div id="ItemSearch_Messages" class="ItemSearch-Messages"> |
---|
137 | </div> |
---|
138 | <table cellpadding="0" width="570"> |
---|
139 | <tbody> |
---|
140 | <tr width="100%"> |
---|
141 | <td width="60"> |
---|
142 | <label class="PageTextClass" style="display: inline-block; width: 100%;" for="ItemSearch_ItemSearchSelection"> |
---|
143 | Urval Varor</label> |
---|
144 | </td> |
---|
145 | <td> |
---|
146 | <select id="ItemSearch_ItemSearchSelection" class="ItemSearch-ItemSearchSelection DropDownListClass" |
---|
147 | style="width: 100%;"> |
---|
148 | <option selected="selected" value="Item">Varor</option> |
---|
149 | <option value="ItemGroup">Varugrupp</option> |
---|
150 | <option value="Basket">Samlingskorg</option> |
---|
151 | </select> |
---|
152 | </td> |
---|
153 | </tr> |
---|
154 | <tr width="100%"> |
---|
155 | <td width="60"> |
---|
156 | <label class="PageTextClass" style="display: inline-block; width: 100%;" for="ItemSearch_ItemGroup"> |
---|
157 | Varugrupp</label> |
---|
158 | </td> |
---|
159 | <td> |
---|
160 | <select id="ItemSearch_ItemGroup" class="ItemSearch-ItemGroup |
---|
161 | DropDownListClass" style="width: 100%;"> |
---|
162 | <option selected="selected" value="7f466a0c-ad00-4cc6-a916-9dc8dc7ba280">Alkoholhaltiga |
---|
163 | drycker</option> |
---|
164 | <option value="1">Bullar, skorpor, kex, kakor, konditori</option> |
---|
165 | <option value="2">Disk&rengöringsmedel</option> |
---|
166 | <option value="3">Drycker</option> |
---|
167 | <option value="4">Fisk, skaldjur, rom</option> |
---|
168 | </select> |
---|
169 | </td> |
---|
170 | </tr> |
---|
171 | <tr width="100%"> |
---|
172 | <td width="60"> |
---|
173 | <label class="PageTextClass" style="display: inline-block; width: 100%;" for="ItemSearch_Basket"> |
---|
174 | Samlingskorg</label> |
---|
175 | </td> |
---|
176 | <td> |
---|
177 | <select id="ItemSearch_Basket" class="ItemSearch-Basket |
---|
178 | DropDownListClass" style="width: 100%;"> |
---|
179 | <option selected="selected" value="1">Buljonger</option> |
---|
180 | <option value="2">Buljongkorg</option> |
---|
181 | <option value="3">Grönsaker</option> |
---|
182 | <option value="4">Kryddkorg</option> |
---|
183 | <option value="5">Kryddkorg</option> |
---|
184 | <option value="6">Puréer</option> |
---|
185 | <option value="7">Specerier</option> |
---|
186 | <option value="8">Tillbehör</option> |
---|
187 | </select> |
---|
188 | </td> |
---|
189 | </tr> |
---|
190 | <tr width="100%"> |
---|
191 | <td width="60"> |
---|
192 | <label class="PageTextClass" style="display: inline-block; width: 100%;" for="ItemSearch_SearchText"> |
---|
193 | Fritext</label> |
---|
194 | </td> |
---|
195 | <td> |
---|
196 | <input id="ItemSearch_SearchText" class="ItemSearch-SearchText |
---|
197 | TextBoxClass" style="height: 21px; width: 100%;" type="text"> |
---|
198 | </td> |
---|
199 | </tr> |
---|
200 | <tr> |
---|
201 | <td width="60"> |
---|
202 | |
---|
203 | </td> |
---|
204 | <td width="110"> |
---|
205 | <input id="ItemSearch_NotConnectedOnly" style="display: inline;" class="ItemSearch-NotConnectedOnly" |
---|
206 | type="checkbox"><label class="PageTextClass" style="display: inline; width: 100%;" |
---|
207 | for="ItemSearch_NotConnectedOnly">Endast ej kopplade varor</label> |
---|
208 | </td> |
---|
209 | <td align="right" valign="top" width="50"> |
---|
210 | <input id="ItemSearch_ibSearch" class="ItemSearch-ibSearch |
---|
211 | ui-state-default ui-corner-all" value="Sök" type="button"> |
---|
212 | </td> |
---|
213 | </tr> |
---|
214 | <tr> |
---|
215 | <td> |
---|
216 | </td> |
---|
217 | <td> |
---|
218 | </td> |
---|
219 | </tr> |
---|
220 | <tr width="100%"> |
---|
221 | <td width="60"> |
---|
222 | <label class="PageTextClass" style="display: inline-block; width: 100%;" for="ItemSearch_ResultList"> |
---|
223 | Varor</label> |
---|
224 | </td> |
---|
225 | <td> |
---|
226 | <select id="ItemSearch_ResultList" class="ItemSearch-Resultlist |
---|
227 | DropDownListClass" style="width: 100%;"> |
---|
228 | <option value="1">Buljongkorg</option> |
---|
229 | <option value="2">Grönsaker</option> |
---|
230 | <option value="3">Kryddkorg</option> |
---|
231 | <option value="4">Kryddkorg</option> |
---|
232 | <option value="5">Puréer</option> |
---|
233 | <option value="6">Specerier</option> |
---|
234 | <option value="7">Tillbehör</option> |
---|
235 | </select> |
---|
236 | </td> |
---|
237 | </tr> |
---|
238 | </tbody> |
---|
239 | </table> |
---|
240 | </div> |
---|
241 | </div> |
---|
242 | </body> |
---|
243 | </html> |
---|