mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-02 22:28:11 +08:00
Create Truncation Component (#1500)
* remove ESLint rules
operator-linebreak is no different then default
quotes is overwriting prettier config
* add string-pixel-width dep
* don't lint-staged src, only staged
* add widthMap
* create Truncate component
* refactor in truncate component
* add font load checking
* remove font-family styling
* render Truncate's child instead of creating own component to render
* refactor to use Truncate component
* add span back
* support children
* remove maybeTruncateString
* sub in Truncate component
* add bold prop
* accurately compute largest possible string
* remove logs
* tweak truncation method
* memoize comp function
* explain disable
* fix bugs w/ abs/floor
* tweak widths
* tweak widths
* fix font size
* remove border
* move test-id
* attempt css solution
* Revert "attempt css solution"
This reverts commit aac4d8a6f6.
* CSS solution v2
* remove string-pixel-width
* remove widthsMap
* remove dead code
* remove "data-truncated" as it is always true
* tweak label width
* fix e2e tests
* remove testing string
* e2e annotations tweaks
* correct snapshot
* remove resolves
* check for labels
* add test-id
* format fix
* update snapshot
* fix color
* pull constants out where available
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`did launch page launched 1`] = `"<span style=\\"width: 185px; display: flex; overflow: hidden; justify-content: flex-start;\\"><span style=\\"overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 1; min-width: 5px;\\">pbm</span><span style=\\"color: transparent; position: relative; overflow: hidden; white-space: nowrap;\\">c3k<span style=\\"position: absolute; right: 0px; color: initial;\\">c3k</span></span></span>"`;
|
||||
|
||||
exports[`metadata loads categories and values from dataset appear 1`] = `"<div style=\\"display: flex; justify-content: space-between; align-items: baseline;\\"><div style=\\"display: flex; justify-content: flex-start; align-items: flex-start;\\"><label class=\\"bp3-control bp3-checkbox\\" for=\\"category-select-louvain\\"><input id=\\"category-select-louvain\\" data-testclass=\\"category-select\\" data-testid=\\"louvain:category-select\\" type=\\"checkbox\\" checked=\\"\\"><span class=\\"bp3-control-indicator\\"></span></label><span role=\\"menuitem\\" tabindex=\\"0\\" data-testid=\\"louvain:category-expand\\" style=\\"cursor: pointer;\\"><span class=\\"bp3-popover-wrapper\\"><span class=\\"bp3-popover-target\\"><span data-testid=\\"louvain:category-label\\" aria-label=\\"louvain\\" class=\\"\\" tabindex=\\"0\\" style=\\"max-width: 265px;\\"><span style=\\"max-width: 265px; display: flex; overflow: hidden; justify-content: flex-start;\\"><span style=\\"overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 1; min-width: 5px;\\">lou</span><span style=\\"color: transparent; position: relative; overflow: hidden; white-space: nowrap;\\">vain<span style=\\"position: absolute; right: 0px; color: initial;\\">vain</span></span></span></span></span></span><svg stroke=\\"currentColor\\" fill=\\"currentColor\\" stroke-width=\\"0\\" viewBox=\\"0 0 320 512\\" data-testclass=\\"category-expand-is-not-expanded\\" height=\\"1em\\" width=\\"1em\\" xmlns=\\"http://www.w3.org/2000/svg\\" style=\\"font-size: 10px; margin-left: 5px;\\"><path d=\\"M285.476 272.971L91.132 467.314c-9.373 9.373-24.569 9.373-33.941 0l-22.667-22.667c-9.357-9.357-9.375-24.522-.04-33.901L188.505 256 34.484 101.255c-9.335-9.379-9.317-24.544.04-33.901l22.667-22.667c9.373-9.373 24.569-9.373 33.941 0L285.475 239.03c9.373 9.372 9.373 24.568.001 33.941z\\"></path></svg></span></div><div><span class=\\"bp3-popover-wrapper\\"><span class=\\"bp3-popover-target\\"><a role=\\"button\\" data-testclass=\\"colorby\\" data-testid=\\"colorby-louvain\\" class=\\"bp3-button\\" tabindex=\\"0\\"><span icon=\\"tint\\" class=\\"bp3-icon bp3-icon-tint\\"><svg data-icon=\\"tint\\" width=\\"16\\" height=\\"16\\" viewBox=\\"0 0 16 16\\"><desc>tint</desc><path d=\\"M7.88 1s-4.9 6.28-4.9 8.9c.01 2.82 2.34 5.1 4.99 5.1 2.65-.01 5.03-2.3 5.03-5.13C12.99 7.17 7.88 1 7.88 1z\\" fill-rule=\\"evenodd\\"></path></svg></span></a></span></span></div></div><div style=\\"margin-left: 26px;\\"><div></div></div><div></div>"`;
|
||||
@@ -44,9 +44,10 @@ export const cellxgeneActions = (page, utils) => ({
|
||||
(rows) =>
|
||||
Object.fromEntries(
|
||||
rows.map((row) => {
|
||||
const cat = row.querySelector(
|
||||
"[data-testclass='categorical-value']"
|
||||
).innerText;
|
||||
const cat = row
|
||||
.querySelector("[data-testclass='categorical-value']")
|
||||
.getAttribute("aria-label");
|
||||
|
||||
const count = row.querySelector(
|
||||
"[data-testclass='categorical-value-count']"
|
||||
).innerText;
|
||||
|
||||
@@ -27,8 +27,10 @@ afterAll(() => {
|
||||
|
||||
describe("did launch", () => {
|
||||
test("page launched", async () => {
|
||||
const element = await utils.getOneElementInnerHTML("[data-testid='header']");
|
||||
expect(element).toBe(data.title);
|
||||
const element = await utils.getOneElementInnerHTML(
|
||||
"[data-testid='header']"
|
||||
);
|
||||
expect(element).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("terms of service, if they are there", async () => {
|
||||
@@ -46,10 +48,10 @@ describe("did launch", () => {
|
||||
describe("metadata loads", () => {
|
||||
test("categories and values from dataset appear", async () => {
|
||||
for (const label in data.categorical) {
|
||||
const categoryName = await utils.getOneElementInnerText(
|
||||
const elem = await utils.getOneElementInnerHTML(
|
||||
`[data-testid="category-${label}"]`
|
||||
);
|
||||
expect(categoryName).toMatch(label);
|
||||
expect(elem).toMatchSnapshot();
|
||||
await utils.clickOn(`${label}:category-expand`);
|
||||
const categories = await cxgActions.getAllCategoriesAndCounts(label);
|
||||
expect(Object.keys(categories)).toMatchObject(
|
||||
|
||||
@@ -201,16 +201,18 @@ describe.each([
|
||||
});
|
||||
|
||||
async function assertCategoryExists(categoryName) {
|
||||
const handle = await utils.waitByID(`${categoryName}:category-expand`);
|
||||
const result = await handle.evaluate((node) => node.innerText);
|
||||
// slice beginning and end of category name result to account for truncation of long names
|
||||
expect(result.slice(0, 10)).toBe(categoryName.slice(0, 10));
|
||||
expect(result.slice(-10)).toBe(categoryName.slice(-10));
|
||||
const handle = await utils.waitByID(`${categoryName}:category-label`);
|
||||
|
||||
const result = await handle.evaluate((node) =>
|
||||
node.getAttribute("aria-label")
|
||||
);
|
||||
|
||||
expect(result).toBe(categoryName);
|
||||
}
|
||||
|
||||
async function assertCategoryDoesNotExist(categoryName) {
|
||||
const result = await page.$(
|
||||
`[data-testid='${categoryName}:category-expand']`
|
||||
`[data-testid='${categoryName}:category-label']`
|
||||
);
|
||||
expect(result).toBeNull();
|
||||
}
|
||||
@@ -222,7 +224,9 @@ describe.each([
|
||||
const previous = await utils.waitByID(
|
||||
`categorical-value-${categoryName}-${labelName}`
|
||||
);
|
||||
expect(await previous.evaluate((node) => node.innerText)).toBe(labelName);
|
||||
expect(
|
||||
await previous.evaluate((node) => node.getAttribute("aria-label"))
|
||||
).toBe(labelName);
|
||||
}
|
||||
|
||||
async function assertLabelDoesNotExist(categoryName, labelName) {
|
||||
|
||||
Reference in New Issue
Block a user