Skip to content

Commit

Permalink
ConnectWithProject: Remove enzyme and convert tests to RTL (#5227)
Browse files Browse the repository at this point in the history
  • Loading branch information
kieftrav committed Mar 2, 2024
1 parent c7ee40d commit d601d3f
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function ConnectWithProject (props) {
<Grid columns={['repeat(auto-fill, minmax(280px, 1fr))']} gap='medium'>
{urls.map(urlObject =>
<ProjectLink
className={`connect-with-project-${urlObject.site}`}
key={urlObject.url}
urlObject={urlObject}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
export const ConnectWithProjectMock = {
project: {
display_name: 'Test Project',
urls: [
{
name: 'Bitbucket',
label: '',
path: 'test-project',
site: 'bitbucket.com',
url: 'https://bitbucket.com/test-project',
},
{
name: 'Facebook',
label: '',
path: 'test-project',
site: 'facebook.com',
url: 'https://facebook.com/test-project',
},
{
name: 'Github',
label: '',
path: 'test-project',
site: 'github.com',
url: 'https://github.com/test-project',
},
{
name: 'Instagram',
label: '',
path: 'test-project',
site: 'instagram.com',
url: 'https://instagram.com/test-project',
},
{
name: 'Medium',
label: '',
path: 'test-project',
site: 'medium.com',
url: 'https://medium.com/test-project',
},
{
name: 'Pinterest',
label: '',
path: 'test-project',
site: 'pinterest.com',
url: 'https://pinterest.com/test-project',
},
{
name: 'Reddit',
label: '',
path: 'test-project',
site: 'reddit.com',
url: 'https://reddit.com/test-project',
},
{
name: 'Tumblr',
label: '',
path: 'test-project',
site: 'tumblr.com',
url: 'https://tumblr.com/test-project',
},
{
name: 'Twitter',
label: '',
path: 'test-project',
site: 'twitter.com',
url: 'https://twitter.com/test-project',
},
{
name: 'Weibo',
label: '',
path: 'test-project',
site: 'weibo.com',
url: 'https://weibo.com/test-project',
},
{
name: 'Wordpress',
label: '',
path: 'test-project',
site: 'wordpress.com',
url: 'https://wordpress.com/test-project',
},
{
name: 'Youtube',
label: '',
path: 'test-project',
site: 'youtube.com',
url: 'https://youtube.com/test-project',
}
]
}
}

export const ConnectWithProjectEmptyMock = {
project: {
display_name: 'Test Project',
urls: []
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
import { shallow } from 'enzyme'

import ConnectWithProject from './ConnectWithProject'
import ProjectLink from './components/ProjectLink'

let wrapper
const PROJECT_NAME = 'project'
const URLS = [
{
label: 'foo',
url: 'bar'
}
]
import { render, screen, within } from '@testing-library/react'
import { composeStory } from '@storybook/react'
import Meta, { ConnectWithProject, ConnectWithProjectEmpty } from './ConnectWithProject.stories.js'
import { ConnectWithProjectMock } from './ConnectWithProject.mock'

describe('Component > ConnectWithProject', function () {
before(function () {
wrapper = shallow(<ConnectWithProject
projectName={PROJECT_NAME}
urls={URLS}
/>)
})

it('should render without crashing', function () {
expect(wrapper).to.be.ok()
describe('when the project has links', function() {
beforeEach(function () {
const ConnectWithProjectStory = composeStory(ConnectWithProject, Meta)
render(<ConnectWithProjectStory />)
})

ConnectWithProjectMock.project.urls.forEach(function (urlObject) {
it(`should render the ${urlObject.name} icon`, async function () {
screen.debug()
await expect(screen.getByLabelText(urlObject.name)).to.be.ok()
})

it(`should render the ${urlObject.name} link`, function () {
const el = document.getElementsByClassName(`connect-with-project-${urlObject.site}`)[0]
expect(within(el).getByRole('link')).to.have.property('href')
})

it(`should render the ${urlObject.name} label`, function () {
const el = document.getElementsByClassName(`connect-with-project-${urlObject.site}`)[0]
expect(within(el).getByText(`ConnectWithProject.ProjectLink.types.${urlObject.name.toLowerCase()}`)).to.exist()
})
})
})

it('should render a `ProjectLink` for each url', function () {
const projectLinks = wrapper.find(ProjectLink)
expect(projectLinks).to.have.lengthOf(1)
describe('when the project has no links', function() {
it('should render as nothing', function () {
const ConnectWithProjectStory = composeStory(ConnectWithProjectEmpty, Meta)
render(<ConnectWithProjectStory />)
expect(screen.queryAllByRole('link').length).to.equal(0)
})
})
})
Original file line number Diff line number Diff line change
@@ -1,84 +1,20 @@
import { Box } from 'grommet'
import ConnectWithProject from './ConnectWithProject'

const mockUrls = [
{
label: '',
path: 'test-project',
site: 'bitbucket.com'
},
{
label: '',
path: 'test-project',
site: 'facebook.com'
},
{
label: '',
path: 'test-project',
site: 'github.com'
},
{
label: '',
path: 'test-project',
site: 'instagram.com'
},
{
label: '',
path: 'test-project',
site: 'medium.com'
},
{
label: '',
path: 'test-project',
site: 'pinterest.com'
},
{
label: '',
path: 'test-project',
site: 'reddit.com'
},
{
label: '',
path: 'test-project',
site: 'tumblr.com'
},
{
label: '',
path: 'test-project',
site: 'twitter.com'
},
{
label: '',
path: 'test-project',
site: 'weibo.com'
},
{
label: '',
path: 'test-project',
site: 'wordpress.com'
},
{
label: '',
path: 'test-project',
site: 'youtube.com'
}
]

const args = {
projectName: 'Test Project',
urls: mockUrls
}
import { Provider } from 'mobx-react'
import ConnectWithProjectComponent from './index'
import { ConnectWithProjectMock, ConnectWithProjectEmptyMock } from './ConnectWithProject.mock'

export default {
title: 'Project App / Shared / ConnectWithProject',
component: ConnectWithProject,
args
component: ConnectWithProjectComponent,
}

export const Default = ({ projectName, urls }) => {
return (
<Box pad='xsmall'>
<ConnectWithProject projectName={projectName} urls={urls} />
</Box>
)
}
export const ConnectWithProject = () => (
<Provider store={ConnectWithProjectMock}>
<ConnectWithProjectComponent />
</Provider>
)

export const ConnectWithProjectEmpty = () => (
<Provider store={ConnectWithProjectEmptyMock}>
<ConnectWithProjectComponent />
</Provider>
)

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Blank } from 'grommet-icons'

function BitbucketIcon (props) {
return (
<Blank viewBox='0 0 50 45' {...props}>
<Blank viewBox='0 0 50 45' aria-label="Bitbucket" {...props}>
<path d='M1.62268177,0.000133495743 C1.14941987,-0.0059704193 0.697680983,0.197511072 0.388643836,0.555994162 C0.0796066892,0.914477253 -0.0550949222,1.39126674 0.0206726408,1.85846409 L6.8212014,43.1422394 C6.99610083,44.1850635 7.89452063,44.9517601 8.95187354,44.9605197 L41.5767895,44.9605197 C42.3704132,44.9707342 43.051874,44.3983071 43.1787986,43.6148321 L49.9793274,1.86647413 C50.0550949,1.39927679 49.9203933,0.922487298 49.6113562,0.564004208 C49.302319,0.205521117 48.8505801,0.00203962635 48.3773182,0.00814354139 L1.62268177,0.000133495743 Z M30.258595,29.8375535 L19.8455356,29.8375535 L17.0259996,15.1070796 L32.7817593,15.1070796 L30.258595,29.8375535 Z' />
</Blank>
)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import BitbucketIcon from './../../components/BitbucketIcon'
import WeiboIcon from './../../components/WeiboIcon'

function formatUrlObject (obj, t) {
function formatUrlObject(obj, t) {
// Default to external website
const formattedObject = {
IconComponent: GlobeIcon,
Expand Down
Empty file.

0 comments on commit d601d3f

Please sign in to comment.