Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1868475: Adds test for independent Mode Dashboard #5293

Merged
merged 1 commit into from Aug 14, 2020

Conversation

a2batic
Copy link
Contributor

@a2batic a2batic commented May 4, 2020

Unit test on breakdown card and details card for independent mode.

Signed-off-by: Kanika kmurarka@redhat.com

@openshift-ci-robot openshift-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. component/ceph Related to ceph-storage-plugin labels May 4, 2020
import { BreakdownCardBody } from "../../components/dashboard-page/storage-dashboard/breakdown-card/breakdown-body";
import DashboardCardTitle from "@console/shared/src/components/dashboard/dashboard-card/DashboardCardTitle";
import { HeaderPrometheusViewLink } from "../../components/dashboard-page/storage-dashboard/breakdown-card/breakdown-header";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort the imports properly

@a2batic a2batic changed the title [WIP] Adds test for independent Mode Dashboard Adds test for independent Mode Dashboard May 26, 2020
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 26, 2020
@a2batic
Copy link
Contributor Author

a2batic commented May 27, 2020

/assign @vojtechszocs

@a2batic
Copy link
Contributor Author

a2batic commented May 27, 2020

/test e2e-gcp-console

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 28, 2020
Copy link
Contributor

@bipuladh bipuladh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand the gist of these tests. If these are tests for Individual cards then we should move them to specific cards. I am not sure if we are testing specifically anything in Independent Mode dashboard.

Comment on lines 40 to 68
it('Should render Card Header', () => {
expect(wrapper.find(DashboardCardHeader).exists()).toBe(true);
});

it('Should render Card Title', () => {
expect(wrapper.find(DashboardCardTitle).exists()).toBe(true);
});

it('Should render Prometheus Header Link', () => {
expect(wrapper.find(HeaderPrometheusViewLink).exists()).toBe(true);
expect(wrapper.find(HeaderPrometheusViewLink).props().link).toEqual(headerLink);
});

it('Should render Dropdown', () => {
expect(wrapper.find(Dropdown).exists()).toBe(true);
expect(wrapper.find(Dropdown).props().items).toEqual(dropDownItems);
expect(wrapper.find(Dropdown).props().title).toEqual('Projects');
});

it('Should render Card body', () => {
expect(wrapper.find(DashboardCardBody).exists()).toBe(true);
});

