Skip to content

Commit

Permalink
Update Notification to expose define helper
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Jan 17, 2024
1 parent 5089f60 commit 4722b9a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
9 changes: 7 additions & 2 deletions src/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@ type NotificationShow = {
};

export type NotificationFunction = ForwardRefExoticComponent<NotificationProps & RefAttributes<NotificationElement>> &
NotificationShow;
NotificationShow & {
define(): Promise<void>;
};

const ForwardedNotification = forwardRef(Notification) as NotificationFunction;


Object.assign(ForwardedNotification, { define: _Notification.define });

ForwardedNotification.show = async function (contents: string, options?: ShowOptions) {
await _Notification.define();
await ForwardedNotification.define();
const Notification = customElements.get('vaadin-notification') as unknown as NotificationShow;
return Notification.show(contents, options);
};
Expand Down
23 changes: 9 additions & 14 deletions test/Notification.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,38 @@ describe('Notification', () => {
return <>FooBar</>;
}

async function until(predicate: () => boolean) {
while (!predicate()) {
await new Promise((r) => setTimeout(r, 10));
}
}

async function assert() {
await until(() => !!document.querySelector('vaadin-notification-card'));
function assert() {
const card = document.querySelector('vaadin-notification-card');
expect(card).to.exist;
expect(card).to.have.text('FooBar');
}

before(Notification.define);

afterEach(cleanup);
afterEach(catcher);

it('should use children if no renderer property set', async () => {
it('should use children if no renderer property set', () => {
render(
<Notification ref={ref} opened>
FooBar
</Notification>,
);
await assert();
assert();
});

it('should use renderer prop if it is set', async () => {
it('should use renderer prop if it is set', () => {
render(<Notification ref={ref} opened renderer={Renderer} />);
await assert();
assert();
});

it('should use children render function as a renderer prop', async () => {
it('should use children render function as a renderer prop', () => {
render(
<Notification ref={ref} opened>
{Renderer}
</Notification>,
);
await assert();
assert();
});

describe('show()', () => {
Expand Down

0 comments on commit 4722b9a

Please sign in to comment.