Skip to content

Commit

Permalink
test: switch toast's utils tests to react testing library
Browse files Browse the repository at this point in the history
  • Loading branch information
lsprr committed Apr 24, 2024
1 parent c0eeb76 commit 8a8cdae
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 40 deletions.
40 changes: 0 additions & 40 deletions packages/react/__tests__/src/components/Toast/utils.js

This file was deleted.

49 changes: 49 additions & 0 deletions packages/react/src/components/Toast/utils.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';
import { render } from '@testing-library/react';
import { tabIndexHandler } from './utils';

let toast: HTMLElement | null;
let targets: HTMLElement[];

beforeEach(() => {
{
/* eslint-disable jsx-a11y/no-noninteractive-tabindex */
}
const { container } = render(
<div>
<div className="toaster"></div>
<div className="zero" tabIndex={0}></div>
<div className="minus-one" tabIndex={-1}></div>
</div>
);

toast = container.querySelector('.toaster');
targets = Array.from(container.querySelectorAll('.zero, .minus-one'));
});

afterEach(() => {
toast = null;
targets = [];
});

test('should properly reset tabIndex', () => {
targets.forEach((target) => {
target.setAttribute('data-cached-tabindex', target.tabIndex.toString());
target.tabIndex = -1;
});

if (toast) {
tabIndexHandler(true, toast);
}

expect(targets[0].tabIndex).toBe(0);
expect(targets[1].tabIndex).toBe(-1);
});

test('should properly set data-cached-tabindex / tabIndex', () => {
if (toast) {
tabIndexHandler(false, toast);
}
expect(targets[0].tabIndex).toBe(-1);
expect(targets[0].getAttribute('data-cached-tabindex')).toBe('0');
});

0 comments on commit 8a8cdae

Please sign in to comment.