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

docs(snackbar): updated docs to support @action #2154

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/components/ebay-snackbar-dialog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ebay-snackbar-dialog
</span>
<span style='font-weight: normal; font-size: medium; margin-bottom: -15px;'>
DS v1.0.0
DS v2.0.0
</span>
</h1>

Expand Down
21 changes: 11 additions & 10 deletions src/components/ebay-snackbar-dialog/examples/action.marko
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class {
declare state: {
open: boolean;
}
};

onCreate() {
this.state = {open: false};
this.state = { open: false };
}

handleOpen() {
Expand All @@ -13,20 +13,21 @@ class {

handleClose() {
this.state.open = false;
}

handleAction() {
//do API call, other action here
alert("action")
this.emit("close");
}
}

<ebay-button on-click("handleOpen")>
Open Action Snackbar
</ebay-button>
<ebay-snackbar-dialog open=state.open on-close('handleClose') on-action("handleAction")>
<ebay-snackbar-dialog
open=state.open
on-close("handleClose")
on-open("emit", "open")
on-action("emit", "action")
...input
>
<@action accessKey="U">
Undo
</@action>
This is the action snackbar
This 'snackbar' text should be 1-2 lines.
</ebay-snackbar-dialog>
2 changes: 1 addition & 1 deletion src/components/ebay-snackbar-dialog/examples/default.marko
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ class {
Open Default Snackbar
</ebay-button>
<ebay-snackbar-dialog open=state.open on-close('handleClose') on-open('emit', 'open') ...input >
${input.snacktext}
This 'snackbar' text should be 1-2 lines.
</ebay-snackbar-dialog>
43 changes: 26 additions & 17 deletions src/components/ebay-snackbar-dialog/snackbar-dialog.stories.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import Readme from "./README.md";
import Component from "./examples/default.marko";
import code from "./examples/default.marko?raw";
import component from "./index.marko";
import {
addRenderBodies,
buildExtensionTemplate,
} from "../../../.storybook/utils";

import defaultTemplate from "./examples/default.marko";
import defaultTemplateCode from "./examples/default.marko?raw";
import withActionTemplate from "./examples/action.marko";
import withActionTemplateCode from "./examples/action.marko?raw";

const Template = (args) => ({
input: {
Expand All @@ -15,7 +23,7 @@ const Template = (args) => ({

export default {
title: "dialogs/ebay-snackbar-dialog",
component: Component,
component,
parameters: {
docs: {
description: {
Expand All @@ -37,9 +45,12 @@ export default {
control: { type: "radio" },
options: ["row", "column"],
},
snacktext: {
control: { type: "text" },
description: "for demo only",
action: {
name: "@action",
description: "If present, shows an action button on snackbar",
table: {
category: "@attribute tags",
},
},
onOpen: {
action: "on-open",
Expand Down Expand Up @@ -74,14 +85,12 @@ export default {
},
};

export const Standard = Template.bind({});
Standard.args = {
snacktext: "This is the snackbar",
};
Standard.parameters = {
docs: {
source: {
code,
},
},
};
export const Default = buildExtensionTemplate(
defaultTemplate,
defaultTemplateCode,
);

export const WithAction = buildExtensionTemplate(
withActionTemplate,
withActionTemplateCode,
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<DocumentFragment>
<button
class="btn btn--secondary"
data-ebayui=""
type="button"
>
Open Default Snackbar
</button>
<div
aria-live="polite"
aria-modal="true"
class="snackbar-dialog snackbar-dialog--transition"
hidden=""
role="dialog"
>
<div
class="snackbar-dialog__window"
>
<div
class="snackbar-dialog__header"
/>
<div
class="snackbar-dialog__main"
>
This 'snackbar' text should be 1-2 lines.
</div>
</div>
</div>
</DocumentFragment>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<DocumentFragment>
<button
class="btn btn--secondary"
data-ebayui=""
type="button"
>
Open Default Snackbar
</button>
<div
aria-live="polite"
aria-modal="true"
class="snackbar-dialog snackbar-dialog--transition"
role="dialog"
>
<div
class="snackbar-dialog__window"
>
<div
class="snackbar-dialog__header"
/>
<div
class="snackbar-dialog__main"
>
This 'snackbar' text should be 1-2 lines.
</div>
</div>
</div>
</DocumentFragment>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<DocumentFragment>
<button
class="btn btn--secondary"
data-ebayui=""
type="button"
>
Open Action Snackbar
</button>
<div
aria-live="polite"
aria-modal="true"
class="snackbar-dialog snackbar-dialog--transition"
hidden=""
role="dialog"
>
<div
class="snackbar-dialog__window"
>
<div
class="snackbar-dialog__header"
/>
<div
class="snackbar-dialog__main"
>
This 'snackbar' text should be 1-2 lines.
</div>
<span
class="snackbar-dialog__actions"
>
<button
class="fake-link"
data-ebayui=""
type="button"
>
Undo
<span
class="clipped"
>
- Access Key: U
</span>
</button>
</span>
</div>
</div>
</DocumentFragment>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<DocumentFragment>
<button
class="btn btn--secondary"
data-ebayui=""
type="button"
>
Open Default Snackbar
</button>
<div
aria-live="polite"
aria-modal="true"
class="snackbar-dialog snackbar-dialog--transition"
hidden=""
role="dialog"
>
<div
class="snackbar-dialog__window snackbar-dialog__window--column"
>
<div
class="snackbar-dialog__header"
/>
<div
class="snackbar-dialog__main"
>
This 'snackbar' text should be 1-2 lines.
</div>
</div>
</div>
</DocumentFragment>
24 changes: 0 additions & 24 deletions src/components/ebay-snackbar-dialog/test/mock/index.js

This file was deleted.

31 changes: 18 additions & 13 deletions src/components/ebay-snackbar-dialog/test/test.browser.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { expect, use } from "chai";
import { composeStories } from "@storybook/marko";
import chaiDom from "chai-dom";
import sinon from "sinon/pkg/sinon";
import { render, fireEvent, cleanup, waitFor } from "@marko/testing-library";
import { fastAnimations } from "../../../common/test-utils/browser";
import template from "..";
import * as mock from "./mock";
import * as stories from "../snackbar-dialog.stories"; // import all stories from the stories file
const { Default, WithAction } = composeStories(stories);

use(chaiDom);
before(() => {
Expand All @@ -19,12 +21,16 @@ afterEach(() => {

/** @type import("@marko/testing-library").RenderResult */
let component;
let clock;

describe("given an open snackbar", () => {
const input = mock.Snackbar_Open;

beforeEach(async () => {
component = await render(template, input);
component = await render(WithAction, { open: true });
clock = sinon.useFakeTimers();
});

afterEach(() => {
clock.restore();
});

it("then it is not hidden in the DOM", () => {
Expand All @@ -33,30 +39,29 @@ describe("given an open snackbar", () => {

describe("clicking on action icon emits action", () => {
it("action emitted", async () => {
await fireEvent.click(component.getByText(/action/i));
await fireEvent.click(component.getByText(/Undo/i));
expect(component.emitted("action")).has.length(1);
});
});

describe("focus and mouseenter prevent closing it until all events", () => {
it("is not closed", async () => {
await fireEvent.mouseEnter(
component.getByText(/action/i).parentElement,
component.getByText(/Undo/i).parentElement,
);
await fireEvent.focus(component.getByText(/action/i).parentElement);
await fireEvent.blur(component.getByText(/action/i).parentElement);
await fireEvent.focus(component.getByText(/Undo/i).parentElement);
await fireEvent.blur(component.getByText(/Undo/i).parentElement);
clock.tick(7000);
await waitFor(() => {
expect(component.emitted("close")).has.length(0);
}, 7000);
});
});
});
});

describe("given a closed snackbar", () => {
const input = mock.Snackbar_Closed;

beforeEach(async () => {
component = await render(template, input);
component = await render(Default);
});

it("then it is hidden in the DOM", () => {
Expand Down
Loading
Loading