[go: nahoru, domu]

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 edfca5b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
12 changes: 6 additions & 6 deletions src/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ function Notification(
);
}

type NotificationShow = {
export type NotificationFunction = ForwardRefExoticComponent<NotificationProps & RefAttributes<NotificationElement>> & {
show(contents: string, options?: ShowOptions): Promise<NotificationElement>;
define(): Promise<void>;
};

export type NotificationFunction = ForwardRefExoticComponent<NotificationProps & RefAttributes<NotificationElement>> &
NotificationShow;

const ForwardedNotification = forwardRef(Notification) as NotificationFunction;

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

ForwardedNotification.show = async function (contents: string, options?: ShowOptions) {
await _Notification.define();
const Notification = customElements.get('vaadin-notification') as unknown as NotificationShow;
await ForwardedNotification.define();
const Notification = customElements.get('vaadin-notification') as typeof NotificationElement;
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 edfca5b

Please sign in to comment.