+ it("show per page", function () {
+ if (!jasmine_config.check_sortby) {
+ debug("ignore check for sort by");
+ return;
+ }
+
+ var waitcount = 0;
+ var sort_value = 'title:1';
+ var per_page_number = 20;
+ var title_list_old = title_list("xxx ");
+
+ function title_list(prefix) {
+ var list = [];
+ var terms = $("div.mkws-records > div.mkws-summary > a");
+ for (var i = 0; i < terms.length; i++) {
+ var term = $(terms[i]).text().trim();
+ list.push(term);
+ // debug(prefix + "title: " + term);
+ }
+ return list;
+ }
+
+ runs(function () {
+ $("div.mkws-records").bind("DOMNodeInserted DOMNodeRemoved propertychange", function () {
+ waitcount++;
+ debug("DOM change mkws-records, sort by: " + waitcount);
+ });
+
+ var select = $("select.mkws-sort option[selected='selected']");
+ debug("Sort by default is: " + select.text() + " and unselect it");
+ select.removeAttr('selected');
+
+ select = $("select.mkws-sort option[value='" + sort_value + "']").attr('selected', true);
+ debug("sort by is set to: " + select.text());
+ select.trigger("change");
+ });
+
+ waitsFor(function () {
+ //debug("wait for2: " + waitcount);
+ return waitcount >= (per_page_number + 10) ? true : false;
+ }, "DOM change mkws-records, by sort page", 3 * jasmine_config.second);
+
+ runs(function () {
+ $("div.mkws-records").unbind("DOMNodeInserted DOMNodeRemoved propertychange");
+ debug("unbind by sort");
+
+ var records = $("div.mkws-records > div.mkws-summary");
+ debug("Sort by got now " + records.length + " records");
+ expect(records.length).toBe(per_page_number);
+ });
+
+ runs(function () {
+ var title_list_new = title_list("yyy ");
+ var diff_flag = 0;
+ for (var i = 0; i < title_list_old.length; i++) {
+ debug((i+1) + ". " + title_list_old[i] + " :: " + title_list_new[i]);
+
+ if (title_list_old[i] != title_list_new[i]) {
+ diff_flag++;
+ }
+ }
+ debug("Title changes: " + diff_flag + " out of " + per_page_number);
+ expect(diff_flag).not.toBe(0);
+ });
+ });
+});
+
+describe("Check async widget discovery", function () {
+ var $ = mkws.$;
+ it("initialises a new widget", function() {
+ $("div.mkws-search").after('<div id="asyncSearch"><div class="mkws-search mkws-team-async"></div></div>');
+ mkws.init("Another search box", "#asyncSearch");
+ waitsFor(function () {
+ return $("#asyncSearch input").length >= 1 ? true : false;
+ }, "Call init() to build an .mkws-search", 750);
+ runs(function () {
+ var numInput = $("div.mkws-search input").length;
+ debug("Input elements present: " + numInput);
+ expect(numInput).toBe(4);
+ var numRec = $("div.mkws-records > div.mkws-summary").length;
+ debug("Records should still be present. There are: " + numRec);
+ expect(numRec).toBeGreaterThan(0);
+ });
+ });