[infra-sk] Move setQueryString to test_util
Also fix a few typos.
Bug: skia:9525
Change-Id: I589fec9ab3d07dbe6af0b3bbb2f4ddfe4e1526f8
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/301841
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
diff --git a/golden/modules/byblame-page-sk/byblame-page-sk_test.js b/golden/modules/byblame-page-sk/byblame-page-sk_test.js
index 78494e3..de4b613 100644
--- a/golden/modules/byblame-page-sk/byblame-page-sk_test.js
+++ b/golden/modules/byblame-page-sk/byblame-page-sk_test.js
@@ -8,6 +8,7 @@
import {
setUpElementUnderTest,
eventPromise,
+ setQueryString,
expectQueryStringToEqual,
} from '../../../infra-sk/modules/test_util';
import { testOnlySetSettings } from '../settings';
@@ -165,14 +166,6 @@
});
});
-function setQueryString(string) {
- history.pushState(
- null,
- '',
- window.location.origin + window.location.pathname + string,
- );
-}
-
function selectCorpus(byblamePageSk, corpus) {
const event = eventPromise('end-task');
$$(`corpus-selector-sk li[title="${corpus}"]`, byblamePageSk).click();
diff --git a/golden/modules/changelists-page-sk/changelists-page-sk_test.js b/golden/modules/changelists-page-sk/changelists-page-sk_test.js
index a48e549..30e4839 100644
--- a/golden/modules/changelists-page-sk/changelists-page-sk_test.js
+++ b/golden/modules/changelists-page-sk/changelists-page-sk_test.js
@@ -11,6 +11,7 @@
import {
eventPromise,
expectQueryStringToEqual,
+ setQueryString,
setUpElementUnderTest,
} from '../../../infra-sk/modules/test_util';
@@ -93,7 +94,7 @@
changelistsPageSk._page_size = 10;
changelistsPageSk._showAll = false;
- changelistsPageSk._fetch();
+ await changelistsPageSk._fetch();
});
}); // end describe('api calls')
@@ -191,12 +192,6 @@
}); // end describe('dynamic content')
});
-function setQueryString(q) {
- history.pushState(
- null, '', window.location.origin + window.location.pathname + q,
- );
-}
-
function goToNextPage(changelistsPageSk) {
const event = eventPromise('end-task');
$$('pagination-sk button.next', changelistsPageSk).click();
diff --git a/golden/modules/ignores-page-sk/ignores-page-sk_test.js b/golden/modules/ignores-page-sk/ignores-page-sk_test.js
index b391032..cc19f9c 100644
--- a/golden/modules/ignores-page-sk/ignores-page-sk_test.js
+++ b/golden/modules/ignores-page-sk/ignores-page-sk_test.js
@@ -5,6 +5,7 @@
import {
eventPromise,
expectQueryStringToEqual,
+ setQueryString,
setUpElementUnderTest,
} from '../../../infra-sk/modules/test_util';
import { fakeNow, ignoreRules_10 } from './test_data';
@@ -201,12 +202,6 @@
});
});
-function setQueryString(q) {
- history.pushState(
- null, '', window.location.origin + window.location.pathname + q,
- );
-}
-
function findUntriagedDigestsCheckbox(ele) {
return $$('.controls checkbox-sk', ele);
}
diff --git a/golden/modules/list-page-sk/list-page-sk_test.js b/golden/modules/list-page-sk/list-page-sk_test.js
index 4c21587..3636215 100644
--- a/golden/modules/list-page-sk/list-page-sk_test.js
+++ b/golden/modules/list-page-sk/list-page-sk_test.js
@@ -5,6 +5,7 @@
import {
eventPromise,
expectQueryStringToEqual,
+ setQueryString,
setUpElementUnderTest,
} from '../../../infra-sk/modules/test_util';
import { sampleByTestList } from './test_data';
@@ -174,12 +175,6 @@
});
});
-function setQueryString(q) {
- history.pushState(
- null, '', window.location.origin + window.location.pathname + q,
- );
-}
-
function clickOnNegativeHeader(ele) {
$$('table > thead > tr > th:nth-child(3)', ele).click();
}
diff --git a/golden/modules/triagelog-page-sk/triagelog-page-sk_test.js b/golden/modules/triagelog-page-sk/triagelog-page-sk_test.js
index 39bca93..4311e9f 100644
--- a/golden/modules/triagelog-page-sk/triagelog-page-sk_test.js
+++ b/golden/modules/triagelog-page-sk/triagelog-page-sk_test.js
@@ -12,6 +12,7 @@
import {
eventPromise,
expectQueryStringToEqual,
+ setQueryString,
setUpElementUnderTest,
} from '../../../infra-sk/modules/test_util';
@@ -178,14 +179,6 @@
});
});
-function setQueryString(string) {
- history.pushState(
- null,
- '',
- window.location.origin + window.location.pathname + string,
- );
-}
-
function goToNextPageOfResults(triagelogPageSk) {
const event = eventPromise('end-task');
$$('pagination-sk button.next', triagelogPageSk).click();
diff --git a/infra-sk/modules/test_util.ts b/infra-sk/modules/test_util.ts
index 004572a..a7d1e8d 100644
--- a/infra-sk/modules/test_util.ts
+++ b/infra-sk/modules/test_util.ts
@@ -20,7 +20,7 @@
* The returned factory function optionally takes a callback function that will
* be called with the newly instantiated element before it is attached to the
* DOM, giving client code a chance to finish setting up the element before e.g.
- * the element's connecetedCallback() method is invoked.
+ * the element's connectedCallback() method is invoked.
*
* Sample usage:
*
@@ -202,3 +202,12 @@
export function expectQueryStringToEqual(expected: string) {
expect(window.location.search).to.equal(expected);
}
+
+/**
+ * Sets the query string to be the provided value. Does *not* cause a page reload.
+ */
+export function setQueryString(q: string) {
+ history.pushState(
+ null, '', window.location.origin + window.location.pathname + q,
+ );
+}
diff --git a/infra-sk/modules/test_util_test.ts b/infra-sk/modules/test_util_test.ts
index 26a94c0..a72416f 100644
--- a/infra-sk/modules/test_util_test.ts
+++ b/infra-sk/modules/test_util_test.ts
@@ -6,6 +6,7 @@
eventPromise,
noEventPromise,
expectQueryStringToEqual,
+ setQueryString,
} from './test_util';
describe('test utilities', () => {
@@ -213,4 +214,16 @@
expectQueryStringToEqual('?foo=bar&alpha=beta&alpha=gamma');
});
});
+
+ describe('setQueryString', () => {
+ it('can set the query to be empty', () => {
+ setQueryString('');
+ expectQueryStringToEqual('');
+ });
+
+ it('can set the query to be not empty', () => {
+ setQueryString('?alpha=beta');
+ expectQueryStringToEqual('?alpha=beta');
+ });
+ });
});