File tree Expand file tree Collapse file tree 2 files changed +37
-3
lines changed
Expand file tree Collapse file tree 2 files changed +37
-3
lines changed Original file line number Diff line number Diff line change 11import React from "react" ;
22import { render } from "@testing-library/react" ;
3- import { RadioList } from "./radio-list" ;
3+ import {
4+ RadioList ,
5+ COMPONENT_CLASS ,
6+ RadioListStyles ,
7+ RadioListButtonStyleClassName ,
8+ } from "./radio-list" ;
49import faker from "faker" ;
510
611describe ( "RadioList" , ( ) => {
@@ -16,4 +21,32 @@ describe("RadioList", () => {
1621 // Assert
1722 expect ( getByText ( expected ) ) . not . toBeNull ( ) ;
1823 } ) ;
24+
25+ test ( "when items prop is empty, radio-list returns" , ( ) => {
26+ // Arrange & Act
27+ const { container } = render ( < RadioList items = { [ ] } /> ) ;
28+ const result = container . querySelector ( "." + COMPONENT_CLASS ) ;
29+
30+ // Assert
31+ expect ( result ) . toBeNil ( ) ;
32+ } ) ;
33+
34+ test ( `when type prop is ${ RadioListStyles . Button } , renders with class name ${ RadioListButtonStyleClassName } ` , ( ) => {
35+ // Arrange
36+ const expected = faker . random . words ( ) ;
37+
38+ // Act
39+ const { container } = render (
40+ < RadioList
41+ items = { [ < span > { expected } </ span > ] }
42+ style = { RadioListStyles . Button }
43+ />
44+ ) ;
45+ const result = container . querySelector (
46+ "." + RadioListButtonStyleClassName
47+ ) ;
48+
49+ // Assert
50+ expect ( result ) . not . toBeNil ( ) ;
51+ } ) ;
1952} ) ;
Original file line number Diff line number Diff line change 11import * as React from "react" ;
22import { UnorderedList } from "./unordered-list" ;
33
4- const COMPONENT_CLASS = "c-radio-list" ;
4+ export const COMPONENT_CLASS = "c-radio-list" ;
5+ export const RadioListButtonStyleClassName = "-button-style" ;
56
67export interface RadioListProps {
78 items : JSX . Element [ ] ;
@@ -22,7 +23,7 @@ const RadioList: React.FunctionComponent<RadioListProps> = (props) => {
2223
2324 const classNames = [ COMPONENT_CLASS ] ;
2425 if ( style === RadioListStyles . Button ) {
25- classNames . push ( "-button-style" ) ;
26+ classNames . push ( RadioListButtonStyleClassName ) ;
2627 }
2728
2829 return (
You can’t perform that action at this time.
0 commit comments