Skip to content

Commit 8fa6d64

Browse files
committed
tests(a11y): space should trigger role button
1 parent 3d4039b commit 8fa6d64

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

cypress/integration/modules/a11y.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ context('Core', () => {
44
describe('a11y', () => {
55
beforeEach(() => {
66
cy.swiperPage();
7-
cy.initSwiper();
7+
cy.initSwiper({
8+
speed: 0,
9+
navigation: true,
10+
pagination: true,
11+
});
812
});
913
it('should add aria-live="polite" to swiper-wrapper', () => {
1014
cy.getSliderWrapper().should('have.attr', 'aria-live', 'polite');
@@ -35,5 +39,19 @@ context('Core', () => {
3539
cy.getSlide(4).should('have.attr', 'aria-label', `5 / ${count}`);
3640
cy.getSlide(9).should('have.attr', 'aria-label', `10 / ${count}`);
3741
});
42+
43+
it('should navigate with arrows on enter or space key', () => {
44+
cy.get('.swiper-button-next').trigger('keydown', { keyCode: 13 });
45+
cy.getSlide(1).should('have.class', 'swiper-slide-active');
46+
cy.get('.swiper-button-next').trigger('keydown', { keyCode: 32 });
47+
cy.getSlide(2).should('have.class', 'swiper-slide-active');
48+
});
49+
50+
it('should navigate with pagination on enter or space key', () => {
51+
cy.get('.swiper-pagination-bullet:nth-child(2)').trigger('keydown', { keyCode: 13 });
52+
cy.getSlide(1).should('have.class', 'swiper-slide-active');
53+
cy.get('.swiper-pagination-bullet:nth-child(5)').trigger('keydown', { keyCode: 32 });
54+
cy.getSlide(4).should('have.class', 'swiper-slide-active');
55+
});
3856
});
3957
});

cypress/support/commands.js

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,51 @@ Cypress.Commands.add(
7575
}
7676
</div>
7777
`;
78-
// eslint-disable-next-line dot-notation
79-
_window.swiper = new _window['SwiperClass'](el, config);
80-
return _window.swiper;
78+
setTimeout(() => {
79+
// eslint-disable-next-line dot-notation
80+
const _config = config;
81+
if (config.navigation === true) {
82+
_config.navigation = {
83+
nextEl: '.swiper-button-next',
84+
prevEl: '.swiper-button-prev',
85+
hideOnClick: false,
86+
disabledClass: 'swiper-button-disabled',
87+
hiddenClass: 'swiper-button-hidden',
88+
lockClass: 'swiper-button-lock',
89+
};
90+
}
91+
if (config.pagination === true) {
92+
_config.pagination = {
93+
el: '.swiper-pagination',
94+
bulletElement: 'span',
95+
clickable: true,
96+
hideOnClick: false,
97+
renderBullet: null,
98+
renderProgressbar: null,
99+
renderFraction: null,
100+
renderCustom: null,
101+
progressbarOpposite: false,
102+
type: 'bullets', // 'bullets' or 'progressbar' or 'fraction' or 'custom'
103+
dynamicBullets: false,
104+
dynamicMainBullets: 1,
105+
formatFractionCurrent: (number) => number,
106+
formatFractionTotal: (number) => number,
107+
bulletClass: 'swiper-pagination-bullet',
108+
bulletActiveClass: 'swiper-pagination-bullet-active',
109+
modifierClass: 'swiper-pagination-', // NEW
110+
currentClass: 'swiper-pagination-current',
111+
totalClass: 'swiper-pagination-total',
112+
hiddenClass: 'swiper-pagination-hidden',
113+
progressbarFillClass: 'swiper-pagination-progressbar-fill',
114+
progressbarOppositeClass: 'swiper-pagination-progressbar-opposite',
115+
clickableClass: 'swiper-pagination-clickable', // NEW
116+
lockClass: 'swiper-pagination-lock',
117+
};
118+
}
119+
_window.swiperRef = new _window.Swiper(el, _config);
120+
console.log(_window.swiperRef);
121+
return _window.swiperRef;
122+
});
81123
});
82124
},
83125
);

cypress/test.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<title>Swiper demo</title>
77
<script src="../package/swiper-bundle.js"></script>
88
<script>
9-
window.SwiperClass = Swiper;
10-
window.swiper = null;
9+
// window.SwiperClass = Swiper;
10+
// window.swiper = null;
1111
</script>
1212
<!-- Link Swiper's CSS -->
1313
<link rel="stylesheet" href="../package/swiper-bundle.css" />

0 commit comments

Comments
 (0)