Skip to content

Commit f096f3a

Browse files
committed
More changes from the checklist
1 parent 6084fa0 commit f096f3a

File tree

10 files changed

+205
-311
lines changed

10 files changed

+205
-311
lines changed

docs/content/Button.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
componentId: button_v2
3-
title: Button v2
2+
componentId: button
3+
title: Button
44
status: Alpha
55
source: https://github.com/primer/react/tree/main/src/Button2
66
storybook: '/react/storybook?path=/story/composite-components-button2'

docs/content/drafts/IconButton.mdx renamed to docs/content/IconButton.mdx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ storybook: '/react/storybook?path=/story/composite-components-button2'
66
description: An accessible button component with no text and only icon.
77
---
88

9-
import {Props} from '../../src/props'
10-
import {ComponentChecklist} from '../../src/component-checklist'
11-
129
## Usage
1310

1411
### Installation

docs/content/drafts/LinkButton.mdx renamed to docs/content/LinkButton.mdx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ storybook: '/react/storybook?path=/story/composite-components-button2'
66
description: It is a combination of a button and link. Use this to make your link look like a button.
77
---
88

9-
import {Props} from '../../src/props'
10-
import {ComponentChecklist} from '../../src/component-checklist'
11-
import {ArrowRightIcon} from '@primer/octicons-react'
12-
139
## Usage
1410

1511
### Installation

docs/content/deprecated/Buttons.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
componentId: button
33
title: Button
4-
status: Alpha
4+
status: deprecated
55
source: https://github.com/primer/react/blob/main/src/Button
66
storybook: '/react/storybook?path=/story/composite-components-button--default-button'
77
---

docs/content/migration-guide/Button.mdx

Lines changed: 0 additions & 99 deletions
This file was deleted.

docs/src/@primer/gatsby-theme-doctocat/nav.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
url: /BranchName
5454
- title: Breadcrumbs
5555
url: /Breadcrumbs
56-
- title: Buttons
57-
url: /Buttons
56+
- title: Button
57+
url: /Button
5858
- title: Checkbox
5959
url: /Checkbox
6060
- title: CheckboxGroup
@@ -79,12 +79,16 @@
7979
url: /Header
8080
- title: Heading
8181
url: /Heading
82+
- title: IconButton
83+
url: /IconButton
8284
- title: Label
8385
url: /Label
8486
- title: LabelGroup
8587
url: /LabelGroup
8688
- title: Link
8789
url: /Link
90+
- title: LinkButton
91+
url: /LinkButton
8892
- title: Overlay
8993
url: /Overlay
9094
- title: Pagehead
@@ -141,12 +145,6 @@
141145
url: /UnderlineNav
142146
- title: Drafts
143147
children:
144-
- title: Button v2
145-
url: /drafts/Button2
146-
- title: LinkButton
147-
url: /drafts/LinkButton
148-
- title: IconButton
149-
url: /drafts/IconButton
150148
- title: Deprecated
151149
children:
152150
- title: ActionList
@@ -155,6 +153,8 @@
155153
url: /deprecated/ActionMenu
156154
- title: BorderBox
157155
url: /deprecated/BorderBox
156+
- title: Buttons
157+
url: /deprecated/Buttons
158158
- title: Dialog
159159
url: /deprecated/Dialog
160160
- title: Dropdown

src/__tests__/Button.test.tsx

Lines changed: 63 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,98 @@
11
import React from 'react'
2-
import {
3-
Button,
4-
ButtonPrimary,
5-
ButtonClose,
6-
ButtonDanger,
7-
ButtonOutline,
8-
ButtonInvisible,
9-
ButtonTableList
10-
} from '../deprecated'
11-
import {ButtonGroup} from '../'
12-
import {render, behavesAsComponent, checkExports} from '../utils/testing'
13-
import {render as HTMLRender, cleanup} from '@testing-library/react'
2+
import {IconButton, Button} from '../Button'
3+
import {behavesAsComponent} from '../utils/testing'
4+
import {render, cleanup, fireEvent} from '@testing-library/react'
145
import {axe, toHaveNoViolations} from 'jest-axe'
156
import 'babel-polyfill'
7+
import {SearchIcon} from '@primer/octicons-react'
168
expect.extend(toHaveNoViolations)
179

