Skip to content

Commit

Permalink
Introduce a collection of behavioural unit tests for navigation
Browse files Browse the repository at this point in the history
This reverts commit ecd881c25df219b511d7efd43dac59e748b21cc7.

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>
  • Loading branch information
Iku-turso and jansav committed Mar 30, 2022
1 parent 2851582 commit 104ce24
Show file tree
Hide file tree
Showing 38 changed files with 17,978 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`extension special characters in page registrations renders 1`] = `<div />`;

exports[`extension special characters in page registrations when navigating to route with ID having special characters renders 1`] = `
<div>
<div>
Some page
</div>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`navigate to extension page renders 1`] = `<div />`;

exports[`navigate to extension page when extension navigates to child route renders 1`] = `
<div>
<div>
Child page
</div>
</div>
`;

exports[`navigate to extension page when extension navigates to route with parameters renders 1`] = `
<div>
<div>
<ul>
<li>
some-string-value-from-navigate
</li>
<li>
126
</li>
<li>
some-array-value-from-navigate
</li>
</ul>
<button
data-testid="button-to-change-page-parameters"
type="button"
>
Some button
</button>
</div>
</div>
`;

exports[`navigate to extension page when extension navigates to route without parameters renders 1`] = `
<div>
<div>
<ul>
<li>
some-string-value
</li>
<li>
42
</li>
<li>
some-array-value,some-other-array-value
</li>
</ul>
<button
data-testid="button-to-change-page-parameters"
type="button"
>
Some button
</button>
</div>
</div>
`;

exports[`navigate to extension page when extension navigates to route without parameters when changing page parameters renders 1`] = `
<div>
<div>
<ul>
<li>
some-changed-string-value
</li>
<li>
84
</li>
<li>
some-changed-array-value,some-other-changed-array-value
</li>
</ul>
<button
data-testid="button-to-change-page-parameters"
type="button"
>
Some button
</button>
</div>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`navigating between routes given route with optional path parameters when navigating to route with path parameters renders 1`] = `
<div>
<pre>
{
"someParameter": "some-value",
"someOtherParameter": "some-other-value"
}
</pre>
</div>
`;

exports[`navigating between routes given route without path parameters when navigating to route renders 1`] = `
<div>
<div>
Some component
</div>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`add-cluster - navigation using application menu renders 1`] = `<div />`;

exports[`add-cluster - navigation using application menu when navigating to add cluster using application menu renders 1`] = `
<div>
<div
class="SettingLayout"
data-testid="add-cluster-page"
>
<div
class="contentRegion"
id="ScrollSpyRoot"
>
<div
class="content flex column gaps"
>
<h2>
Add Clusters from Kubeconfig
</h2>
<p>
Clusters added here are
<b>
not
</b>
merged into the
<code>
~/.kube/config
</code>
file.
<a
href="https://docs.k8slens.dev/main//catalog/add-clusters/"
rel="noreferrer"
target="_blank"
>
Read more about adding clusters
</a>
.
</p>
<div
class="flex column"
/>
<div
class="actions-panel"
>
<button
class="Button primary"
disabled=""
type="button"
>
Add clusters
</button>
</div>
</div>
<div
class="toolsRegion"
>
<div
class="fixed top-[60px]"
>
<div>
<div
aria-label="Close"
role="button"
>
<i
class="Icon material focusable"
>
<span
class="icon"
data-icon-name="close"
>
close
</span>
</i>
</div>
<div
aria-hidden="true"
>
ESC
</div>
</div>
</div>
</div>
</div>
</div>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/

import type { RenderResult } from "@testing-library/react";
import { ApplicationBuilder, getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import isAutoUpdateEnabledInjectable from "../../main/is-auto-update-enabled.injectable";

// TODO: Make components free of side effects by making them deterministic
jest.mock("../../renderer/components/tooltip");
jest.mock("../../renderer/components/monaco-editor/monaco-editor");

describe("add-cluster - navigation using application menu", () => {
let applicationBuilder: ApplicationBuilder;
let rendered: RenderResult;

beforeEach(async () => {
applicationBuilder = getApplicationBuilder().beforeSetups(({ mainDi }) => {
mainDi.override(isAutoUpdateEnabledInjectable, () => () => false);
});

rendered = await applicationBuilder.render();
});

it("renders", () => {
expect(rendered.container).toMatchSnapshot();
});

it("does not show welcome page yet", () => {
const actual = rendered.queryByTestId("add-cluster-page");

expect(actual).toBeNull();
});

describe("when navigating to add cluster using application menu", () => {
beforeEach(() => {
applicationBuilder.applicationMenu.click("file.add-cluster");
});

it("renders", () => {
expect(rendered.container).toMatchSnapshot();
});

it("shows add cluster page", () => {
const actual = rendered.getByTestId("add-cluster-page");

expect(actual).not.toBeNull();
});
});
});
Loading

0 comments on commit 104ce24

Please sign in to comment.