Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: clean up notification animation tests #7341

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 21 additions & 30 deletions packages/notification/test/animation.test.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
import { expect } from '@esm-bundle/chai';
import { aTimeout, fixtureSync, oneEvent } from '@vaadin/testing-helpers';
import '../vaadin-notification.js';
import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';

registerStyles(
'vaadin-notification-card',
css`
@keyframes test-animation {
100% {
opacity: 0;
}
}

:host {
width: 200px;
background: lightgrey;
}

:host([slot^='bottom']) {
animation: none !important;
}

:host([slot='middle'][closing]) {
animation: test-animation 100ms;
}
`,
{ moduleId: 'vaadin-notification-card-animation-theme' },
);

describe('animated notifications', () => {
let wrapper, notifications, container;

const animationDuration = 20;

beforeEach(async () => {
wrapper = fixtureSync(`
<div>
Expand All @@ -41,16 +17,21 @@ describe('animated notifications', () => {
notifications = Array.from(wrapper.children);
container = notifications[0]._container;

// Change default duration and wait for both notifications to be opened
const duration = 20;
notifications[0]._card.style.animation = 'none';
notifications[1]._card.style.animationDuration = `${animationDuration}ms`;

notifications.forEach((elm) => {
elm.duration = duration;
elm.duration = -1;
elm.opened = true;
elm.renderer = (root) => {
root.textContent = 'Notification';
};
});
await aTimeout(duration);

// Notification 0 has no animation, it is fully opened immediately
// Notification 1 has animation, it is fully opened after the animation ends.
// Let's, however, start the tests while the opening animation is still running.
await aTimeout(animationDuration / 2);
});

afterEach(() => {
Expand All @@ -59,24 +40,31 @@ describe('animated notifications', () => {

describe('animation', () => {
it('should remove card immediately if no animation defined', () => {
notifications[0].close();
expect(notifications[0]._card.parentNode).not.to.be.ok;
});

it('should not remove card after timeout if animation running', () => {
notifications[1].close();
expect(notifications[1]._card.parentNode).to.be.ok;
});

it('should remove card after animation', async () => {
notifications[1].close();
await oneEvent(notifications[1]._card, 'animationend');
expect(notifications[1]._card.parentNode).not.to.be.ok;
});

it('should close the container when all active notifications disappear', async () => {
notifications[0].close();
notifications[1].close();
await oneEvent(notifications[1]._card, 'animationend');
expect(container.opened).to.be.false;
});

it('should set `closing` attribute and remove later', async () => {
notifications[0].close();
notifications[1].close();
expect(notifications[0]._card.hasAttribute('closing')).to.be.false;
expect(notifications[1]._card.hasAttribute('closing')).to.be.true;
await oneEvent(notifications[1]._card, 'animationend');
Expand All @@ -85,6 +73,9 @@ describe('animated notifications', () => {
});

it('should set `opening` attribute and remove later', async () => {
notifications[1].close();
await oneEvent(notifications[1]._card, 'animationend');
notifications[1].open();
expect(notifications[1]._card.hasAttribute('opening')).to.be.true;
await oneEvent(notifications[1]._card, 'animationend');
expect(notifications[1]._card.hasAttribute('opening')).to.be.false;
Expand Down
Loading