it('Should render Breakdown Card body', () => {
expect(wrapper.find(BreakdownCardBody).exists()).toBe(true);
expect(wrapper.find(BreakdownCardBody).props().isLoading).toBe(true);
expect(wrapper.find(BreakdownCardBody).props().hasLoadError).toBe(false);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are part of Breakdown Card right? Why are we testing them again? We should only test whether Breakdown card is getting rendered or not. If these tests are not there in Breakdown lets add them there rather than here.

Copy link
Contributor Author

@a2batic a2batic May 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bipuladh these tests are for breakdown card of independent mode. All these component are part of the card directly, looking at the component.

I believe test related to how breakdown card uses props should be part of the breakdown-card test. But, as part of this card, we should add test related to expected props been sent to breakdown component, because they are set and calculated here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are part of Breakdown Card right?

It seems that BreakdownCard component tested here is OCS / independent mode specific. The code is currently in src/components/independent-dashboard-page/breakdown-card/card.tsx.

Similarly, there is e.g. (OCS specific) UtilizationCard in src/components/independent-dashboard-page/utilization-card/card.tsx.

Both of these are built on top of DashboardCard which is a core Console component.

What we're missing here (I think) is a test for the core DashboardCard component:

git grep 'DashboardCard' *.spec.*
# no results

For now, I'm OK with these tests being here. In future, we should refactor & move relevant bits into ^^ spec.

cc @rawagner

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we have a core DashboardCard spec, tests for OCS specific components built on top of it should only test the OCS specifics (in terms of their render output or behavior).

Comment on lines 33 to 45
it('Should render Card Header', () => {
expect(wrapper.find(DashboardCardHeader).exists()).toBe(true);
});

it('Should render Card Title', () => {
expect(wrapper.find(DashboardCardTitle).exists()).toBe(true);
});

it('Should render details properly', () => {
expect(wrapper.find('[data-test-id="cluster-name"]').text()).toEqual('foo');
expect(wrapper.find('[data-test-id="cluster-subscription"]').text()).toEqual('fooVersion');
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This again should be part of details card. We can add these tests in console-shared.

urlResults: 'foo',
prometheusResults: {
// eslint-disable-next-line no-new-func
getIn: new Function(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simply use the function declaration syntax:

Suggested change
getIn: new Function(),
getIn: () => {},

Using the new Function constructor is generally deprecated since it has the following characteristics:

  • it is completely dynamic, i.e. function's body is a string that needs to be parsed & evaluated (*)
  • runs in global context, i.e. the code does not create closures to their creation context (unlike eval)

(*) this also has security & performance implications

@@ -0,0 +1,67 @@
export const DashboardItems = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest naming this file independent-mode-dashboard-data.ts since it contains test data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'd name this dashboardData

Suggested change
export const DashboardItems = {
export const dashboardData = {

@@ -0,0 +1,68 @@
import * as React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have a structure like:

$ tree packages/ceph-storage-plugin/src/components/independent-dashboard-page
packages/ceph-storage-plugin/src/components/independent-dashboard-page
|-- breakdown-card
|   `-- card.tsx
|-- details-card
|   `-- card.tsx
|-- status-card
|   `-- card.tsx
`-- utilization-card
    `-- card.tsx

I'd suggest to simplify it to:

|-- breakdown-card.tsx
|-- details-card.tsx
|-- status-card.tsx
`-- utilization-card.tsx

Also, please keep the path convention for better test vs. tested-unit correlation, by placing this spec at

src/__tests__/independent-dashboard-page/breakdown-card.spec.tsx

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you're following a single-test-directory convention in Ceph plugin:

$ find packages/ceph-storage-plugin/src -type d -name __tests__
packages/ceph-storage-plugin/src/__tests__

in which case it's more important to keep your __tests__ structure well organized, in my opinion.

beforeEach(() => {
wrapper = shallow(
<BreakdownCard
watchPrometheus={DashboardItems.watchPrometheus as any}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
watchPrometheus={DashboardItems.watchPrometheus as any}
watchPrometheus={dashboardData.watchPrometheus as any}

'Storage Classes': 'Storage Classes',
};

export const headerLink =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

headerLink and dropDownItems are treated as expected test data.

Therefore, I'd suggest naming them expectedDropDownItems and expectedHeaderLink respectively.

export const headerLink =
'topk(20, (sum(kubelet_volume_stats_used_bytes * on (namespace,persistentvolumeclaim) group_left(storageclass, provisioner) (kube_persistentvolumeclaim_info * on (storageclass) group_left(provisioner) kube_storageclass_info {provisioner=~"(.*rbd.csi.ceph.com)|(.*cephfs.csi.ceph.com)|(ceph.rook.io/block)"})) by (namespace)))';

export const detailsCardData = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not simply move detailsCardData.resources into dashboardData.resources and remove the detailsCardData export?

This way, you'll have a single source of test data (dashboardData) that can be used in all relevant tests.

Comment on lines 40 to 68
it('Should render Card Header', () => {
expect(wrapper.find(DashboardCardHeader).exists()).toBe(true);
});

it('Should render Card Title', () => {
expect(wrapper.find(DashboardCardTitle).exists()).toBe(true);
});

it('Should render Prometheus Header Link', () => {
expect(wrapper.find(HeaderPrometheusViewLink).exists()).toBe(true);
expect(wrapper.find(HeaderPrometheusViewLink).props().link).toEqual(headerLink);
});

it('Should render Dropdown', () => {
expect(wrapper.find(Dropdown).exists()).toBe(true);
expect(wrapper.find(Dropdown).props().items).toEqual(dropDownItems);
expect(wrapper.find(Dropdown).props().title).toEqual('Projects');
});

it('Should render Card body', () => {
expect(wrapper.find(DashboardCardBody).exists()).toBe(true);
});

it('Should render Breakdown Card body', () => {
expect(wrapper.find(BreakdownCardBody).exists()).toBe(true);
expect(wrapper.find(BreakdownCardBody).props().isLoading).toBe(true);
expect(wrapper.find(BreakdownCardBody).props().hasLoadError).toBe(false);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are part of Breakdown Card right?

It seems that BreakdownCard component tested here is OCS / independent mode specific. The code is currently in src/components/independent-dashboard-page/breakdown-card/card.tsx.

Similarly, there is e.g. (OCS specific) UtilizationCard in src/components/independent-dashboard-page/utilization-card/card.tsx.

Both of these are built on top of DashboardCard which is a core Console component.

What we're missing here (I think) is a test for the core DashboardCard component:

git grep 'DashboardCard' *.spec.*
# no results

For now, I'm OK with these tests being here. In future, we should refactor & move relevant bits into ^^ spec.

cc @rawagner

Comment on lines 40 to 68
it('Should render Card Header', () => {
expect(wrapper.find(DashboardCardHeader).exists()).toBe(true);
});

it('Should render Card Title', () => {
expect(wrapper.find(DashboardCardTitle).exists()).toBe(true);
});

it('Should render Prometheus Header Link', () => {
expect(wrapper.find(HeaderPrometheusViewLink).exists()).toBe(true);
expect(wrapper.find(HeaderPrometheusViewLink).props().link).toEqual(headerLink);
});

it('Should render Dropdown', () => {
expect(wrapper.find(Dropdown).exists()).toBe(true);
expect(wrapper.find(Dropdown).props().items).toEqual(dropDownItems);
expect(wrapper.find(Dropdown).props().title).toEqual('Projects');
});

it('Should render Card body', () => {
expect(wrapper.find(DashboardCardBody).exists()).toBe(true);
});

it('Should render Breakdown Card body', () => {
expect(wrapper.find(BreakdownCardBody).exists()).toBe(true);
expect(wrapper.find(BreakdownCardBody).props().isLoading).toBe(true);
expect(wrapper.find(BreakdownCardBody).props().hasLoadError).toBe(false);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we have a core DashboardCard spec, tests for OCS specific components built on top of it should only test the OCS specifics (in terms of their render output or behavior).

@a2batic
Copy link
Contributor Author

a2batic commented Jun 29, 2020

@vojtechszocs addressed review comments, please review.

Signed-off-by: Kanika <kmurarka@redhat.com>
@a2batic
Copy link
Contributor Author

a2batic commented Aug 12, 2020

@vojtechszocs addressed review comments, please review.

@a2batic
Copy link
Contributor Author

a2batic commented Aug 12, 2020

/test e2e-gcp-console

@a2batic a2batic changed the title Adds test for independent Mode Dashboard Bug 1868475 : Adds test for independent Mode Dashboard Aug 12, 2020
@a2batic a2batic changed the title Bug 1868475 : Adds test for independent Mode Dashboard Bug 1868475: Adds test for independent Mode Dashboard Aug 12, 2020
@openshift-ci-robot openshift-ci-robot added the bugzilla/severity-low Referenced Bugzilla bug's severity is low for the branch this PR is targeting. label Aug 12, 2020
@openshift-ci-robot
Copy link
Contributor

@a2batic: This pull request references Bugzilla bug 1868475, which is invalid:

  • expected the bug to target the "4.6.0" release, but it targets "---" instead

Comment /bugzilla refresh to re-evaluate validity if changes to the Bugzilla bug are made, or edit the title of this pull request to link to a different bug.

In response to this:

Bug 1868475: Adds test for independent Mode Dashboard

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot added the bugzilla/invalid-bug Indicates that a referenced Bugzilla bug is invalid for the branch this PR is targeting. label Aug 12, 2020
@a2batic
Copy link
Contributor Author

a2batic commented Aug 12, 2020

/bugzilla refresh

@openshift-ci-robot openshift-ci-robot added the bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. label Aug 12, 2020
@openshift-ci-robot
Copy link
Contributor

@a2batic: This pull request references Bugzilla bug 1868475, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.6.0) matches configured target release for branch (4.6.0)
  • bug is in the state NEW, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

In response to this:

/bugzilla refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot removed the bugzilla/invalid-bug Indicates that a referenced Bugzilla bug is invalid for the branch this PR is targeting. label Aug 12, 2020
@a2batic
Copy link
Contributor Author

a2batic commented Aug 12, 2020

/test e2e-gcp-console

@vojtechszocs
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 13, 2020
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: a2batic, gnehapk, vojtechszocs

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

3 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@a2batic
Copy link
Contributor Author

a2batic commented Aug 14, 2020

/retest

@openshift-merge-robot openshift-merge-robot merged commit 950853a into openshift:master Aug 14, 2020
@openshift-ci-robot
Copy link
Contributor

@a2batic: All pull requests linked via external trackers have merged: openshift/console#5293. Bugzilla bug 1868475 has been moved to the MODIFIED state.

In response to this:

Bug 1868475: Adds test for independent Mode Dashboard

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@spadgett spadgett added this to the v4.6 milestone Aug 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. bugzilla/severity-low Referenced Bugzilla bug's severity is low for the branch this PR is targeting. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. component/ceph Related to ceph-storage-plugin lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants