-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(UsaNavPrimaryItem): implement
UsaNavPrimaryItem
component
ISSUES CLOSED: #93
- Loading branch information
1 parent
d146173
commit db5ca2f
Showing
5 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
src/components/UsaNavPrimaryItem/UsaNavPrimaryItem.stories.js
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,63 @@ | ||
import UsaNavPrimaryItem from './UsaNavPrimaryItem.vue' | ||
|
||
const defaultProps = { | ||
href: UsaNavPrimaryItem.props.href.default, | ||
to: UsaNavPrimaryItem.props.to.default, | ||
routerComponentName: UsaNavPrimaryItem.props.routerComponentName.default, | ||
} | ||
|
||
export default { | ||
component: UsaNavPrimaryItem, | ||
title: 'Components/UsaNavPrimaryItem', | ||
argTypes: { | ||
href: { | ||
control: { type: 'text' }, | ||
}, | ||
to: { | ||
control: { type: 'text' }, | ||
}, | ||
routerComponentName: { | ||
control: { type: 'text' }, | ||
}, | ||
defaultSlot: { | ||
control: { type: 'text' }, | ||
}, | ||
}, | ||
args: { | ||
href: defaultProps.href, | ||
to: defaultProps.to, | ||
routerComponentName: defaultProps.routerComponentName, | ||
defaultSlot: 'Test nav link', | ||
}, | ||
decorators: [ | ||
() => ({ | ||
template: '<story />', | ||
provide: { | ||
closeAllDropdowns: e => { | ||
e.preventDefault() | ||
}, | ||
}, | ||
}), | ||
], | ||
} | ||
|
||
const DefaultTemplate = (args, { argTypes }) => ({ | ||
components: { UsaNavPrimaryItem }, | ||
props: Object.keys(argTypes), | ||
setup() { | ||
return { ...args } | ||
}, | ||
template: `<UsaNavPrimaryItem | ||
v-bind="$attrs" | ||
:href="href" | ||
:to="to" | ||
:router-component-name="routerComponentName" | ||
>${args.defaultSlot}</UsaNavPrimaryItem>`, | ||
}) | ||
|
||
export const DefaultNavPrimaryItem = DefaultTemplate.bind({}) | ||
DefaultNavPrimaryItem.args = { | ||
...defaultProps, | ||
href: '/test-page', | ||
} | ||
DefaultNavPrimaryItem.storyName = 'Default' |
63 changes: 63 additions & 0 deletions
63
src/components/UsaNavPrimaryItem/UsaNavPrimaryItem.test.js
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,63 @@ | ||
import '@module/uswds/dist/css/uswds.min.css' | ||
import { mount } from '@cypress/vue' | ||
import UsaNavPrimaryItem from './UsaNavPrimaryItem.vue' | ||
|
||
describe('UsaNavPrimaryItem', () => { | ||
it('renders the component', () => { | ||
mount(UsaNavPrimaryItem, { | ||
props: { | ||
href: '#', | ||
}, | ||
attrs: { | ||
'data-test': 'test-attr', | ||
}, | ||
slots: { | ||
default: () => 'Test nav link', | ||
}, | ||
global: { | ||
provide: { | ||
closeAllDropdowns: cy.stub().as('closeAllDropdowns'), | ||
}, | ||
}, | ||
}) | ||
|
||
cy.get('li.usa-nav__primary-item') | ||
.as('item') | ||
.should('not.have.attr', 'data-test') | ||
|
||
cy.get('@item') | ||
.find('a') | ||
.as('link') | ||
.should('have.class', 'usa-nav__link') | ||
.and('have.attr', 'data-test') | ||
.and('contain', 'test-attr') | ||
|
||
cy.get('@link').should('have.attr', 'href').and('contain', '#') | ||
cy.get('@link').find('span').should('contain', 'Test nav link') | ||
|
||
cy.get('@closeAllDropdowns').should('not.be.called') | ||
|
||
cy.get('@link').click() | ||
|
||
cy.get('@closeAllDropdowns').should('be.called') | ||
}) | ||
|
||
it('renders as vue router link', () => { | ||
mount(UsaNavPrimaryItem, { | ||
props: { | ||
to: '/test', | ||
'router-component-name': 'router-link', | ||
}, | ||
slots: { | ||
default: () => 'Test nav link', | ||
}, | ||
global: { | ||
provide: { | ||
closeAllDropdowns: () => {}, | ||
}, | ||
}, | ||
}) | ||
|
||
cy.get('router-link').should('have.attr', 'to').and('contain', '/test') | ||
}) | ||
}) |
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,31 @@ | ||
<script> | ||
export default { | ||
inheritAttrs: false, | ||
} | ||
</script> | ||
|
||
<script setup> | ||
import { inject } from 'vue' | ||
import BaseLink from '@/components/BaseLink' | ||
defineProps({ | ||
...BaseLink.props, | ||
}) | ||
const closeAllDropdowns = inject('closeAllDropdowns') | ||
</script> | ||
|
||
<template> | ||
<li class="usa-nav__primary-item"> | ||
<BaseLink | ||
v-bind="$attrs" | ||
class="usa-nav__link" | ||
:href="href" | ||
:to="to" | ||
:router-component-name="routerComponentName" | ||
@click="closeAllDropdowns" | ||
> | ||
<span><slot></slot></span> | ||
</BaseLink> | ||
</li> | ||
</template> |
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,4 @@ | ||
import UsaNavPrimaryItem from './UsaNavPrimaryItem.vue' | ||
|
||
export { UsaNavPrimaryItem } | ||
export default UsaNavPrimaryItem |
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