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
Bug 1868475: Adds test for independent Mode Dashboard #5293
Conversation
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"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort the imports properly
/assign @vojtechszocs |
/test e2e-gcp-console |
There was a problem hiding this 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.
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); | ||
}); | ||
}); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
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'); | ||
}); | ||
}); |
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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:
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 = { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
export const DashboardItems = { | |
export const dashboardData = { |
@@ -0,0 +1,68 @@ | |||
import * as React from 'react'; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
watchPrometheus={DashboardItems.watchPrometheus as any} | |
watchPrometheus={dashboardData.watchPrometheus as any} |
'Storage Classes': 'Storage Classes', | ||
}; | ||
|
||
export const headerLink = |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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.
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); | ||
}); | ||
}); |
There was a problem hiding this comment.
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
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); | ||
}); | ||
}); |
There was a problem hiding this comment.
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).
@vojtechszocs addressed review comments, please review. |
Signed-off-by: Kanika <kmurarka@redhat.com>
84eeb16
to
703c7fa
Compare
@vojtechszocs addressed review comments, please review. |
/test e2e-gcp-console |
@a2batic: This pull request references Bugzilla bug 1868475, which is invalid:
Comment In response to this:
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. |
/bugzilla refresh |
@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
In response to this:
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. |
/test e2e-gcp-console |
/lgtm |
[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 |
/retest Please review the full test history for this PR and help us cut down flakes. |
3 similar comments
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest |
@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:
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. |
Unit test on breakdown card and details card for independent mode.
Signed-off-by: Kanika kmurarka@redhat.com