Skip to content

Commit

Permalink
fixup! Test(web): Add tests for Toast component
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelklibani committed Mar 6, 2024
1 parent 6b828d1 commit 6d0ed55
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/web/src/js/__tests__/Toast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ import { clearFixture, getFixture } from '../../../tests/helpers/fixture';
import Toast from '../Toast';
import { CLASS_NAME_HIDDEN, CLASS_NAME_OPEN } from '../constants';

const testId = 'toast-test';

const toastHtmlClosed = `
<div id="toast-test" class="ToastBar ToastBar--success ToastBar--dismissible is-hidden"></div>
<div id="${testId}" class="ToastBar ToastBar--success ToastBar--dismissible is-hidden">
<button type="button" data-spirit-target="#toast-test" aria-expanded="false">Close</button>
</div>
`;

const toastHtmlOpened = `
<div id="toast-test" class="ToastBar ToastBar--success ToastBar--dismissible is-open"></div>
<div id="toast-test" class="ToastBar ToastBar--success ToastBar--dismissible is-open">
<button type="button" data-spirit-target="#toast-test" aria-expanded="true">Close</button>
</div>
`;

describe('Toast', () => {
Expand Down Expand Up @@ -55,12 +61,14 @@ describe('Toast', () => {

const element = fixtureEl.querySelector('.ToastBar') as HTMLElement;
const toast = new Toast(element);
const trigger = fixtureEl.querySelector(`[data-spirit-target="#${testId}"]`) as HTMLButtonElement;

const showSpy = jest.spyOn(Toast.prototype, 'show');

await toast.show();

expect(showSpy).toHaveBeenCalled();
expect(trigger).toHaveAttribute('aria-expanded', 'true');
expect(element).toHaveClass(CLASS_NAME_OPEN);
});
});
Expand All @@ -71,12 +79,14 @@ describe('Toast', () => {

const element = fixtureEl.querySelector('.ToastBar') as HTMLElement;
const toast = new Toast(element);
const trigger = fixtureEl.querySelector(`[data-spirit-target="#${testId}"]`) as HTMLButtonElement;

const hideSpy = jest.spyOn(Toast.prototype, 'hide');

await toast.hide();

expect(hideSpy).toHaveBeenCalled();
expect(trigger).toHaveAttribute('aria-expanded', 'false');
expect(element).toHaveClass(CLASS_NAME_HIDDEN);
});
});
Expand Down

0 comments on commit 6d0ed55

Please sign in to comment.