Skip to content

Commit

Permalink
test(ui-metric): migrate old Metric tests
Browse files Browse the repository at this point in the history
Closes: INSTUI-4150
  • Loading branch information
ToMESSKa committed Aug 27, 2024
1 parent c2d239f commit 3e74a02
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 195 deletions.
59 changes: 57 additions & 2 deletions package-lock.json

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

7 changes: 5 additions & 2 deletions packages/ui-metric/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@
"prop-types": "^15.8.1"
},
"devDependencies": {
"@instructure/ui-axe-check": "10.2.0",
"@instructure/ui-babel-preset": "10.2.0",
"@instructure/ui-color-utils": "10.2.0",
"@instructure/ui-test-locator": "10.2.0",
"@instructure/ui-test-utils": "10.2.0",
"@instructure/ui-themes": "10.2.0"
"@instructure/ui-themes": "10.2.0",
"@testing-library/jest-dom": "^6.4.6",
"@testing-library/react": "^15.0.7",
"vitest": "^2.0.2"
},
"peerDependencies": {
"react": ">=16.8 <=18"
Expand Down
29 changes: 0 additions & 29 deletions packages/ui-metric/src/Metric/MetricLocator.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,65 +23,74 @@
*/

import React from 'react'
import { expect, mount } from '@instructure/ui-test-utils'
import { render, screen } from '@testing-library/react'
import '@testing-library/jest-dom'
import { vi } from 'vitest'

import { Metric } from '../index'
import { MetricLocator } from '../MetricLocator'

describe('<Metric />', async () => {
describe('<Metric />', () => {
it('should render the label', async () => {
await mount(<Metric renderLabel="Grade" renderValue="80%" />)

const metric = await MetricLocator.find()
const { container } = render(
<Metric renderLabel="Grade" renderValue="80%" />
)

expect(await metric.findWithText('Grade')).to.exist()
expect(container).toHaveTextContent('Grade')
})

it('should render the value', async () => {
await mount(<Metric renderLabel="Grade" renderValue="80%" />)

const metric = await MetricLocator.find()
const { container } = render(
<Metric renderLabel="Grade" renderValue="80%" />
)

expect(await metric.findWithText('80%')).to.exist()
expect(container).toHaveTextContent('80%')
})

it('passes props through to Metric element', async () => {
await mount(
<Metric data-automation="foo" renderLabel="Grade" renderValue="80%" />
render(
<Metric
data-testid="metric"
data-automation="foo"
renderLabel="Grade"
renderValue="80%"
/>
)
const metric = screen.getByTestId('metric')

expect(await MetricLocator.find()).to.have.attribute(
'data-automation',
'foo'
)
expect(metric).toHaveAttribute('data-automation', 'foo')
})

it('should not have role="gridcell" for the value', async () => {
await mount(<Metric renderLabel="Grade" renderValue="80%" />)

const metric = await MetricLocator.find()
const value = await metric.findWithText('80%')
render(<Metric renderLabel="Grade" renderValue="80%" />)
const value = screen.getByText('80%')

expect(
await value.find('[role="gridcell"]', { expectEmpty: true })
).to.not.exist()
expect(value).not.toHaveAttribute('role', 'gridcell')
})

it('should not have role=rowheader for the label', async () => {
await mount(<Metric renderLabel="Grade" renderValue="80%" />)
render(<Metric renderLabel="Grade" renderValue="80%" />)
const label = screen.getByText('Grade')

const metric = await MetricLocator.find()
const label = await metric.findWithText('Grade')
expect(label).not.toHaveAttribute('role', 'rowheader')
})

it('should allow ReactNodes as labels and values', async () => {
const { container } = render(<Metric renderLabel={<div>hello</div>} />)

expect(container).toHaveTextContent('hello')
})

it('should allow methods as labels', async () => {
const renderLabel = vi.fn()
render(<Metric renderLabel={renderLabel} />)

expect(
await label.find('[role="rowheader"]', { expectEmpty: true })
).to.not.exist()
expect(renderLabel).toHaveBeenCalled()
})

it('should allow methods and ReactNodes as labels and values', async () => {
await mount(<Metric renderLabel={<div>hello</div>} />)
const metric = await MetricLocator.find()
const label = await metric.findWithText('hello')
expect(label).to.exist()
it('should allow methods as values', async () => {
const renderValue = vi.fn()
render(<Metric renderValue={renderValue} />)

expect(renderValue).toHaveBeenCalled()
})
})
27 changes: 0 additions & 27 deletions packages/ui-metric/src/Metric/locator.ts

This file was deleted.

40 changes: 0 additions & 40 deletions packages/ui-metric/src/MetricGroup/MetricGroupLocator.ts

This file was deleted.

Loading

0 comments on commit 3e74a02

Please sign in to comment.