18-
// eslint-disable-next-line @typescript-eslint/no-empty-function
19-
function noop() {}
20-
2110
describe('Button', () => {
22-
behavesAsComponent({Component: Button})
23-
24-
checkExports('deprecated/Button', {
25-
default: Button,
26-
ButtonPrimary,
27-
ButtonDanger,
28-
ButtonOutline,
29-
ButtonInvisible,
30-
ButtonTableList,
31-
ButtonClose
32-
})
33-
checkExports('ButtonGroup', {
34-
default: ButtonGroup
35-
})
11+
behavesAsComponent({Component: Button, options: {skipAs: true}})
3612

37-
it('renders a <button>', () => {
38-
expect(render(<Button />).type).toEqual('button')
13+
it('renders a <button>', async () => {
14+
const container = render(<Button>Default</Button>)
15+
const button = await container.findByRole('button')
16+
expect(button.textContent).toEqual('Default')
3917
})
4018

4119
it('should have no axe violations', async () => {
42-
const {container} = HTMLRender(<Button>Click here</Button>)
20+
const {container} = render(<Button>Click here</Button>)
4321
const results = await axe(container)
4422
expect(results).toHaveNoViolations()
4523
cleanup()
4624
})
4725

48-
it('preserves "onClick" prop', () => {
49-
expect(render(<Button onClick={noop} />).props.onClick).toEqual(noop)
50-
})
51-
52-
it('respects width props', () => {
53-
expect(render(<Button sx={{width: 200}} />)).toHaveStyleRule('width', '200px')
26+
it('preserves "onClick" prop', async () => {
27+
const onClick = jest.fn()
28+
const container = render(<Button onClick={onClick}>Noop</Button>)
29+
const button = await container.findByRole('button')
30+
fireEvent.click(button)
31+
expect(onClick).toHaveBeenCalledTimes(1)
5432
})
5533

56-
it('respects the "disabled" prop', () => {
57-
const item = render(<Button disabled />)
58-
expect(item.props.disabled).toEqual(true)
59-
expect(item).toMatchSnapshot()
34+
it('respects width props', async () => {
35+
const container = render(<Button sx={{width: 200}}>Block</Button>)
36+
const button = await container.findByRole('button')
37+
expect(button).toHaveStyleRule('width', '200px')
6038
})
6139

62-
it('respects the "variant" prop', () => {
63-
expect(render(<Button variant="small" />)).toHaveStyleRule('font-size', '12px')
64-
expect(render(<Button variant="large" />)).toHaveStyleRule('font-size', '16px')
65-
})
66-
67-
it('respects the "fontSize" prop over the "variant" prop', () => {
68-
expect(render(<Button variant="small" sx={{fontSize: 20}} />)).toHaveStyleRule('font-size', '20px')
69-
})
70-
})
71-
72-
describe('ButtonPrimary', () => {
73-
behavesAsComponent({Component: ButtonPrimary})
74-
75-
it('renders a <button>', () => {
76-
expect(render(<ButtonPrimary />).type).toEqual('button')
40+
it('respects the "disabled" prop', async () => {
41+
const onClick = jest.fn()
42+
const container = render(
43+
<Button onClick={onClick} disabled>
44+
Disabled
45+
</Button>
46+
)
47+
const button = await container.findByRole('button')
48+
expect(button.hasAttribute('disabled')).toEqual(true)
49+
fireEvent.click(button)
50+
expect(onClick).toHaveBeenCalledTimes(0)
7751
})
7852

79-
it('renders correct disabled styles', () => {
80-
const item = render(<ButtonPrimary disabled />)
81-
expect(item).toMatchSnapshot()
53+
it('respects the "variant" prop', async () => {
54+
const container = render(<Button size="small">Smol</Button>)
55+
const button = await container.findByRole('button')
56+
expect(button).toHaveStyleRule('font-size', '12px')
8257
})
83-
})
84-
85-
describe('ButtonDanger', () => {
86-
behavesAsComponent({Component: ButtonDanger})
8758

88-
it('renders a <button>', () => {
89-
expect(render(<ButtonDanger />).type).toEqual('button')
59+
it('respects the "fontSize" prop over the "variant" prop', async () => {
60+
const container = render(
61+
<Button size="small" sx={{fontSize: 20}}>
62+
Big Smol
63+
</Button>
64+
)
65+
const button = await container.findByRole('button')
66+
expect(button).toHaveStyleRule('font-size', '20px')
9067
})
9168

92-
it('renders correct disabled styles', () => {
93-
const item = render(<ButtonDanger disabled />)
94-
expect(item).toMatchSnapshot()
69+
it('styles primary button appropriately', async () => {
70+
const container = render(<Button variant="primary">Primary</Button>)
71+
const button = await container.findByRole('button')
72+
expect(button).toMatchSnapshot()
9573
})
96-
})
97-
98-
describe('ButtonOutline', () => {
99-
behavesAsComponent({Component: ButtonOutline})
10074

101-
it('renders a <button> by default', () => {
102-
expect(render(<ButtonOutline />).type).toEqual('button')
75+
it('styles invisible button appropriately', async () => {
76+
const container = render(<Button variant="invisible">Invisible</Button>)
77+
const button = await container.findByRole('button')
78+
expect(button).toMatchSnapshot()
10379
})
10480

105-
it('renders correct disabled styles', () => {
106-
const item = render(<ButtonOutline disabled />)
107-
expect(item).toMatchSnapshot()
81+
it('styles danger button appropriately', async () => {
82+
const container = render(<Button variant="danger">Danger</Button>)
83+
const button = await container.findByRole('button')
84+
expect(button).toMatchSnapshot()
10885
})
109-
})
11086

111-
describe('ButtonInvisible', () => {
112-
behavesAsComponent({Component: ButtonOutline})
113-
114-
it('renders a <button> by default', () => {
115-
expect(render(<ButtonInvisible />).type).toEqual('button')
87+
it('styles outline button appropriately', async () => {
88+
const container = render(<Button variant="outline">Outline</Button>)
89+
const button = await container.findByRole('button')
90+
expect(button).toMatchSnapshot()
11691
})
11792

118-
it('renders correct disabled styles', () => {
119-
const item = render(<ButtonInvisible disabled />)
120-
expect(item).toMatchSnapshot()
93+
it('styles icon only button to make it a square', async () => {
94+
const container = render(<IconButton icon={SearchIcon} iconLabel="Search icon only button" />)
95+
const IconOnlyButton = await container.findByRole('button')
96+
expect(IconOnlyButton).toHaveStyleRule('padding-right', '8px')
12197
})
12298
})
123-
124-
describe('ButtonGroup', () => {
125-
behavesAsComponent({Component: ButtonGroup})
126-
})
127-
128-
describe('ButtonTableList', () => {
129-
behavesAsComponent({Component: ButtonTableList})
130-
})

0 commit comments

Comments
 (0)