Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit aff686d

Browse files
committed
chore: cypress tests cleanup
1 parent 69b31ae commit aff686d

File tree

4 files changed

+80
-74
lines changed

4 files changed

+80
-74
lines changed

packages/c-alert/tests/c-alert.cy.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ it('contains the correct role', () => {
1919
.should('exist')
2020
})
2121

22-
it.only('renders its children', () => {
22+
it('renders its children', () => {
2323
cy.mount(
2424
<CAlert data-testid="alert" variant="left-accent" status="info" mb="3">
2525
<CAlertIcon mr="2" />

packages/c-button/src/button-group.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { computed, defineComponent, h, PropType } from 'vue'
1+
import { computed, ComputedRef, defineComponent, h, PropType } from 'vue'
22
import {
33
SystemCSSProperties,
44
SystemStyleObject,
@@ -34,9 +34,9 @@ const props = {
3434
...vueThemingProps,
3535
}
3636

37-
type ButtonGroupContext = () => ThemingProps & {
37+
type ButtonGroupContext = ComputedRef<ThemingProps & {
3838
isDisabled?: boolean
39-
}
39+
}>
4040

4141
const [ButtonGroupProvider, useButtonGroup] = createContext<ButtonGroupContext>(
4242
{
@@ -49,34 +49,36 @@ const CButtonGroup = defineComponent({
4949
name: 'CButtonGroup',
5050
props,
5151
setup(props, { attrs, slots }) {
52-
ButtonGroupProvider(() => ({
52+
ButtonGroupProvider(computed(() => ({
5353
size: props.size,
5454
colorScheme: props.colorScheme,
5555
variant: props.variant,
5656
isDisabled: props.isDisabled,
57-
}))
58-
return () => {
59-
const styles = computed(() => {
60-
let groupStyles: SystemStyleObject = {
61-
display: 'inline-flex',
62-
}
57+
})))
6358

64-
if (props.isAttached) {
65-
groupStyles = {
66-
...groupStyles,
67-
'> *:first-of-type:not(:last-of-type)': { borderRightRadius: 0 },
68-
'> *:not(:first-of-type):not(:last-of-type)': { borderRadius: 0 },
69-
'> *:not(:first-of-type):last-of-type': { borderLeftRadius: 0 },
70-
}
71-
} else {
72-
groupStyles = {
73-
...groupStyles,
74-
'& > *:not(style) ~ *:not(style)': { marginLeft: props.spacing },
75-
}
59+
const styles = computed(() => {
60+
let groupStyles: SystemStyleObject = {
61+
display: 'inline-flex',
62+
}
63+
64+
if (props.isAttached) {
65+
groupStyles = {
66+
...groupStyles,
67+
'> *:first-of-type:not(:last-of-type)': { borderRightRadius: 0 },
68+
'> *:not(:first-of-type):not(:last-of-type)': { borderRadius: 0 },
69+
'> *:not(:first-of-type):last-of-type': { borderLeftRadius: 0 },
70+
}
71+
} else {
72+
groupStyles = {
73+
...groupStyles,
74+
'& > *:not(style) ~ *:not(style)': { marginLeft: props.spacing },
7675
}
76+
}
7777

78-
return groupStyles
79-
})
78+
return groupStyles
79+
})
80+
81+
return () => {
8082

8183
return h(
8284
chakra('div', { label: 'button__group' }),

packages/c-button/src/button.ts

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ const CButtonSpinner = defineComponent({
2121
>,
2222
},
2323
setup(props, { attrs }) {
24+
const spinnerStyles = computed<SystemStyleObject>(() => ({
25+
display: 'flex',
26+
alignItems: 'center',
27+
position: props.label ? 'relative' : 'absolute',
28+
marginEnd: props.label ? props.spacing : 0,
29+
}))
30+
2431
return () => {
25-
const spinnerStyles = computed<SystemStyleObject>(() => ({
26-
display: 'flex',
27-
alignItems: 'center',
28-
position: props.label ? 'relative' : 'absolute',
29-
marginEnd: props.label ? props.spacing : 0,
30-
}))
3132
return h(
3233
chakra('div', {
3334
label: 'button__spinner',
@@ -80,41 +81,42 @@ const CButton = defineComponent({
8081
name: 'CButton',
8182
props: BUTTON_PROPS,
8283
setup(props, { attrs, slots }) {
83-
return () => {
84-
const themingProps = computed<ThemingProps>(() =>
85-
filterUndefined({
86-
colorScheme: props.colorScheme,
87-
variant: props.variant,
88-
size: props.size,
89-
styleConfig: props.styleConfig,
90-
})
91-
)
92-
93-
const group = useButtonGroup()
94-
const styles = useStyleConfig('Button', {
95-
...group?.(),
96-
...themingProps.value,
84+
const themingProps = computed<ThemingProps>(() =>
85+
filterUndefined({
86+
colorScheme: props.colorScheme,
87+
variant: props.variant,
88+
size: props.size,
89+
styleConfig: props.styleConfig,
9790
})
91+
)
9892

99-
const _focus = mergeWith({}, styles.value?.['_focus'] ?? {}, {
100-
zIndex: 1,
101-
})
93+
const group = useButtonGroup()
94+
const styles = useStyleConfig('Button', {
95+
...group.value,
96+
...themingProps.value,
97+
})
98+
99+
const _focus = computed(() => mergeWith({}, styles.value?.['_focus'] ?? {}, {
100+
zIndex: 1,
101+
}))
102+
103+
const buttonStyles = computed<SystemStyleObject>(() => ({
104+
display: 'inline-flex',
105+
appearance: 'none',
106+
alignItems: 'center',
107+
justifyContent: 'center',
108+
transition: 'all 250ms',
109+
userSelect: 'none',
110+
position: 'relative',
111+
whiteSpace: 'nowrap',
112+
verticalAlign: 'middle',
113+
outline: 'none',
114+
width: props.isFullWidth ? '100%' : 'auto',
115+
...styles.value,
116+
...(!!group.value && { _focus: _focus.value }),
117+
}))
102118

103-
const buttonStyles = computed<SystemStyleObject>(() => ({
104-
display: 'inline-flex',
105-
appearance: 'none',
106-
alignItems: 'center',
107-
justifyContent: 'center',
108-
transition: 'all 250ms',
109-
userSelect: 'none',
110-
position: 'relative',
111-
whiteSpace: 'nowrap',
112-
verticalAlign: 'middle',
113-
outline: 'none',
114-
width: props.isFullWidth ? '100%' : 'auto',
115-
...styles.value,
116-
...(!!group && { _focus }),
117-
}))
119+
return () => {
118120

119121
return h(
120122
chakra(props.as, {

tests/support.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import { mount as cyMount } from '@cypress/vue'
44
import { feActivity } from 'feather-icons-paths'
55
import { MotionPlugin } from '@vueuse/motion'
66
import { h, Fragment, Component } from 'vue'
7-
8-
import ChakraUIVuePlugin, { chakra } from '@chakra-ui/vue-next'
7+
import Chakra, { chakra, extendTheme } from '@chakra-ui/vue-next'
98
import { domElements } from '@chakra-ui/vue-system'
109
import { CReset } from '@chakra-ui/c-reset'
1110

1211

12+
const theme = extendTheme({})
13+
1314
declare global {
1415
namespace Cypress {
1516
interface cy extends Chainable {
@@ -44,9 +45,9 @@ const globalComponents = domElements.reduce((acc, tag) => {
4445
const plugins = [
4546
MotionPlugin,
4647
[
47-
ChakraUIVuePlugin,
48+
Chakra,
4849
{
49-
// TODO: import icons from the same place that Playground does
50+
extendTheme: theme,
5051
icons: {
5152
library: { feActivity },
5253
},
@@ -56,13 +57,14 @@ const plugins = [
5657

5758
// @ts-ignore
5859
Cypress.Commands.add('mount', (MyComponent, options?) => {
59-
// createApp root element
60-
const rootComponent = () => (
61-
<>
62-
<MyComponent />
63-
<CReset />
64-
</>
65-
)
60+
const rootComponent = () => {
61+
return (
62+
<>
63+
<MyComponent />
64+
<CReset />
65+
</>
66+
)
67+
}
6668

6769
return cyMount(
6870
{

0 commit comments

Comments
 (0)