diff --git a/tests/plugins/image/ImageButton_test.js b/tests/plugins/image/ImageButton_test.js new file mode 100644 index 00000000..8aace4a1 --- /dev/null +++ b/tests/plugins/image/ImageButton_test.js @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2016, Globo.com (https://github.com/globocom) + * + * License: MIT + */ + +import React from "react"; +import { shallow, mount } from "enzyme"; + +import ImageButton from "../../../src/plugins/image/ImageButton"; +import { editorStateFromRaw } from "../../../src/utils"; + +describe("ImageButton component", () => { + let testContext; + + beforeEach(() => { + const INITIAL_CONTENT = { + entityMap: {}, + blocks: [] + }; + + testContext = { + onChange: jest.fn(), + editorState: editorStateFromRaw(INITIAL_CONTENT), + className: "image-button", + title: "title image button" + }; + + jest.spyOn(window, "prompt").mockImplementation(() => "Enter an URL"); + + testContext.wrapper = mount(); + }); + + // smoke test + it("it should render", () => { + shallow(); + }); + + it("it should render the expected HTML", () => { + expect(testContext.wrapper.html()).toMatchSnapshot(); + }); + + it("it should render the expected className", () => { + expect(testContext.wrapper.find("button.image-button")).toHaveLength(1); + }); + + it("it should render the expected attribute title", () => { + expect(testContext.wrapper.find("button").props()["title"]).toBe( + "title image button" + ); + }); + + it("it should simulate the click button", () => { + testContext.wrapper.find("button").simulate("click"); + expect(testContext.onChange.mock.calls.length).toEqual(1); + }); +}); diff --git a/tests/plugins/image/__snapshots__/ImageButton_test.js.snap b/tests/plugins/image/__snapshots__/ImageButton_test.js.snap new file mode 100644 index 00000000..935d4faa --- /dev/null +++ b/tests/plugins/image/__snapshots__/ImageButton_test.js.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ImageButton component it should render the expected HTML 1`] = `""`;