@carbon/ibm-products-web-components
Version:
Carbon for IBM Products Web Components
66 lines (63 loc) • 3.05 kB
JavaScript
/**
* Copyright IBM Corp. 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
import { describe, it, expect } from 'vitest';
import { fixture, oneEvent, html } from '@open-wc/testing';
import './notification-panel.js';
import './notification.js';
import './notification-footer.js';
/**
* Copyright IBM Corp. 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const templateFooter = () => {
return html `
<c4p-notification-footer
slot="footer"
view-all-label="View all (10)"
@c4p-notification-view-all=${() => {
console.log('view all clicked');
}}
@c4p-notification-settings=${() => {
console.log('Settings clicked');
}}
></c4p-notification-footer>
`;
};
describe('c4p-notification', () => {
it('should render the notification', async () => {
const notificationFooter = (await fixture(templateFooter()));
expect(notificationFooter).toBeDefined();
});
it('should render View All text based the "viewAllLabel" prop passed', async () => {
var _a, _b;
const notificationFooter = (await fixture(templateFooter()));
expect(notificationFooter.viewAllLabel).toBe('View all (10)');
const viewAllButton = (_a = notificationFooter.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('.c4p--notifications-panel__view-all-button');
expect((_b = viewAllButton === null || viewAllButton === void 0 ? void 0 : viewAllButton.textContent) === null || _b === void 0 ? void 0 : _b.trim()).toBe(notificationFooter.viewAllLabel);
});
it('should emit "c4p-notification-view-all" when clicked on view all button', async () => {
var _a;
const notificationFooter = (await fixture(templateFooter()));
const eventPromise = oneEvent(notificationFooter, 'c4p-notification-view-all');
const viewAllButton = (_a = notificationFooter.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('.c4p--notifications-panel__view-all-button');
viewAllButton === null || viewAllButton === void 0 ? void 0 : viewAllButton.click();
const event = await eventPromise;
expect(event).toBeDefined();
});
it('should emit "c4p-notification-settings" when clicked on settings button', async () => {
var _a;
const notificationFooter = (await fixture(templateFooter()));
const eventPromise = oneEvent(notificationFooter, 'c4p-notification-settings');
const settingsButton = (_a = notificationFooter.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('.c4p--notifications-panel__settings-button');
settingsButton === null || settingsButton === void 0 ? void 0 : settingsButton.click();
const event = await eventPromise;
expect(event).toBeDefined();
});
});
//# sourceMappingURL=notification-footer.test.js.map