-
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,945 additions
and
2,106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const finalRules = { | ||
/* airbnb config overrides */ | ||
'react/jsx-filename-extension': [0], | ||
'import/no-extraneous-dependencies': [0], | ||
'import/no-named-as-default': [0], // allow component to be the same as the default export | ||
'class-methods-use-this': [0], | ||
'no-throw-literal': [0], | ||
'comma-dangle': [ | ||
'error', | ||
{ | ||
arrays: 'always-multiline', | ||
objects: 'always-multiline', | ||
imports: 'always-multiline', | ||
exports: 'always-multiline', | ||
functions: 'never', | ||
}, | ||
], | ||
'arrow-parens': [2, 'as-needed', { requireForBlockBody: true }], | ||
|
||
// Allow prop spreading for React components, but not for html elements | ||
'react/jsx-props-no-spreading': [ | ||
2, | ||
{ | ||
custom: 'ignore', | ||
explicitSpread: 'ignore', | ||
}, | ||
], | ||
'react/jsx-no-bind': [ | ||
2, | ||
{ | ||
allowArrowFunctions: true, | ||
allowFunctions: true, | ||
}, | ||
], | ||
'react/no-unstable-nested-components': [ | ||
2, | ||
{ | ||
allowAsProps: true, | ||
}, | ||
], | ||
'react/require-default-props': [0], | ||
'default-param-last': [0], | ||
'function-call-argument-newline': [0], | ||
'function-paren-newline': [0], | ||
'no-promise-executor-return': [0], | ||
'react/function-component-definition': [0], | ||
'sonarjs/no-duplicate-string': [0], | ||
'sonarjs/no-identical-functions': [0], | ||
}; | ||
|
||
const overrides = [ | ||
{ | ||
files: ['frontend/**/*'], | ||
env: { | ||
browser: true, | ||
node: true, | ||
}, | ||
}, | ||
{ | ||
files: ['**/*.test.js', '**/*.test.jsx'], | ||
env: { | ||
'jest/globals': true, | ||
}, | ||
plugins: ['jest'], | ||
extends: ['airbnb', 'plugin:sonarjs/recommended'], | ||
rules: { ...finalRules, 'react/jsx-props-no-spreading': 0 }, | ||
}, | ||
]; | ||
|
||
module.exports = { | ||
overrides, | ||
plugins: ['import'], | ||
extends: ['airbnb', 'plugin:sonarjs/recommended', 'plugin:no-unsanitized/DOM'], | ||
rules: finalRules, | ||
parserOptions: { | ||
ecmaVersion: 2021, | ||
}, | ||
settings: { | ||
'import/resolver': { | ||
webpack: {}, | ||
}, | ||
}, | ||
}; |
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
30 changes: 30 additions & 0 deletions
30
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,30 @@ | ||
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
107 changes: 107 additions & 0 deletions
107
frontend/pages/sites/$siteId/published/BranchViewLink.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,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
Oops, something went wrong.