Skip to content

Commit

Permalink
test(ui-breadcrumb): migrate old Breadcrumb tests
Browse files Browse the repository at this point in the history
Closes: INSTUI-3865
  • Loading branch information
git-nandor committed Oct 13, 2023
1 parent 5c79ae3 commit 12107d7
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 286 deletions.
14 changes: 9 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions packages/ui-breadcrumb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
"license": "MIT",
"devDependencies": {
"@instructure/ui-babel-preset": "8.46.1",
"@instructure/ui-test-locator": "8.46.1",
"@instructure/ui-test-utils": "8.46.1",
"@instructure/ui-themes": "8.46.1"
"@instructure/ui-themes": "8.46.1",
"@instructure/ui-axe-check": "8.46.1",
"@instructure/ui-scripts": "^8.46.1",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^14.0.0"
},
"dependencies": {
"@babel/runtime": "^7.22.15",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 - present Instructure, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import React from 'react'
import { fireEvent, render, screen } from '@testing-library/react'
import '@testing-library/jest-dom/extend-expect'

import { runAxeCheck } from '@instructure/ui-axe-check'
import { BreadcrumbLink } from '../index'

const TEST_TEXT_01 = 'Account'
const TEST_LINK = 'http://instructure-test.com'
const TEST_TO = '/example'

const originalResizeObserver = global.ResizeObserver

describe('<BreadcrumbLink />', () => {
beforeAll(() => {
// Mock for ResizeObserver browser API
global.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn()
}))
})

it('should render an anchor tag when given a href prop', () => {
render(<BreadcrumbLink href={TEST_LINK}>{TEST_TEXT_01}</BreadcrumbLink>)
const anchor = screen.getByRole('link')

expect(anchor).toHaveAttribute('href', TEST_LINK)
})

it('should render as a button and respond to onClick event', () => {
const onClick = jest.fn()

render(<BreadcrumbLink onClick={onClick}>{TEST_TEXT_01}</BreadcrumbLink>)
const button = screen.getByRole('button')

fireEvent.click(button)

expect(onClick).toHaveBeenCalledTimes(1)
})

it('should allow to prop to pass through', () => {
const { container } = render(
<BreadcrumbLink to={TEST_TO}>{TEST_TEXT_01}</BreadcrumbLink>
)
const link = container.querySelector('a')

expect(link).toBeInTheDocument()
expect(link).toHaveAttribute('to', TEST_TO)
})

it('should not render a link when not given an href prop', () => {
const { container } = render(
<BreadcrumbLink>{TEST_TEXT_01}</BreadcrumbLink>
)
const elementWithHref = container.querySelector('[href]')
const anchor = container.querySelector('a')
const span = container.querySelector('span')

expect(elementWithHref).toBeNull()
expect(anchor).toBeNull()
expect(span).toBeInTheDocument()
expect(span).toHaveTextContent(TEST_TEXT_01)
})

it('should not render a button when not given an onClick prop', () => {
const { container } = render(
<BreadcrumbLink>{TEST_TEXT_01}</BreadcrumbLink>
)
const button = container.querySelector('button')
const span = container.querySelector('span')

expect(button).toBeNull()
expect(span).toBeInTheDocument()
expect(span).toHaveTextContent(TEST_TEXT_01)
})

it('should meet a11y standards as a link', async () => {
const { container } = render(
<BreadcrumbLink href={TEST_LINK}>{TEST_TEXT_01}</BreadcrumbLink>
)
const axeCheck = await runAxeCheck(container)

expect(axeCheck).toBe(true)
})

it('should meet a11y standards as a span', async () => {
const { container } = render(
<BreadcrumbLink>{TEST_TEXT_01}</BreadcrumbLink>
)
const axeCheck = await runAxeCheck(container)

expect(axeCheck).toBe(true)
})

afterAll(() => {
global.ResizeObserver = originalResizeObserver
})
})

This file was deleted.

27 changes: 0 additions & 27 deletions packages/ui-breadcrumb/src/Breadcrumb/BreadcrumbLink/locator.ts

This file was deleted.

39 changes: 0 additions & 39 deletions packages/ui-breadcrumb/src/Breadcrumb/BreadcrumbLocator.ts

This file was deleted.

Loading

0 comments on commit 12107d7

Please sign in to comment.