1- import React from "react" ;
1+ import React , { ReactElement } from "react" ;
2+ import { Button } from "@react-md/button" ;
23import { render } from "@testing-library/react" ;
3- import { create } from "react-test-renderer" ;
44
5- import { DialogFooter , DialogFooterProps } from "../DialogFooter" ;
5+ import {
6+ DialogFooter ,
7+ DialogFooterAlignment ,
8+ DialogFooterProps ,
9+ } from "../DialogFooter" ;
610
7- const aligns : DialogFooterProps [ "align" ] [ ] = [
11+ const aligns : readonly DialogFooterAlignment [ ] = [
812 "none" ,
913 "start" ,
1014 "end" ,
@@ -13,73 +17,23 @@ const aligns: DialogFooterProps["align"][] = [
1317 "stacked-end" ,
1418] ;
1519
20+ function Test ( { align } : DialogFooterProps ) : ReactElement {
21+ return (
22+ < DialogFooter align = { align } >
23+ < Button > First Button</ Button >
24+ < Button > Second Button</ Button >
25+ </ DialogFooter >
26+ ) ;
27+ }
28+
1629describe ( "DialogFooter" , ( ) => {
1730 it ( "should render correctly" , ( ) => {
18- const { container } = render ( < DialogFooter > Footer</ DialogFooter > ) ;
19- const footer = container . querySelector ( "footer" ) as HTMLElement ;
20-
21- expect ( footer ) . not . toBeNull ( ) ;
22- expect ( footer . textContent ) . toBe ( "Footer" ) ;
23- } ) ;
24-
25- it ( 'should apply the "rmd-dialog__footer--flex" className if the align prop is not "none"' , ( ) => {
26- const { container, rerender } = render ( < DialogFooter align = "none" /> ) ;
27- const footer = container . querySelector ( "footer" ) as HTMLElement ;
28- expect ( footer . className ) . not . toContain ( "rmd-dialog__footer--flex" ) ;
29-
30- aligns . slice ( 1 ) . forEach ( ( align ) => {
31- rerender ( < DialogFooter align = { align } /> ) ;
32- expect ( footer . className ) . toContain ( "rmd-dialog__footer--flex" ) ;
33- } ) ;
34- } ) ;
35-
36- it ( 'should apply the "rmd-dialog__footer--ALIGN" className if the align prop is not "none"' , ( ) => {
37- const { container, rerender } = render ( < DialogFooter align = "none" /> ) ;
38- const footer = container . querySelector ( "footer" ) as HTMLElement ;
39- expect ( footer . className ) . not . toContain ( "rmd-dialog__footer--none" ) ;
31+ const { container, rerender } = render ( < Test /> ) ;
32+ expect ( container ) . toMatchSnapshot ( ) ;
4033
41- aligns . slice ( 1 ) . forEach ( ( align ) => {
42- rerender ( < DialogFooter align = { align } /> ) ;
43- expect ( footer . className ) . toContain ( `rmd-dialog__footer--${ align } ` ) ;
44- } ) ;
45- } ) ;
46-
47- it ( 'should default to align="end"' , ( ) => {
48- const { container } = render ( < DialogFooter /> ) ;
49-
50- const footer = container . querySelector ( "footer" ) as HTMLElement ;
51- expect ( footer ) . not . toBeNull ( ) ;
52-
53- expect ( footer . className ) . toContain ( "rmd-dialog__footer--end" ) ;
54- } ) ;
55-
56- it ( "should render correctly (with snapshots)" , ( ) => {
5734 aligns . forEach ( ( align ) => {
58- expect (
59- create (
60- < DialogFooter id = "dialog-footer" align = { align } >
61- < button id = "close-dialog" type = "button" >
62- Close
63- </ button >
64- < button id = "confirm-dialog" type = "button" >
65- Confirm
66- </ button >
67- </ DialogFooter >
68- ) . toJSON ( )
69- ) . toMatchSnapshot ( ) ;
70-
71- expect (
72- create (
73- < DialogFooter id = "dialog-footer" className = "custom-class names-here" >
74- < button id = "close-dialog" type = "button" >
75- Close
76- </ button >
77- < button id = "confirm-dialog" type = "button" >
78- Confirm
79- </ button >
80- </ DialogFooter >
81- ) . toJSON ( )
82- ) . toMatchSnapshot ( ) ;
35+ rerender ( < Test align = { align } /> ) ;
36+ expect ( container ) . toMatchSnapshot ( ) ;
8337 } ) ;
8438 } ) ;
8539} ) ;
0 commit comments