Skip to content

Commit 83cbf0c

Browse files
test(separator): adds testing to separator component, fixes silly mistakes found throught tests
1 parent 2f716e6 commit 83cbf0c

File tree

2 files changed

+68
-5
lines changed

2 files changed

+68
-5
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { Separator } from './separator';
2+
3+
describe('Critical Functionality', () => {
4+
it('INIT', () => {
5+
cy.mount(<Separator />);
6+
7+
cy.checkA11yForComponent();
8+
});
9+
10+
it('GIVEN no orientation prop THEN aria-orientation is set unset', () => {
11+
cy.mount(<Separator />);
12+
13+
cy.findByRole('separator').should('not.have.attr', 'aria-orientation');
14+
});
15+
16+
it("GIVEN orientation prop 'horizontal' THEN aria-orientation is unset", () => {
17+
cy.mount(<Separator orientation="horizontal" />);
18+
19+
cy.findByRole('separator').should('not.have.attr', 'aria-orientation');
20+
});
21+
22+
it("GIVEN orientation prop 'vertical' THEN aria-orientation is set to 'vertical'", () => {
23+
cy.mount(<Separator orientation="vertical" />);
24+
25+
cy.findByRole('separator').should('have.attr', 'aria-orientation', 'vertical');
26+
});
27+
28+
it("GIVEN no orientation prop THEN data-orientation is set to 'horizontal'", () => {
29+
cy.mount(<Separator />);
30+
31+
cy.findByRole('separator').should('not.have.attr', 'aria-orientation');
32+
});
33+
34+
it("GIVEN orientation prop 'horizontal' THEN data-orientation is set to 'horizontal'", () => {
35+
cy.mount(<Separator orientation="horizontal" />);
36+
37+
cy.findByRole('separator').should('not.have.attr', 'aria-orientation');
38+
});
39+
40+
it("GIVEN orientation prop 'vertical' THEN data-orientation is set to 'vertical'", () => {
41+
cy.mount(<Separator orientation="vertical" />);
42+
43+
cy.findByRole('separator').should('have.attr', 'aria-orientation', 'vertical');
44+
});
45+
46+
it("GIVEN decorative prop THEN role is set to 'none' AND aria-orientation is unset", () => {
47+
cy.mount(<Separator decorative />);
48+
49+
cy.findByRole('none').should('not.have.attr', 'aria-orientation');
50+
});
51+
52+
it('GIVEN invalid orientation prop THEN console.warn is called', () => {
53+
const consoleSpy = cy.spy(console, 'warn');
54+
cy.mount(<Separator orientation={'invalid' as any} />);
55+
56+
cy.wrap(consoleSpy).should('have.been.calledWithMatch', /Invalid prop 'orientation'/);
57+
});
58+
});

packages/kit-headless/src/components/separator/separator.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import { component$, HTMLAttributes, useComputed$ } from '@builder.io/qwik';
1+
import { QwikIntrinsicElements } from '@builder.io/qwik';
2+
import { component$, useComputed$ } from '@builder.io/qwik';
23

34
const ORIENTATIONS = ['horizontal', 'vertical'] as const;
45

56
type Orientation = (typeof ORIENTATIONS)[number];
67

7-
export interface SeparatorProps extends HTMLAttributes<HTMLElement> {
8+
type QwikDiv = QwikIntrinsicElements['div'];
9+
10+
export interface SeparatorProps extends QwikDiv {
811
/**
912
* Either `vertical` or `horizontal`. Defaults to `horizontal`.
1013
*/
@@ -40,18 +43,20 @@ export const Separator = component$(
4043

4144
// `aria-orientation` defaults to `horizontal` so we only need it if `orientation` is vertical
4245
const ariaOrientation = useComputed$(() =>
43-
orientation.value === 'vertical' ? orientation : undefined
46+
orientation.value === 'vertical' ? orientation.value : undefined
4447
);
4548

4649
const semanticProps = useComputed$(() =>
4750
decorative
4851
? { role: 'none' }
4952
: {
5053
role: 'separator',
51-
'aria-orientation': ariaOrientation
54+
'aria-orientation': ariaOrientation.value
5255
}
5356
);
5457

55-
return <div data-orientation={orientation} {...semanticProps} {...props} />;
58+
return (
59+
<div data-orientation={orientation.value} {...semanticProps.value} {...props} />
60+
);
5661
}
5762
);

0 commit comments

Comments
 (0)