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

test: Test the ImageButton component #409

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
57 changes: 57 additions & 0 deletions tests/plugins/image/ImageButton_test.js
Original file line number Diff line number Diff line change
@@ -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(<ImageButton {...testContext} />);
});

// smoke test
it("it should render", () => {
shallow(<ImageButton />);
});

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);
});
});
3 changes: 3 additions & 0 deletions tests/plugins/image/__snapshots__/ImageButton_test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ImageButton component it should render the expected HTML 1`] = `"<button class=\\"image-button\\" type=\\"button\\" title=\\"title image button\\"><svg class=\\"sidemenu__button__icon\\" width=\\"24\\" height=\\"24\\" viewBox=\\"0 0 24 24\\"><path d=\\"M18.222 6H5.778C4.8 6 4 6.6 4 7.333v9.334C4 17.4 4.8 18 5.778 18h12.444C19.2 18 20 17.4 20 16.667V7.333C20 6.6 19.2 6 18.222 6zm-4.084 4l-3 4.51L9 11.503 6 16h12l-3.862-6z\\" fill=\\"currentColor\\" fill-rule=\\"evenodd\\"></path></svg></button>"`;