Skip to content

Commit

Permalink
Well completion unit tests (equinor#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
avanti-em authored Jun 23, 2021
1 parent 83dc678 commit c657e08
Show file tree
Hide file tree
Showing 10 changed files with 341 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ describe("Test Filter Menu", () => {
type: "ui/updateIsDrawerOpen",
});
});
it("Test tooltip title when menu not open", async () => {
render(<FilterMenu />, {
wrapper: Wrapper,
});
fireEvent.mouseOver(screen.getByTestId("filter_button"));
expect(await screen.findByText("Filter")).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "@testing-library/jest-dom/extend-expect";
import { fireEvent, render, screen } from "@testing-library/react";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import "jest-styled-components";
import React from "react";
import { Wrapper } from "../../test/TestWrapper";
Expand All @@ -20,4 +20,20 @@ describe("Test view menu", () => {
);
await screen.findByText("Well sorting levels");
});

it("click OK to sort", async () => {
render(<SortButton />, {
wrapper: Wrapper,
});
fireEvent.click(
screen.getByRole("menuitem", { name: "Sort/Group by Attributes" })
);
await screen.findByText("Well sorting levels");
fireEvent.click(screen.getByRole("button", { name: "OK" }));
await waitFor(() => {
expect(
screen.queryByText("Well sorting levels")
).not.toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ describe("test time range selector", () => {
});
userEvent.type(screen.getByRole("slider"), "{arrowright}");
expect(testStore.dispatch).toHaveBeenCalledTimes(2);
expect(testStore.dispatch).toBeCalledWith({
payload: [0, -1],
expect(testStore.dispatch).toHaveBeenNthCalledWith(1, {
payload: [0, NaN],
type: "ui/updateTimeIndexRange",
});
expect(testStore.dispatch).toHaveBeenNthCalledWith(2, {
payload: [0, 9],
type: "ui/updateTimeIndexRange",
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
import "@testing-library/jest-dom/extend-expect";
import { render } from "@testing-library/react";
import { fireEvent, render, screen } from "@testing-library/react";
import "jest-styled-components";
import React from "react";
import { Wrapper } from "../../test/TestWrapper";
import { testStore, Wrapper } from "../../test/TestWrapper";
import WellAttributesSelector from "./WellAttributesSelector";

//Manually add the scrollTo because it is not implemented in jsdom
//Without it, the SmartNodeSelector reports TypeError: suggestionsRef.current.scrollTo is not a function
Element.prototype.scrollTo = jest.fn();

describe("test well attributes selector", () => {
it("snapshot test", () => {
const { container } = render(
Wrapper({ children: <WellAttributesSelector /> })
);
expect(container.firstChild).toMatchSnapshot();
});

it("click to dispatch redux action", async () => {
render(<WellAttributesSelector />, {
wrapper: Wrapper,
});

const attributeFilter = screen.getByRole("textbox");
fireEvent.change(attributeFilter, {
target: { value: "type:Injector" },
});
expect(testStore.dispatch).toHaveBeenCalledTimes(1);
expect(testStore.dispatch).toBeCalledWith({
payload: ["type:Injector"],
type: "ui/updateFilterByAttributes",
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,15 @@ describe("test pagination", () => {
type: "ui/updateCurrentPage",
});
});
it("click to dispatch redux action", async () => {
render(<WellPagination />, {
wrapper: Wrapper,
});
fireEvent.click(screen.getByText("1"));
expect(testStore.dispatch).toHaveBeenCalledTimes(4);
expect(testStore.dispatch).toBeCalledWith({
payload: 1,
type: "ui/updateCurrentPage",
});
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "@testing-library/jest-dom/extend-expect";
import { fireEvent, render, screen } from "@testing-library/react";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import "jest-styled-components";
import React from "react";
import { testStore, Wrapper } from "../../test/TestWrapper";
Expand All @@ -24,12 +25,46 @@ describe("test Zone Selector", () => {
});
});

it("click to dispatch redux action to remove one zone", async () => {
it("select 'zone1' check box to dispatch redux action and show only zone1", async () => {
render(<ZoneSelector />, {
wrapper: Wrapper,
});

fireEvent.click(screen.getByText(/select zone\(s\)\.\.\./i));
expect(screen.getByPlaceholderText("Search...")).toBeInTheDocument();
userEvent.click(screen.getByRole("button", { name: /remove all/i }));
const zoneFilter = screen.getByText(/select zone\(s\)\.\.\./i);
userEvent.click(zoneFilter);
const dropdown = screen.getByPlaceholderText("Search...");
await waitFor(() => expect(dropdown).toBeVisible());
userEvent.type(dropdown, "{down}");
userEvent.type(dropdown, "{enter}");

expect(testStore.dispatch).toHaveBeenCalledTimes(3);
expect(testStore.dispatch).toHaveBeenNthCalledWith(1, {
payload: [],
type: "ui/updateFilteredZones",
});
expect(testStore.dispatch).toHaveBeenNthCalledWith(2, {
payload: [],
type: "ui/updateFilteredZones",
});
expect(testStore.dispatch).toHaveBeenNthCalledWith(3, {
payload: [
"zone1.1",
"zone1.2",
"zone1.3",
"zone2.1",
"zone2.2",
"zone2.3",
"zone3.1",
"zone3.2",
"zone3.3",
"zone4.1",
"zone4.2",
"zone4.3",
"zone4.4",
"zone4.5",
],
type: "ui/updateFilteredZones",
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,64 @@ exports[`test settings bar snapshot test 1`] = `
/>
<input
type="hidden"
value="-1"
value="9"
/>
<span
class="MuiSlider-mark"
data-index="0"
style="left: 0%;"
/>
<span
class="MuiSlider-mark"
data-index="1"
style="left: 11.11111111111111%;"
/>
<span
class="MuiSlider-mark"
data-index="2"
style="left: 22.22222222222222%;"
/>
<span
class="MuiSlider-mark"
data-index="3"
style="left: 33.333333333333336%;"
/>
<span
class="MuiSlider-mark"
data-index="4"
style="left: 44.44444444444444%;"
/>
<span
class="MuiSlider-mark"
data-index="5"
style="left: 55.55555555555556%;"
/>
<span
class="MuiSlider-mark"
data-index="6"
style="left: 66.66666666666667%;"
/>
<span
class="MuiSlider-mark"
data-index="7"
style="left: 77.77777777777777%;"
/>
<span
class="MuiSlider-mark"
data-index="8"
style="left: 88.88888888888889%;"
/>
<span
class="MuiSlider-mark MuiSlider-markActive"
data-index="9"
style="left: 100%;"
/>
<span
aria-labelledby="time-step-slider-label"
aria-orientation="horizontal"
aria-valuemax="-1"
aria-valuemax="9"
aria-valuemin="0"
aria-valuenow="-1"
aria-valuenow="9"
class="MuiSlider-thumb MuiSlider-thumbColorPrimary PrivateValueLabel-open-9 PrivateValueLabel-thumb-8"
data-index="0"
role="slider"
Expand All @@ -279,7 +329,9 @@ exports[`test settings bar snapshot test 1`] = `
>
<span
class="PrivateValueLabel-label-12"
/>
>
2002-10-01
</span>
</span>
</span>
</span>
Expand All @@ -301,7 +353,58 @@ exports[`test settings bar snapshot test 1`] = `
<select
class="c5"
id="time-end-selector"
/>
>
<option
value="0"
>
2000-02-01
</option>
<option
value="1"
>
2000-06-01
</option>
<option
value="2"
>
2000-07-01
</option>
<option
value="3"
>
2000-10-01
</option>
<option
value="4"
>
2001-01-01
</option>
<option
value="5"
>
2001-03-01
</option>
<option
value="6"
>
2001-04-01
</option>
<option
value="7"
>
2001-10-01
</option>
<option
value="8"
>
2002-07-01
</option>
<option
value="9"
>
2002-10-01
</option>
</select>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit c657e08

Please sign in to comment.