|
| 1 | +/* |
| 2 | + * The MIT License (MIT) |
| 3 | + * |
| 4 | + * Copyright (c) 2015 - present Instructure, Inc. |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all |
| 14 | + * copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | + * SOFTWARE. |
| 23 | + */ |
| 24 | +import React from 'react' |
| 25 | +import { SubNav } from '../../packages/ui-top-nav-bar' |
| 26 | +import '../support/component' |
| 27 | +import 'cypress-real-events' |
| 28 | + |
| 29 | + |
| 30 | +describe('<SubNav/>', () => { |
| 31 | + it('should call onClick and redirect when item is clicked', async () => { |
| 32 | + const onClickSpy = cy.spy().as('onClickSpy') |
| 33 | + |
| 34 | + cy.mount( |
| 35 | + <SubNav |
| 36 | + menuItems={[ |
| 37 | + { title: 'Home', href: '#', selected: true }, |
| 38 | + { title: 'Announcements', href: '#', selected: false }, |
| 39 | + { title: 'Assignments', href: '#-test', selected: false, onClick: onClickSpy } |
| 40 | + ]} |
| 41 | + /> |
| 42 | + ) |
| 43 | + cy.contains('Assignments').realClick() |
| 44 | + |
| 45 | + cy.get('@onClickSpy').should('have.been.called') |
| 46 | + cy.url().should('contain', '#-test') |
| 47 | + }) |
| 48 | + |
| 49 | + it('should be able to select with keyboard', async () => { |
| 50 | + const onClickSpy = cy.spy().as('onClickSpy') |
| 51 | + cy.mount( |
| 52 | + <SubNav |
| 53 | + menuItems={[ |
| 54 | + { title: 'Home', href: '#'}, |
| 55 | + { title: 'Announcements', href: '#-test2', selected: false, onClick: onClickSpy }, |
| 56 | + { title: 'Assignments', href: '#-test', selected: true } |
| 57 | + ]} |
| 58 | + /> |
| 59 | + ) |
| 60 | + cy.contains('Home').focus() |
| 61 | + cy.realPress(['Tab']).wait(100) |
| 62 | + cy.realPress(['Enter']).wait(100) |
| 63 | + |
| 64 | + cy.get('@onClickSpy').should('have.been.called') |
| 65 | + cy.url().should('contain', '#-test2') |
| 66 | + }) |
| 67 | +}) |
0 commit comments