Skip to content

Commit

Permalink
move individual feature importance tests for text dashboard to common…
Browse files Browse the repository at this point in the history
… e2e package folder to re-use for unit and notebook tests (microsoft#2299)
  • Loading branch information
imatiach-msft authored Aug 31, 2023
1 parent ffa1acb commit efbc451
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { IInterpretTextData } from "./IInterpretTextData";
import { IInterpretTextData } from "@responsible-ai/e2e";

const interpretTextDatasets = {
newsgroupBinaryData: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { describeIndividualFeatureImportance } from "../../../describer/interpretText/individualFeatureImportance/describeIndividualFeatureImportance";
import { describeTextIndividualFeatureImportance } from "@responsible-ai/e2e";

describeIndividualFeatureImportance("newsgroupBinaryData");
import { interpretTextDatasets } from "../../../../src/describer/interpretText/interpretTextDatasets";

describeTextIndividualFeatureImportance(
"newsgroupBinaryData",
interpretTextDatasets.newsgroupBinaryData
);
2 changes: 2 additions & 0 deletions libs/e2e/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export * from "./lib/describer/interpretText/IInterpretTextData";
export * from "./lib/describer/interpretText/individualFeatureImportance/describeTextIndividualFeatureImportance";
export * from "./lib/describer/modelAssessment/featureImportances/aggregateFeatureImportance/describeAggregateFeatureImportance";
export * from "./lib/describer/modelAssessment/causalAnalysis/describeCausalAnalysis";
export * from "./lib/describer/modelAssessment/dataBalance/describeDataBalance";
Expand Down
12 changes: 12 additions & 0 deletions libs/e2e/src/lib/describer/interpretText/Constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export enum Locators {
ClassImportanceWeights = "#ClassImportanceWeights",
TextChoiceGroup = "#TextChoiceGroup",
TextFeatureLegend = "#TextFeatureLegend",
TextHighlighting = "#TextHighlighting",
TextExplanationChart = "#TextExplanationChart",
TextTopKSlider = "#TextTopKSlider",
TextWordsDropdown = "#ClassImportanceWeights div.ms-Dropdown-container"
}
19 changes: 19 additions & 0 deletions libs/e2e/src/lib/describer/interpretText/dropdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export function selectDropdown(
selector: string,
item: string | number
): Cypress.Chainable<JQuery<HTMLElement>> {
cy.get(selector).eq(0).click();
return cy
.get(".ms-Callout")
.should("be.visible")
.get(".ms-Dropdown-optionText")
.contains(item)
.click();
}

export function getDropdownValue(selector: string): string | undefined {
return cy.$$(`${selector} .ms-Dropdown-title`).text();
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { Locators } from "../../../util/Constants";
import { Locators } from "../Constants";
import {
checkNumBars,
checkYAxisLabel,
checkNumLabels
} from "../../../util/validateBarChart";
} from "../validateBarChart";

export function describeBarChart(expectedNumValues: number): void {
describe("Sub bar chart", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { Locators } from "../../../util/Constants";
import { selectDropdown, getDropdownValue } from "../../../util/dropdown";
import { getDefaultTopKWords } from "../../../util/getDefaultTopKWords";
import { validateBarChart } from "../../../util/validateBarChart";
import { Locators } from "../Constants";
import { selectDropdown, getDropdownValue } from "../dropdown";
import { getDefaultTopKWords } from "../getDefaultTopKWords";
import { IInterpretTextData } from "../IInterpretTextData";
import { validateBarChart } from "../validateBarChart";

function validateTextBarChart(expectedNumValues: number): void {
validateBarChart(Locators.TextExplanationChart, expectedNumValues);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { Locators } from "../../../util/Constants";
import { Locators } from "../Constants";

export function describeLegend(): void {
describe("Legend", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { Locators } from "../../../util/Constants";
import { validateBarChart } from "../../../util/validateBarChart";
import { Locators } from "../Constants";
import { validateBarChart } from "../validateBarChart";

function validateTextBarChart(expectedNumValues: number): void {
validateBarChart(Locators.TextExplanationChart, expectedNumValues);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { Locators } from "../../../util/Constants";
import { getDefaultTopKWords } from "../../../util/getDefaultTopKWords";
import { validateBarChart } from "../../../util/validateBarChart";
import { Locators } from "../Constants";
import { getDefaultTopKWords } from "../getDefaultTopKWords";
import { IInterpretTextData } from "../IInterpretTextData";
import { validateBarChart } from "../validateBarChart";

function getSlider(): Cypress.Chainable<JQuery<HTMLElement>> {
return cy.get(`${Locators.TextTopKSlider} .ms-Slider-slideBox`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { Locators } from "../../../util/Constants";
import { Locators } from "../Constants";
import { IInterpretTextData } from "../IInterpretTextData";

export function describeTextHighlighting(dataShape: IInterpretTextData): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { getDefaultTopKWords } from "../../../util/getDefaultTopKWords";
import { interpretTextDatasets } from "../interpretTextDatasets";
import { getDefaultTopKWords } from "../getDefaultTopKWords";
import { IInterpretTextData } from "../IInterpretTextData";

import { describeBarChart } from "./describeBarChart";
import { describeClassImportanceWeightsDropdown } from "./describeClassImportanceWeightsDropdown";
Expand All @@ -13,10 +13,10 @@ import { describeTextHighlighting } from "./describeTextHighlighting";

const testName = "Individual feature importance";

export function describeIndividualFeatureImportance(
name: keyof typeof interpretTextDatasets
export function describeTextIndividualFeatureImportance(
name: string,
datasetShape: IInterpretTextData
): void {
const datasetShape = interpretTextDatasets[name];
describe(testName, () => {
before(() => {
cy.visit(`#/interpretText/${name}/light/english/Version-1`);
Expand Down

0 comments on commit efbc451

Please sign in to comment.