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
packages/dev-console/src/component/project-access: Add tests #3820
packages/dev-console/src/component/project-access: Add tests #3820
Conversation
9b26897
to
da1f2c8
Compare
@@ -40,4 +42,4 @@ const RenderProjectAccessPage: React.FC<RenderProjectAccessPageProps> = ({ names | |||
); | |||
}; | |||
|
|||
export default withStartGuide(RenderProjectAccessPage); | |||
export const RenderProjectAccessPage = withStartGuide(RenderProjectAccessPageComponent); |
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.
Change back to a default export.
import { LoadingBox, StatusBox } from '@console/internal/components/utils'; | ||
import ProjectAccess, { ProjectAccessProps } from '../ProjectAccess'; | ||
|
||
const projectAccessProps: ProjectAccessProps = { |
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 are now using React.ComponentProps
instead of exporting the props type.
Please update the references.
You are also mutating the same instance across multiple tests. You should be creating it new before each test.
@@ -8,7 +8,9 @@ export interface RenderProjectAccessPageProps { | |||
namespace: string; | |||
} | |||
|
|||
const RenderProjectAccessPage: React.FC<RenderProjectAccessPageProps> = ({ namespace }) => { | |||
export const RenderProjectAccessPageComponent: React.FC<RenderProjectAccessPageProps> = ({ |
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.
Change name back to RenderProjectAccessPage once the default export is reverted.
}; | ||
|
||
describe('Project Access', () => { | ||
let renderProjectAccess: ShallowWrapper<ProjectAccessProps>; |
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.
No need for the declaration to be here. Can leave it inside the individual tests.
it('should show the LoadingBox when role bindings are not loaded, but user has access to role bindings', () => { | ||
projectAccessProps.roleBindings.loaded = false; | ||
renderProjectAccess = shallow(<ProjectAccess {...projectAccessProps} />); | ||
expect(renderProjectAccess.exists()).toBe(true); |
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 assertion is unnecessary because the wrapper will always exist.
enzymejs/enzyme#1864
|
||
describe('Project Access Page', () => { | ||
let wrapper: ShallowWrapper<ProjectAccessPageProps>; | ||
let projectAccessPageProps; |
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.
Unnecessary to have declaration of props here.
da1f2c8
to
14e1da9
Compare
@@ -1,7 +1,7 @@ | |||
import * as React from 'react'; | |||
import { match as RMatch } from 'react-router'; | |||
import { NamespaceBar } from '@console/internal/components/namespace'; | |||
import RenderProjectAccessPage, { RenderProjectAccessPageProps } from './RenderProjectAccessPage'; | |||
import RenderProjectAccess from './RenderProjectAccessPage'; |
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 the name change is required?
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.
Otherwise, it gives import/no-named-as-default
lint error. The RenderProjectAccess
points to the default export in the RenderProjectAccessPage.tsx
file. Please do let me know if there's any other alternative for this
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.
What I meant is,
why not
import RenderProjectAccessPage from './RenderProjectAccessPage'
in lieu of import RenderProjectAccess from './RenderProjectAccessPage'
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.
In the RenderProjectAccessPage
component, I have used RenderProjectAccessPage
as default export (for real usage) and named export (for testing). Because of this change it gives me an import/no-named-as-default
lint error in the ProjectAccessPage.tsx
file where the component is being imported. To fix this error I had to import it like import RenderProjectAccess from './RenderProjectAccessPage'
, here RenderProjectAccess
points to the default export
squash commits into 1 |
840526a
to
5a11439
Compare
|
||
describe('Project Access', () => { | ||
it('should show the LoadingBox when role bindings are not loaded, but user has access to role bindings', () => { | ||
const projectAccessProps: ProjectAccessProps = { |
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.
You can declare this inside beforeEach block and change the specific prop of this object in each test case. No need to declare this in each test case
move test data from `mocks` to `tests` folder
5a11439
to
b410843
Compare
/kind cleanup |
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.
/assign
const props: React.ComponentProps<typeof ProjectAccess> = { | ||
formName: 'project access', | ||
namespace, | ||
}; |
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 variable creation is a bit bizarre in itself... was there any reason why you separated this into a variable instead of directly on the component? (originally when you did the feature - no change needed now, just curious)
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.
@andrewballantyne yes, I could have directly passed formName and namespace. It might have gone unnoticed when I did the feature
/test e2e-gcp-console |
1 similar comment
/test e2e-gcp-console |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: andrewballantyne, debsmita1, invincibleJai 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 |
/hold |
/test e2e-gcp-console |
/test analyze |
/hold cancel |
/retest Please review the full test history for this PR and help us cut down flakes. |
9 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 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 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. |
Added tests for :
Refer Jira tasks :