-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
3,689 additions
and
1,968 deletions.
There are no files selected for viewing
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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
28 changes: 28 additions & 0 deletions
28
frontend/pages/sites/$siteId/builds/CreateBuildLink.test.jsx
This file contains 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,28 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { spy } from 'sinon'; | ||
import CreateBuildLink from './CreateBuildLink'; | ||
|
||
describe('<CreateBuildLink />', () => { | ||
const props = { | ||
handlerParams: { dish: 'tacos', cuisine: 'mexican' }, | ||
handleClick: spy(), | ||
children: 'hey there', | ||
}; | ||
|
||
test('it renders', () => { | ||
render(<CreateBuildLink {...props} />); | ||
expect(screen.getByRole('button')).toBeInTheDocument(); | ||
}); | ||
|
||
test('it calls the .handleClick function, passing handler params', () => { | ||
render(<CreateBuildLink {...props} />); | ||
const handler = props.handleClick; | ||
const params = props.handlerParams; | ||
|
||
fireEvent.click(screen.getByRole('button')); | ||
expect(handler.calledOnce).toBeTruthy(); | ||
expect(handler.calledWith(...Object.keys(params).map(key => params[key]))).toBeTruthy(); | ||
}); | ||
}); |
This file contains 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 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,107 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import { BranchViewLink } from './BranchViewLink'; | ||
|
||
const proxyDomain = process.env.PROXY_DOMAIN; | ||
|
||
describe('<BranchViewLink/>', () => { | ||
const awsBucketName = 'test-bucket'; | ||
const siteDomain = 'prod-url.com'; | ||
const demoDomain = 'demo-url.com'; | ||
const proxyOrigin = `https://${awsBucketName}.${proxyDomain}`; | ||
const unprovisionedS3Key = '/this/is/unprovisoned/branch'; | ||
|
||
const defaultBranch = 'default-branch'; | ||
const demoBranch = 'demo-branch'; | ||
const VIEW_BUILD = 'View site preview'; | ||
|
||
const testSite = { | ||
defaultBranch, | ||
demoBranch, | ||
domain: `https://${siteDomain}`, | ||
demoDomain: `https://${demoDomain}`, | ||
owner: 'test-owner', | ||
repository: 'test-repo', | ||
awsBucketName, | ||
s3ServiceName: 'federalist-production-s3', | ||
domains: [ | ||
{ | ||
names: siteDomain, | ||
siteBranchConfigId: 123, | ||
state: 'provisioned', | ||
}, | ||
{ | ||
names: demoDomain, | ||
siteBranchConfigId: 256, | ||
state: 'provisioned', | ||
}, | ||
{ | ||
names: 'unprovisioned.gov', | ||
siteBranchConfigId: 411, | ||
state: 'pending', | ||
}, | ||
], | ||
siteBranchConfigs: [ | ||
{ | ||
branch: defaultBranch, | ||
id: 123, | ||
}, | ||
{ | ||
branch: demoBranch, | ||
id: 256, | ||
}, | ||
{ | ||
s3Key: unprovisionedS3Key, | ||
branch: 'unprovisioned-branch', | ||
id: 411, | ||
}, | ||
], | ||
}; | ||
|
||
let props; | ||
|
||
beforeEach(() => { | ||
props = { | ||
branchName: 'branch-name', | ||
site: testSite, | ||
}; | ||
}); | ||
|
||
it("renders a link to the default branch's site", () => { | ||
props.branchName = 'default-branch'; | ||
render(<BranchViewLink {...props} />); | ||
const anchor = screen.getByRole('link'); | ||
expect(anchor).toHaveAttribute('href', `https://${siteDomain}`); | ||
expect(anchor).toHaveTextContent(VIEW_BUILD); | ||
}); | ||
|
||
it("renders a link to the demo branch's site", () => { | ||
props.branchName = 'demo-branch'; | ||
render(<BranchViewLink {...props} />); | ||
const anchor = screen.getByRole('link'); | ||
expect(anchor).toHaveAttribute('href', `https://${demoDomain}`); | ||
expect(anchor).toHaveTextContent(VIEW_BUILD); | ||
}); | ||
|
||
it('renders the preview link to site branch when the domain is not provisioned', () => { | ||
props.branchName = 'unprovisioned-branch'; | ||
render(<BranchViewLink {...props} />); | ||
const anchor = screen.getByRole('link'); | ||
expect(anchor).toHaveAttribute('href', `${proxyOrigin}${unprovisionedS3Key}`); | ||
expect(anchor).toHaveTextContent(VIEW_BUILD); | ||
}); | ||
|
||
it('renders a preview link to the other branches', () => { | ||
const branchName = 'some-other-branch'; | ||
const updatedProps = { ...props, branchName }; | ||
render(<BranchViewLink {...updatedProps} />); | ||
const anchor = screen.getByRole('link'); | ||
expect(anchor).toHaveAttribute( | ||
'href', | ||
`${proxyOrigin}/preview/${testSite.owner}/${testSite.repository}/${branchName}` | ||
); | ||
expect(anchor).toHaveTextContent(VIEW_BUILD); | ||
}); | ||
}); |
This file contains 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 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,19 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import ExpandableArea from './ExpandableArea'; | ||
|
||
describe('<ExpandableArea/>', () => { | ||
it('renders', () => { | ||
const title = 'Test Title'; | ||
render( | ||
<ExpandableArea title={title}> | ||
<p>hello</p> | ||
</ExpandableArea> | ||
); | ||
|
||
const button = screen.getByRole('button'); | ||
expect(button).toHaveTextContent(title); | ||
}); | ||
}); |
This file contains 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 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,62 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import GitHubLink from './GitHubLink'; | ||
|
||
describe('<GitHubLink/>', () => { | ||
it('renders', () => { | ||
const props = { owner: 'owner', repository: 'a-repo', text: 'link text' }; | ||
render(<GitHubLink {...props} />); | ||
|
||
const anchor = screen.getByRole('link'); | ||
expect(anchor).toHaveClass('repo-link'); | ||
|
||
expect(anchor).toHaveAttribute('href', 'https://github.com/owner/a-repo'); | ||
expect(anchor).toHaveAttribute('title', 'View repository on GitHub'); | ||
expect(anchor).toHaveTextContent('link text'); | ||
|
||
// TODO: actually render svg with https://react-svgr.com/docs/node-api/ in tests | ||
// const icon = screen.getByTitle('icon-github'); | ||
// expect(icon).toBeInTheDocument(); | ||
}); | ||
|
||
it('can link to a branch', () => { | ||
const props = { | ||
text: 'link text', owner: 'pumpkin-pie', repository: 'candle', branch: 'the-branch', | ||
}; | ||
|
||
render(<GitHubLink {...props} />); | ||
|
||
const anchor = screen.getByRole('link'); | ||
expect(anchor).toHaveClass('repo-link'); | ||
expect(anchor).toHaveAttribute('href', 'https://github.com/pumpkin-pie/candle/tree/the-branch'); | ||
expect(anchor).toHaveAttribute('title', 'View branch on GitHub'); | ||
}); | ||
|
||
it('encodes the branch name', () => { | ||
const props = { | ||
text: 'boop', owner: 'spam', repository: 'potato', branch: '#-hash-#', | ||
}; | ||
render(<GitHubLink {...props} />); | ||
|
||
const anchor = screen.getByRole('link'); | ||
expect(anchor).toHaveClass('repo-link'); | ||
expect(anchor).toHaveAttribute('href', 'https://github.com/spam/potato/tree/%23-hash-%23'); | ||
}); | ||
|
||
it('links to a specific commit', () => { | ||
const props = { | ||
text: 'boop', owner: 'zookeeni', repository: 'veggies', sha: '123A', | ||
}; | ||
|
||
render(<GitHubLink {...props} />); | ||
|
||
const anchor = screen.getByRole('link'); | ||
expect(anchor).toHaveClass('repo-link'); | ||
|
||
const commitUrl = `https://github.com/${props.owner}/${props.repository}/commit/${props.sha}`; | ||
|
||
expect(anchor).toHaveAttribute('href', commitUrl); | ||
}); | ||
}); |
This file contains 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,12 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import LoadingIndicator from './LoadingIndicator'; | ||
|
||
describe('<LoadingIndicator/>', () => { | ||
it('renders', () => { | ||
render(<LoadingIndicator />); | ||
screen.getByText('Loading...'); | ||
}); | ||
}); |
This file contains 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
Oops, something went wrong.