Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions package-lock.json

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

1 change: 1 addition & 0 deletions packages/doc-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@babel/plugin-transform-runtime": "^7.29.0",
"@babel/preset-env": "^7.29.0",
"@babel/preset-typescript": "^7.28.5",
"@primer/vitest-config": "^0.0.0",
"@rollup/plugin-babel": "^6.1.0",
"@rollup/plugin-commonjs": "^29.0.0",
"@rollup/plugin-json": "^6.1.0",
Expand Down
1 change: 1 addition & 0 deletions packages/doc-gen/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default defineConfig({
},
test: {
environment: 'node',
setupFiles: ['@primer/vitest-config/setup'],
detectAsyncLeaks: true,
},
})
1 change: 1 addition & 0 deletions packages/postcss-preset-primer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"postcss-preset-env": "^10.1.3"
},
"devDependencies": {
"@primer/vitest-config": "^0.0.0",
"@types/postcss-mixins": "9.0.5",
"cssnano": "^7.0.7",
"postcss": "^8.4.41",
Expand Down
1 change: 1 addition & 0 deletions packages/postcss-preset-primer/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {defineConfig} from 'vitest/config'
export default defineConfig({
test: {
environment: 'node',
setupFiles: ['@primer/vitest-config/setup'],
detectAsyncLeaks: true,
},
})
1 change: 1 addition & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"@figma/code-connect": "1.3.2",
"@primer/css": "^21.5.1",
"@primer/doc-gen": "^0.0.1",
"@primer/vitest-config": "^0.0.0",
"@rollup/plugin-babel": "6.1.0",
"@rollup/plugin-commonjs": "29.0.0",
"@rollup/plugin-json": "6.1.0",
Expand Down
143 changes: 80 additions & 63 deletions packages/react/src/ActionList/Group.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, it, expect} from 'vitest'
import {describe, it, expect, vi} from 'vitest'
import {render as HTMLRender} from '@testing-library/react'
import {PlusIcon} from '@primer/octicons-react'
import BaseStyles from '../BaseStyles'
Expand All @@ -22,22 +22,23 @@ describe('ActionList.Group', () => {
implementsClassName(ActionList.GroupHeading, classes.GroupHeading)

it('should throw an error when ActionList.GroupHeading has an `as` prop when it is used within ActionMenu context', async () => {
expect(() =>
HTMLRender(
<BaseStyles>
<ActionMenu open={true}>
<ActionMenu.Button>Trigger</ActionMenu.Button>
<ActionMenu.Overlay>
<ActionList>
<ActionList.Group>
<ActionList.GroupHeading as="h2">Group Heading</ActionList.GroupHeading>
</ActionList.Group>
</ActionList>
</ActionMenu.Overlay>
</ActionMenu>
</BaseStyles>,
),
).toThrow(
expect.hasAssertions()
expectRenderError(
() =>
HTMLRender(
<BaseStyles>
<ActionMenu open={true}>
<ActionMenu.Button>Trigger</ActionMenu.Button>
<ActionMenu.Overlay>
<ActionList>
<ActionList.Group>
<ActionList.GroupHeading as="h2">Group Heading</ActionList.GroupHeading>
</ActionList.Group>
</ActionList>
</ActionMenu.Overlay>
</ActionMenu>
</BaseStyles>,
),
"Looks like you are trying to set a heading level to a menu role. Group headings for menu type action lists are for representational purposes, and rendered as divs. Therefore they don't need a heading level.",
)
})
Expand All @@ -56,17 +57,18 @@ describe('ActionList.Group', () => {
expect(heading).toHaveTextContent('Group Heading')
})
it('should throw an error if ActionList.GroupHeading is used without an `as` prop when no role is specified (for list role)', async () => {
expect(() =>
HTMLRender(
<ActionList>
<ActionList.Heading as="h1">Heading</ActionList.Heading>
<ActionList.Group>
<ActionList.GroupHeading>Group Heading</ActionList.GroupHeading>
<ActionList.Item>Item</ActionList.Item>
</ActionList.Group>
</ActionList>,
),
).toThrow(
expect.hasAssertions()
expectRenderError(
() =>
HTMLRender(
<ActionList>
<ActionList.Heading as="h1">Heading</ActionList.Heading>
<ActionList.Group>
<ActionList.GroupHeading>Group Heading</ActionList.GroupHeading>
<ActionList.Item>Item</ActionList.Item>
</ActionList.Group>
</ActionList>,
),
"You are setting a heading for a list, that requires a heading level. Please use 'as' prop to set a proper heading level.",
)
})
Expand Down Expand Up @@ -191,44 +193,59 @@ describe('ActionList.Group', () => {
})

it('throws when GroupHeading.TrailingAction is used inside an ActionMenu (menu role) and the feature flag is enabled', () => {
expect(() =>
HTMLRender(
<FeatureFlags flags={{primer_react_action_list_group_heading_trailing_action: true}}>
<BaseStyles>
<ActionMenu open={true}>
<ActionMenu.Button>Trigger</ActionMenu.Button>
<ActionMenu.Overlay>
<ActionList>
<ActionList.Group>
<ActionList.GroupHeading>
Group Heading
<ActionList.GroupHeading.TrailingAction label="New field" icon={PlusIcon} />
</ActionList.GroupHeading>
</ActionList.Group>
</ActionList>
</ActionMenu.Overlay>
</ActionMenu>
</BaseStyles>
</FeatureFlags>,
),
).toThrow(/can not be used inside an ActionList with an ARIA role of "menu"/)
expect.hasAssertions()
expectRenderError(
() =>
HTMLRender(
<FeatureFlags flags={{primer_react_action_list_group_heading_trailing_action: true}}>
<BaseStyles>
<ActionMenu open={true}>
<ActionMenu.Button>Trigger</ActionMenu.Button>
<ActionMenu.Overlay>
<ActionList>
<ActionList.Group>
<ActionList.GroupHeading>
Group Heading
<ActionList.GroupHeading.TrailingAction label="New field" icon={PlusIcon} />
</ActionList.GroupHeading>
</ActionList.Group>
</ActionList>
</ActionMenu.Overlay>
</ActionMenu>
</BaseStyles>
</FeatureFlags>,
),
/can not be used inside an ActionList with an ARIA role of "menu"/,
)
})

it('throws when GroupHeading.TrailingAction is used inside a listbox role and the feature flag is enabled', () => {
expect(() =>
HTMLRender(
<FeatureFlags flags={{primer_react_action_list_group_heading_trailing_action: true}}>
<ActionList role="listbox">
<ActionList.Group>
<ActionList.GroupHeading>
Group Heading
<ActionList.GroupHeading.TrailingAction label="New field" icon={PlusIcon} />
</ActionList.GroupHeading>
</ActionList.Group>
</ActionList>
</FeatureFlags>,
),
).toThrow(/can not be used inside an ActionList with an ARIA role of "listbox"/)
expect.hasAssertions()
expectRenderError(
() =>
HTMLRender(
<FeatureFlags flags={{primer_react_action_list_group_heading_trailing_action: true}}>
<ActionList role="listbox">
<ActionList.Group>
<ActionList.GroupHeading>
Group Heading
<ActionList.GroupHeading.TrailingAction label="New field" icon={PlusIcon} />
</ActionList.GroupHeading>
</ActionList.Group>
</ActionList>
</FeatureFlags>,
),
/can not be used inside an ActionList with an ARIA role of "listbox"/,
)
})
})
})

function expectRenderError(callback: () => void, error: string | RegExp) {
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {})
try {
expect(callback).toThrow(error)
} finally {
consoleError.mockRestore()
}
}
Loading
Loading