Skip to content

Commit

Permalink
chore: Add test for bug #1022 color by category (#1024)
Browse files Browse the repository at this point in the history
  • Loading branch information
tihuan authored Jul 9, 2024
1 parent 867311d commit 791e93d
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .infra/rdev/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ stack:
services:
explorer:
image:
tag: sha-151cb084
tag: sha-4b2072d4
replicaCount: 1
env:
# env vars common to all deployment stages
Expand Down
34 changes: 34 additions & 0 deletions client/__tests__/e2e/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ import {
} from "../util/helpers";
import { SCALE_MAX_HIRES } from "../../src/util/constants";
import { PANEL_EMBEDDING_MINIMIZE_TOGGLE_TEST_ID } from "../../src/components/PanelEmbedding/constants";
import { CONTINUOUS_SECTION_TEST_ID } from "../../src/components/continuous/constants";
import { CATEGORICAL_SECTION_TEST_ID } from "../../src/components/categorical/constants";

const { describe, skip } = test;

Expand Down Expand Up @@ -264,6 +266,38 @@ for (const testDataset of testDatasets) {
}
});

/**
* https://github.com/chanzuckerberg/single-cell-explorer/issues/1022
*/
test("bug fix color by category #1022", async ({
page,
}, testInfo) => {
skipIfSidePanel(graphTestId, MAIN_PANEL);

await goToPage(page, url);

// Expand category
for (const label of Object.keys(
data.categorical
) as (keyof typeof data.categorical)[]) {
await page.getByTestId(`${label}:category-expand`).click();
}

await page
.getByTestId(CONTINUOUS_SECTION_TEST_ID)
.getByTestId(/colorby-/)
.first()
.click();

await page
.getByTestId(CATEGORICAL_SECTION_TEST_ID)
.getByTestId(/colorby-/)
.first()
.click();

await snapshotTestGraph(page, testInfo);
});

test("selects cells via lasso", async ({ page }, testInfo) => {
// TODO: fix bug for side panel where subset1 doesn't reset after layout switch
skipIfSidePanel(graphTestId, MAIN_PANEL);
Expand Down
9 changes: 7 additions & 2 deletions client/src/components/categorical/category/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SKELETON } from "@blueprintjs/core/lib/esnext/common/classes";
import React, { useRef, useEffect } from "react";
import { connect, shallowEqual } from "react-redux";
import { FaChevronRight, FaChevronDown } from "react-icons/fa";
import { AnchorButton, Classes, Position, Tooltip } from "@blueprintjs/core";
import { Button, Classes, Position, Tooltip } from "@blueprintjs/core";
import Async, { AsyncProps } from "react-async";
import memoize from "memoize-one";

Expand Down Expand Up @@ -311,6 +311,11 @@ class Category extends React.PureComponent<CategoryProps> {
<Async.Fulfilled persist>
{(asyncProps: CategoryAsyncProps) => {
const {
/**
* (thuang): `colorAccessor` needs to be accessed from `asyncProps` instead
* of `this.props.colors` to prevent the bug below
* https://github.com/chanzuckerberg/single-cell-explorer/issues/1022
*/
colorAccessor,
colorTable,
colorData,
Expand Down Expand Up @@ -485,7 +490,7 @@ const CategoryHeader = React.memo(
hide: { enabled: false },
}}
>
<AnchorButton
<Button
data-testid={`colorby-${metadataField}`}
onClick={onColorChangeClick}
active={isColorAccessor}
Expand Down
1 change: 1 addition & 0 deletions client/src/components/categorical/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const CATEGORICAL_SECTION_TEST_ID = "categorical-section";
2 changes: 2 additions & 0 deletions client/src/components/categorical/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Collapse from "../../util/collapse";
import { ControlsHelpers } from "../../util/stateManager";
import { track } from "../../analytics";
import { EVENTS } from "../../analytics/events";
import { CATEGORICAL_SECTION_TEST_ID } from "./constants";

// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
type State = any;
Expand Down Expand Up @@ -152,6 +153,7 @@ class Categories extends React.Component<{}, State> {
);
return (
<div
data-testid={CATEGORICAL_SECTION_TEST_ID}
style={{
padding: globals.leftSidebarSectionPadding,
paddingBottom: 0,
Expand Down
1 change: 1 addition & 0 deletions client/src/components/continuous/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const CONTINUOUS_SECTION_TEST_ID = "continuous-section";
3 changes: 2 additions & 1 deletion client/src/components/continuous/continuous.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Collapse from "../../util/collapse";
import { RootState } from "../../reducers";
import AnnoMatrix from "../../annoMatrix/annoMatrix";
import { AnnotationColumnSchema } from "../../common/types/schema";
import { CONTINUOUS_SECTION_TEST_ID } from "./constants";

interface StateProps {
schema?: AnnoMatrix["schema"];
Expand All @@ -32,7 +33,7 @@ class Continuous extends React.PureComponent<StateProps> {
.filter((col: AnnotationColumnSchema) => !col.writable) // skip user annotations - they will be treated as categorical
.map((col: AnnotationColumnSchema) => col.name);
return allContinuousNames.length ? (
<div>
<div data-testid={CONTINUOUS_SECTION_TEST_ID}>
<Collapse>
<span style={{ paddingLeft: 10 }}>Continuous</span>
{allContinuousNames.map((key, index) => (
Expand Down

0 comments on commit 791e93d

Please sign in to comment.