mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-29 05:58:11 +08:00
* revert all commits to before Typescript migration * update compat workflow to match latest deps (#2335) * update compat workflow to match latest deps * attempt to debug * attempt to debug * remove debugging code * typo * update deps to match desktop (#2340) * fix: don't run lint with `--fix` on push tests (#2273) * fix: don't run lint with `--fix` on push tests * npx Co-authored-by: maniarathi <mani.arathi@gmail.com> Co-authored-by: Madison Dunitz <madison.dunitz@chanzuckerberg.com> * rename X_approx_distribution to X_approximate_distribution (#2337) * Correctly handle non-finite numbers in heuristic determination of X distribution (#2342) * handle non-finites explicitly * improve and test edge case handling for distribution estimation * revert debugging changes * code readability * clean up type inferencing (#2332) * unit tests for 64 bit conversion * clean up type handling * type inference tests * more type inference fixes * use schema to determine user intent for data typing * stop using deprecated API * fbs type encoding test * add missing test * add more tests * correctly infer X type for CXG adaptor * lint * fix typo * ts migration * cleanup from PR review * lint * PR review changes * remove unused packages from client (#2359) * remove unused packages from client * add missing peer dep * fix: disable FE auth testing on compatibility tests (#2377) * update: release process (#2277) Co-authored-by: maniarathi <mani.arathi@gmail.com> * fix: remove spaces in param setup (#2380) * delete deploy workflow (#2396) * undo reformatting which now does not pass lint * fix snapshots which changed due to npm dep changes * add missing quoting to snapshot * another snapshot typo fix * TS Revert (2) - replay PR #2347 and #2354 (#2403) * replay edits from PR 2347 * TS Revert (3) - replay edits in PR #2327 (#2404) * replay edits in PR 2327 * TS Revert (4) - replay PR #2355 (#2405) * replay edits in PR 2355 * add additional babel config * reformat with new prettier config Co-authored-by: Severiano Badajoz <sbadajoz@chanzuckerberg.com> Co-authored-by: maniarathi <mani.arathi@gmail.com> Co-authored-by: Madison Dunitz <madison.dunitz@chanzuckerberg.com>
132 lines
3.6 KiB
JavaScript
132 lines
3.6 KiB
JavaScript
/* eslint-disable no-await-in-loop -- await in loop is needed to emulate sequential user actions */
|
|
export function getTestId(id) {
|
|
return `[data-testid='${id}']`;
|
|
}
|
|
|
|
export function getTestClass(className) {
|
|
return `[data-testclass='${className}']`;
|
|
}
|
|
|
|
export async function waitByID(testId, props = {}) {
|
|
return page.waitForSelector(getTestId(testId), props);
|
|
}
|
|
|
|
export async function waitByClass(testClass, props = {}) {
|
|
return page.waitForSelector(`[data-testclass='${testClass}']`, props);
|
|
}
|
|
|
|
export async function waitForAllByIds(testIds) {
|
|
await Promise.all(
|
|
testIds.map((testId) => page.waitForSelector(getTestId(testId)))
|
|
);
|
|
}
|
|
|
|
export async function getAllByClass(testClass) {
|
|
return page.$$(`[data-testclass=${testClass}]`);
|
|
}
|
|
|
|
export async function typeInto(testId, text) {
|
|
// blueprint's typeahead is treating typing weird, clicking & waiting first solves this
|
|
// only works for text without special characters
|
|
await waitByID(testId);
|
|
const selector = getTestId(testId);
|
|
// type ahead can be annoying if you don't pause before you type
|
|
await page.click(selector);
|
|
await page.waitForTimeout(200);
|
|
await page.type(selector, text);
|
|
}
|
|
|
|
export async function clearInputAndTypeInto(testId, text) {
|
|
await waitByID(testId);
|
|
const selector = getTestId(testId);
|
|
// only works for text without special characters
|
|
// type ahead can be annoying if you don't pause before you type
|
|
await page.click(selector);
|
|
await page.waitForTimeout(200);
|
|
// select all
|
|
await page.click(selector, { clickCount: 3 });
|
|
await page.keyboard.press("Backspace");
|
|
await page.type(selector, text);
|
|
}
|
|
|
|
export async function clickOn(testId, options = {}) {
|
|
await expect(page).toClick(getTestId(testId), options);
|
|
}
|
|
|
|
/**
|
|
* (thuang): There are times when Puppeteer clicks on a button and the page doesn't respond.
|
|
* So I added clickOnUntil() to retry clicking until a given condition is met.
|
|
*/
|
|
export async function clickOnUntil(testId, assert) {
|
|
const MAX_RETRY = 10;
|
|
const WAIT_FOR_MS = 200;
|
|
|
|
let retry = 0;
|
|
|
|
while (retry < MAX_RETRY) {
|
|
try {
|
|
await clickOn(testId);
|
|
await assert();
|
|
|
|
break;
|
|
} catch (error) {
|
|
retry += 1;
|
|
|
|
await page.waitForTimeout(WAIT_FOR_MS);
|
|
}
|
|
}
|
|
|
|
if (retry === MAX_RETRY) {
|
|
throw Error("clickOnUntil() assertion failed!");
|
|
}
|
|
}
|
|
|
|
export async function getOneElementInnerHTML(selector, options = {}) {
|
|
await page.waitForSelector(selector, options);
|
|
|
|
return page.$eval(selector, (el) => el.innerHTML);
|
|
}
|
|
|
|
export async function getOneElementInnerText(selector) {
|
|
expect(page).toMatchElement(selector);
|
|
|
|
return page.$eval(selector, (el) => el.innerText);
|
|
}
|
|
|
|
export async function getElementCoordinates(testId) {
|
|
return page.$eval(getTestId(testId), (elem) => {
|
|
const { left, top } = elem.getBoundingClientRect();
|
|
return [left, top];
|
|
});
|
|
}
|
|
|
|
async function clickTermsOfService() {
|
|
if (!(await isElementPresent(getTestId("tos-cookies-accept")))) return;
|
|
|
|
await clickOn("tos-cookies-accept");
|
|
}
|
|
|
|
async function nameNewAnnotation() {
|
|
if (await isElementPresent(getTestId("annotation-dialog"))) {
|
|
await typeInto("new-annotation-name", "ignoreE2E");
|
|
await clickOn("submit-annotation");
|
|
|
|
// wait for the page to load
|
|
await waitByClass("autosave-complete");
|
|
}
|
|
}
|
|
|
|
export async function goToPage(url) {
|
|
await page.goto(url, {
|
|
waitUntil: "networkidle0",
|
|
});
|
|
|
|
await nameNewAnnotation();
|
|
await clickTermsOfService();
|
|
}
|
|
|
|
export async function isElementPresent(selector, options) {
|
|
return Boolean(await page.$(selector, options));
|
|
}
|
|
/* eslint-enable no-await-in-loop -- await in loop is needed to emulate sequential user actions */
|