-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6596 from ampproject/feature/6071-onboarding-site…
…-review Introduce Site Review to the Onboarding Wizard
- Loading branch information
Showing
66 changed files
with
1,655 additions
and
1,002 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
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
4 changes: 2 additions & 2 deletions
4
assets/src/components/amp-setting-toggle/test/__snapshots__/index.js.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
assets/src/components/dev-tools-toggle/test/__snapshots__/index.js.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import PropTypes from 'prop-types'; | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
import { Selectable } from '../selectable'; | ||
|
||
/** | ||
* Nav menu. | ||
* | ||
* @param {Object} props Component props. | ||
* @param {Array} props.links List of links. | ||
* @param {Function} props.onClick Click handler that receives the original event and a clicked link object. | ||
*/ | ||
export function NavMenu( { links = [], onClick } ) { | ||
return ( | ||
<Selectable | ||
ElementName="nav" | ||
className="nav-menu" | ||
> | ||
<ul className="nav-menu__list"> | ||
{ links.map( ( link ) => ( | ||
<li key={ link.url } className="nav-menu__item"> | ||
<a | ||
className={ classnames( 'nav-menu__link', { | ||
'nav-menu__link--active': link.isActive, | ||
} ) } | ||
href={ link.url } | ||
onClick={ ( event ) => onClick( event, link ) } | ||
> | ||
{ link.label } | ||
</a> | ||
</li> | ||
) ) } | ||
</ul> | ||
</Selectable> | ||
); | ||
} | ||
|
||
NavMenu.propTypes = { | ||
links: PropTypes.arrayOf( | ||
PropTypes.shape( { | ||
url: PropTypes.string, | ||
label: PropTypes.string, | ||
isActive: PropTypes.bool, | ||
} ), | ||
), | ||
onClick: PropTypes.func, | ||
}; |
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,64 @@ | ||
.nav-menu__item { | ||
margin: 0; | ||
|
||
& + & { | ||
border-top: 1px solid var(--amp-settings-color-border); | ||
} | ||
} | ||
|
||
.amp .nav-menu__link { | ||
align-items: center; | ||
color: var(--amp-settings-color-muted); | ||
display: flex; | ||
flex-flow: row nowrap; | ||
font-size: 14px; | ||
justify-content: space-between; | ||
padding: 0.75rem 1rem; | ||
text-decoration: none; | ||
transition: background-color 120ms ease; | ||
|
||
&.nav-menu__link--active, | ||
&:hover { | ||
background-color: var(--very-light-gray); | ||
color: var(--amp-settings-color-muted); | ||
} | ||
|
||
&:focus { | ||
box-shadow: none; | ||
} | ||
|
||
&::after { | ||
border: 2px solid; | ||
border-bottom: none; | ||
border-left: none; | ||
content: ""; | ||
display: block; | ||
flex: 0 0 auto; | ||
height: 8px; | ||
margin-left: 1rem; | ||
transform: rotateZ(45deg); | ||
width: 8px; | ||
} | ||
} | ||
|
||
// Nav menu as a selectable component. | ||
.nav-menu.selectable { | ||
padding: 0; | ||
|
||
.nav-menu__list { | ||
margin: 0; | ||
padding: 0 1rem; | ||
} | ||
|
||
.nav-menu__link { | ||
margin: 0 -1rem; | ||
} | ||
|
||
.nav-menu__item:first-child .nav-menu__link { | ||
border-radius: 8px 8px 0 0; | ||
} | ||
|
||
.nav-menu__item:last-child .nav-menu__link { | ||
border-radius: 0 0 8px 8px; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
assets/src/components/nav-menu/test/__snapshots__/nav-menu.js.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import { act } from 'react-dom/test-utils'; | ||
import { create } from 'react-test-renderer'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { render } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { NavMenu } from '../index'; | ||
|
||
let container; | ||
|
||
const links = [ | ||
{ | ||
url: 'https://example.com/foo', | ||
label: 'Foo', | ||
isActive: false, | ||
}, | ||
{ | ||
url: 'https://example.com/bar', | ||
label: 'Bar', | ||
isActive: true, | ||
}, | ||
]; | ||
|
||
describe( 'NavMenu', () => { | ||
beforeEach( () => { | ||
container = document.createElement( 'div' ); | ||
document.body.appendChild( container ); | ||
} ); | ||
|
||
afterEach( () => { | ||
document.body.removeChild( container ); | ||
container = null; | ||
} ); | ||
|
||
it( 'matches the snapshot', () => { | ||
const wrapper = create( <NavMenu links={ links } /> ); | ||
|
||
expect( wrapper.toJSON() ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'renders a nav menu with a list of links', () => { | ||
act( () => { | ||
render( | ||
<NavMenu links={ links } />, | ||
container, | ||
); | ||
} ); | ||
|
||
expect( container.querySelector( 'nav' ) ).not.toBeNull(); | ||
expect( container.querySelector( 'ul' ) ).not.toBeNull(); | ||
expect( container.querySelectorAll( 'li' ) ).toHaveLength( 2 ); | ||
} ); | ||
|
||
it( 'contains correct links', () => { | ||
act( () => { | ||
render( | ||
<NavMenu links={ links } />, | ||
container, | ||
); | ||
} ); | ||
|
||
expect( container.querySelector( 'nav' ).textContent ).toBe( 'FooBar' ); | ||
expect( container.querySelectorAll( 'a' ) ).toHaveLength( 2 ); | ||
expect( container.querySelectorAll( 'a[href="https://example.com/foo"]' ) ).toHaveLength( 1 ); | ||
expect( container.querySelectorAll( 'a[href="https://example.com/bar"]' ) ).toHaveLength( 1 ); | ||
expect( container.querySelectorAll( 'a[class*="--active"]' ) ).toHaveLength( 1 ); | ||
expect( container.querySelector( 'a[class*="--active"]' ).getAttribute( 'href' ) ).toBe( 'https://example.com/bar' ); | ||
} ); | ||
|
||
it( 'calls the handler function on click', () => { | ||
const handler = jest.fn(); | ||
|
||
act( () => { | ||
render( | ||
<NavMenu links={ links } onClick={ handler } />, | ||
container, | ||
); | ||
} ); | ||
|
||
act( | ||
() => { | ||
container.querySelector( 'a' ).click(); | ||
}, | ||
); | ||
|
||
expect( handler ).toHaveBeenCalledTimes( 1 ); | ||
|
||
const [ event, link ] = handler.mock.calls[ 0 ]; | ||
expect( event.type ).toBe( 'click' ); | ||
expect( link ).toBe( links[ 0 ] ); | ||
} ); | ||
} ); |
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.