@@ -5,45 +5,8 @@ import * as React from "react";
55import { InPageNavigation , InPageNavigationItem } from "../src" ;
66
77describe ( "InPageNavigation" , ( ) => {
8- it ( "should render a nav with correct aria-label" , ( ) => {
9- const { getByRole } = render (
10- < InPageNavigation aria-label = "my-nav" >
11- < InPageNavigationItem href = "#" > page 1</ InPageNavigationItem >
12- < InPageNavigationItem href = "#" > page 2</ InPageNavigationItem >
13- </ InPageNavigation > ,
14- ) ;
15-
16- expect ( getByRole ( "navigation" ) ) . toHaveAttribute ( "aria-label" , "my-nav" ) ;
17- } ) ;
18-
19- it ( "should render a list with list items and links" , ( ) => {
20- const { getAllByRole } = render (
21- < InPageNavigation aria-label = "my-nav" >
22- < InPageNavigationItem href = "#" > page 1</ InPageNavigationItem >
23- < InPageNavigationItem href = "#" > page 2</ InPageNavigationItem >
24- </ InPageNavigation > ,
25- ) ;
26-
27- expect ( getAllByRole ( "list" ) ) . toHaveLength ( 1 ) ;
28- expect ( getAllByRole ( "listitem" ) ) . toHaveLength ( 2 ) ;
29- expect ( getAllByRole ( "link" ) ) . toHaveLength ( 2 ) ;
30- } ) ;
31-
32- it ( "should use the currentPage prop to apply aria-current" , ( ) => {
33- const { getByText } = render (
34- < InPageNavigation aria-label = "my-nav" >
35- < InPageNavigationItem href = "#" > page 1</ InPageNavigationItem >
36- < InPageNavigationItem currentPage href = "#" >
37- page 2
38- </ InPageNavigationItem >
39- </ InPageNavigation > ,
40- ) ;
41-
42- expect ( getByText ( "page 2" ) ) . toHaveAttribute ( "aria-current" , "page" ) ;
43- } ) ;
44-
45- it ( "should pass props given to InPageNavigationItem onto its <a> child" , ( ) => {
46- const { getByText } = render (
8+ it ( "should render semantically correct with aria properly" , ( ) => {
9+ const { getByRole, getAllByRole, getByText } = render (
4710 < InPageNavigation aria-label = "my-nav" >
4811 < InPageNavigationItem data-test-id = "page-1" href = "#" >
4912 page 1
@@ -54,40 +17,17 @@ describe("InPageNavigation", () => {
5417 </ InPageNavigation > ,
5518 ) ;
5619
20+ expect ( getByRole ( "navigation" ) ) . toHaveAttribute ( "aria-label" , "my-nav" ) ;
21+ expect ( getAllByRole ( "list" ) ) . toHaveLength ( 1 ) ;
22+ expect ( getAllByRole ( "listitem" ) ) . toHaveLength ( 2 ) ;
23+ expect ( getAllByRole ( "link" ) ) . toHaveLength ( 2 ) ;
24+ expect ( getByText ( "page 2" ) ) . toHaveAttribute ( "aria-current" , "page" ) ;
5725 expect ( getByText ( "page 1" ) ) . toHaveAttribute ( "data-test-id" , "page-1" ) ;
5826 } ) ;
5927} ) ;
6028
6129describe ( "Customization" , ( ) => {
62- it ( "should set a default element name" , ( ) => {
63- const { getByRole } = render (
64- < InPageNavigation aria-label = "my-nav" >
65- < InPageNavigationItem href = "#" > page 1</ InPageNavigationItem >
66- </ InPageNavigation > ,
67- ) ;
68-
69- expect ( getByRole ( "navigation" ) ) . toHaveAttribute ( "data-paste-element" , "IN_PAGE_NAVIGATION" ) ;
70- expect ( getByRole ( "list" ) ) . toHaveAttribute ( "data-paste-element" , "IN_PAGE_NAVIGATION_ITEMS" ) ;
71- expect ( getByRole ( "listitem" ) ) . toHaveAttribute ( "data-paste-element" , "IN_PAGE_NAVIGATION_ITEM" ) ;
72- expect ( getByRole ( "link" ) ) . toHaveAttribute ( "data-paste-element" , "IN_PAGE_NAVIGATION_ITEM_ANCHOR" ) ;
73- } ) ;
74-
75- it ( "should set a custom element name when provided" , ( ) => {
76- const { getByRole } = render (
77- < InPageNavigation element = "MY_IN_PAGE_NAVIGATION" aria-label = "my-nav" >
78- < InPageNavigationItem element = "MY_IN_PAGE_NAVIGATION_ITEM" href = "#" >
79- page 1
80- </ InPageNavigationItem >
81- </ InPageNavigation > ,
82- ) ;
83-
84- expect ( getByRole ( "navigation" ) ) . toHaveAttribute ( "data-paste-element" , "MY_IN_PAGE_NAVIGATION" ) ;
85- expect ( getByRole ( "list" ) ) . toHaveAttribute ( "data-paste-element" , "MY_IN_PAGE_NAVIGATION_ITEMS" ) ;
86- expect ( getByRole ( "listitem" ) ) . toHaveAttribute ( "data-paste-element" , "MY_IN_PAGE_NAVIGATION_ITEM" ) ;
87- expect ( getByRole ( "link" ) ) . toHaveAttribute ( "data-paste-element" , "MY_IN_PAGE_NAVIGATION_ITEM_ANCHOR" ) ;
88- } ) ;
89-
90- it ( "should add custom styles to default element names" , ( ) => {
30+ it ( "should add custom styles to the default element name" , ( ) => {
9131 const { getByRole } = render (
9232 < CustomizationProvider
9333 baseTheme = "default"
@@ -102,13 +42,24 @@ describe("Customization", () => {
10242 < InPageNavigation aria-label = "my-nav" >
10343 < InPageNavigationItem href = "#" > page 1</ InPageNavigationItem >
10444 </ InPageNavigation >
45+ ,
10546 </ CustomizationProvider > ,
10647 ) ;
10748
108- expect ( getByRole ( "navigation" ) ) . toHaveStyleRule ( "font-weight" , "400" ) ;
109- expect ( getByRole ( "list" ) ) . toHaveStyleRule ( "padding" , "0.75rem" ) ;
110- expect ( getByRole ( "listitem" ) ) . toHaveStyleRule ( "margin" , "0.75rem" ) ;
111- expect ( getByRole ( "link" ) ) . toHaveStyleRule ( "font-size" , "1rem" ) ;
49+ const nav = getByRole ( "navigation" ) ;
50+ const list = getByRole ( "list" ) ;
51+ const listitem = getByRole ( "listitem" ) ;
52+ const link = getByRole ( "link" ) ;
53+
54+ expect ( nav ) . toHaveAttribute ( "data-paste-element" , "IN_PAGE_NAVIGATION" ) ;
55+ expect ( list ) . toHaveAttribute ( "data-paste-element" , "IN_PAGE_NAVIGATION_ITEMS" ) ;
56+ expect ( listitem ) . toHaveAttribute ( "data-paste-element" , "IN_PAGE_NAVIGATION_ITEM" ) ;
57+ expect ( link ) . toHaveAttribute ( "data-paste-element" , "IN_PAGE_NAVIGATION_ITEM_ANCHOR" ) ;
58+
59+ expect ( nav ) . toHaveStyleRule ( "font-weight" , "400" ) ;
60+ expect ( list ) . toHaveStyleRule ( "padding" , "0.75rem" ) ;
61+ expect ( listitem ) . toHaveStyleRule ( "margin" , "0.75rem" ) ;
62+ expect ( link ) . toHaveStyleRule ( "font-size" , "1rem" ) ;
11263 } ) ;
11364
11465 it ( "should add custom styles to custom element names" , ( ) => {
@@ -131,9 +82,19 @@ describe("Customization", () => {
13182 </ CustomizationProvider > ,
13283 ) ;
13384
134- expect ( getByRole ( "navigation" ) ) . toHaveStyleRule ( "font-weight" , "400" ) ;
135- expect ( getByRole ( "list" ) ) . toHaveStyleRule ( "padding" , "0.75rem" ) ;
136- expect ( getByRole ( "listitem" ) ) . toHaveStyleRule ( "margin" , "0.75rem" ) ;
137- expect ( getByRole ( "link" ) ) . toHaveStyleRule ( "font-size" , "1rem" ) ;
85+ const nav = getByRole ( "navigation" ) ;
86+ const list = getByRole ( "list" ) ;
87+ const listitem = getByRole ( "listitem" ) ;
88+ const link = getByRole ( "link" ) ;
89+
90+ expect ( nav ) . toHaveAttribute ( "data-paste-element" , "MY_IN_PAGE_NAVIGATION" ) ;
91+ expect ( list ) . toHaveAttribute ( "data-paste-element" , "MY_IN_PAGE_NAVIGATION_ITEMS" ) ;
92+ expect ( listitem ) . toHaveAttribute ( "data-paste-element" , "MY_IN_PAGE_NAVIGATION_ITEM" ) ;
93+ expect ( link ) . toHaveAttribute ( "data-paste-element" , "MY_IN_PAGE_NAVIGATION_ITEM_ANCHOR" ) ;
94+
95+ expect ( nav ) . toHaveStyleRule ( "font-weight" , "400" ) ;
96+ expect ( list ) . toHaveStyleRule ( "padding" , "0.75rem" ) ;
97+ expect ( listitem ) . toHaveStyleRule ( "margin" , "0.75rem" ) ;
98+ expect ( link ) . toHaveStyleRule ( "font-size" , "1rem" ) ;
13899 } ) ;
139100} ) ;
0 commit comments