-
Notifications
You must be signed in to change notification settings - Fork 1.1k
adding unit tests #7581
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
Merged
Merged
adding unit tests #7581
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d41fb4d
unit tests
36b5914
working
b002b3e
Merge branch 'main' into unit-tests-2
4b5bffb
fixing tests
f8b0f90
Merge branch 'main' into unit-tests-2
329f9bc
Merge branch 'main' into unit-tests-2
ba9f0ad
add popover test
b88780b
remove comments
59ec94a
remove comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/components/FeatureFlags/__tests__/FeatureFlags.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import * as React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import FeatureFlags from '../index'; | ||
import FeatureFlagSummary from '../FeatureFlagSummary'; | ||
|
||
describe('FeatureFlags', () => { | ||
it('should render the FeatureFlags component', async () => { | ||
render(<FeatureFlags></FeatureFlags>); | ||
const element = await screen.findByRole('heading', { name: 'appSync' }); | ||
expect(element).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the FeatureFlagSummary component', async () => { | ||
const flag = { | ||
description: | ||
'Changes the permission format to grant access to graphql operations instead of appsync control plane operations', | ||
type: 'Feature', | ||
valueType: 'Boolean', | ||
versionAdded: '4.42.0', | ||
deprecationDate: 'May 1st 2021', | ||
values: [ | ||
{ | ||
value: 'true', | ||
description: 'Creates IAM policies to allow Query/Mutations', | ||
defaultNewProject: true, | ||
defaultExistingProject: false | ||
}, | ||
{ | ||
value: 'false', | ||
description: | ||
'Uses previous policy format which allows control plane access to AppSync', | ||
defaultNewProject: false, | ||
defaultExistingProject: true | ||
} | ||
] | ||
}; | ||
|
||
const component = ( | ||
<FeatureFlagSummary | ||
key={`feature-flag-summary-${1}`} | ||
name={'generateGraphQLPermissions'} | ||
feature={flag} | ||
/> | ||
); | ||
render(component); | ||
const element = await screen.findByRole('link', { | ||
name: 'generateGraphQLPermissions' | ||
}); | ||
expect(element).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the FeatureFlagSummary component without description if one doesn"t exist on the flag', async () => { | ||
const flag = { | ||
type: 'Feature', | ||
valueType: 'Boolean', | ||
versionAdded: '4.42.0', | ||
deprecationDate: 'May 1st 2021', | ||
values: [ | ||
{ | ||
value: 'true', | ||
description: 'Creates IAM policies to allow Query/Mutations', | ||
defaultNewProject: true, | ||
defaultExistingProject: false | ||
}, | ||
{ | ||
value: 'false', | ||
description: | ||
'Uses previous policy format which allows control plane access to AppSync', | ||
defaultNewProject: false, | ||
defaultExistingProject: true | ||
} | ||
] | ||
}; | ||
|
||
const component = ( | ||
<FeatureFlagSummary | ||
key={`feature-flag-summary-${1}`} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, |
||
name={'generateGraphQLPermissions'} | ||
feature={flag} | ||
/> | ||
); | ||
render(component); | ||
const element = await screen.findByRole('heading', { | ||
name: 'generateGraphQLPermissions' | ||
}); | ||
expect(element.nextElementSibling?.tagName).not.toBe('P'); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
src/components/FeatureLists/__tests__/FeatureLists.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import * as React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { FeatureList, FeatureItem, PlatformFeatureList } from '../index'; | ||
|
||
const routerMock = { | ||
__esModule: true, | ||
useRouter: () => { | ||
return { | ||
query: { platform: 'react' }, | ||
pathname: '/gen1/', | ||
asPath: '/gen1/' | ||
}; | ||
} | ||
}; | ||
|
||
jest.mock('next/router', () => routerMock); | ||
|
||
describe('FeatureLists', () => { | ||
const featureListComponent = ( | ||
<FeatureList heading="Deploy" level={2}> | ||
<FeatureItem | ||
linkText="SSR/SSG/ISR hosting support" | ||
href="/react/deploy-and-host/hosting/" | ||
> | ||
Deploy apps in Next.js, Nuxt.js, Gatsby, React, Vue, Angular (and more) | ||
by simply connecting your Git repository. | ||
</FeatureItem> | ||
</FeatureList> | ||
); | ||
|
||
it('should render the FeatureList component', async () => { | ||
render(featureListComponent); | ||
|
||
const heading = await screen.findByRole('heading', { name: 'Deploy' }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not blocking, but you can combine the H2 expect in this findByRole with:
|
||
|
||
expect(heading).toBeInTheDocument(); | ||
expect(heading.tagName).toBe('H2'); | ||
}); | ||
|
||
it('should render the FeatureItem component', async () => { | ||
render(featureListComponent); | ||
|
||
const link = await screen.findByRole('link', { | ||
name: 'SSR/SSG/ISR hosting support' | ||
}); | ||
|
||
expect(link).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the PlatformFeatureList component', async () => { | ||
render(<PlatformFeatureList platform="react" />); | ||
|
||
const link = await screen.findByRole('link', { | ||
name: 'Simple configuration' | ||
}); | ||
|
||
const heading = await screen.findByRole('heading', { | ||
name: 'Features for React' | ||
}); | ||
|
||
expect(link).toBeInTheDocument(); | ||
expect(heading).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/components/FrameworkGrid/__tests__/FrameworkGrid.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { FrameworkGrid } from '../index'; | ||
|
||
const routerMock = { | ||
__esModule: true, | ||
useRouter: () => { | ||
return { | ||
query: { platform: 'react' }, | ||
pathname: '/gen1/', | ||
asPath: '/gen1/' | ||
}; | ||
} | ||
}; | ||
|
||
jest.mock('next/router', () => routerMock); | ||
|
||
describe('FrameworkGrid', () => { | ||
const component = <FrameworkGrid currentKey="react" />; | ||
|
||
it('should render the FrameworkGrid component', async () => { | ||
render(component); | ||
const framework = await screen.findByRole('link', { name: 'React' }); | ||
expect(framework).toBeInTheDocument(); | ||
}); | ||
|
||
it('should highlight icon of the currentKey', async () => { | ||
render(component); | ||
const framework = await screen.findByRole('link', { name: 'React' }); | ||
expect(framework.classList).toContain('framework-grid__link--current'); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: Can we remove this key prop? I'm not seeing why we need it here.