-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate class component to functional (#403)
Co-authored-by: Lucas Silveira <[email protected]>
- Loading branch information
1 parent
777316a
commit 1caecd3
Showing
5 changed files
with
132 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (c) 2016, Globo.com (https://github.com/globocom) | ||
* | ||
* License: MIT | ||
*/ | ||
|
||
import React from "react"; | ||
import { mount } from "enzyme"; | ||
|
||
import image from "../../src/plugins/image/plugin"; | ||
import PluginsModal from "../../src/components/PluginsModal"; | ||
import { ActionsContext } from "../../src/components/ActionsProvider"; | ||
|
||
describe("PluginsModal", () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
const mountComponent = (params = {}, onAction = jest.fn()) => { | ||
const props = { | ||
i18n: {}, | ||
isOpen: false, | ||
toggleModalVisibility: jest.fn(), | ||
plugins: [image], | ||
onChange: jest.fn(), | ||
editorState: {}, | ||
modalOptions: {}, | ||
...params | ||
}; | ||
|
||
return mount( | ||
<ActionsContext.Provider value={{ onAction }}> | ||
<PluginsModal {...props} /> | ||
</ActionsContext.Provider> | ||
); | ||
}; | ||
|
||
it("should be able to render component", () => { | ||
const component = mountComponent(); | ||
expect(component.find("Modal")).toBeTruthy(); | ||
}); | ||
|
||
it("should be able to render modal with different size options", () => { | ||
const component = mountComponent({ | ||
modalOptions: { | ||
width: 900, | ||
height: 900 | ||
} | ||
}); | ||
|
||
const { width, height } = component.find("Modal").props(); | ||
expect(width).toEqual(900); | ||
expect(height).toEqual(900); | ||
}); | ||
|
||
it("should be able to execute onCloseRequest function", () => { | ||
const toggleModalVisibility = jest.fn(); | ||
const onAction = jest.fn(); | ||
|
||
const component = mountComponent( | ||
{ | ||
isOpen: true, | ||
toggleModalVisibility | ||
}, | ||
onAction | ||
); | ||
|
||
const { onCloseRequest } = component.find("Modal").props(); | ||
onCloseRequest(); | ||
expect(toggleModalVisibility).toHaveBeenCalled(); | ||
expect(onAction).toHaveBeenCalled(); | ||
}); | ||
}); |