Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(delete-book): add delete book confirmation
- Loading branch information
1 parent
25efe44
commit e0a2994
Showing
8 changed files
with
160 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import Modal from "../../../components/common/Modal"; | ||
|
||
const props = { | ||
title: 'title', | ||
question: 'question', | ||
subText: 'subText', | ||
confirmColor: 'confirmColor', | ||
cancelColor: 'cancelColor', | ||
confirmText: 'confirmText', | ||
cancelText: 'cancelText', | ||
modalAction: jest.fn() | ||
}; | ||
|
||
describe('Modal', () => { | ||
const wrapper = shallow(<Modal { ...props } />); | ||
it('renders without crashing', () => { | ||
expect(wrapper.getElement().type).toBe("div"); | ||
expect(wrapper.find("div").length).toBeGreaterThan(1); | ||
}); | ||
|
||
it("calls modalAction prop function when a confirm button is clicked", () => { | ||
const confirmButton = wrapper.find("button").at(1); | ||
confirmButton.simulate("click"); | ||
expect(wrapper.instance().props.modalAction).toHaveBeenCalled(); | ||
}); | ||
}) |
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,18 @@ | ||
import rootReducer from "../../reducers/rootReducer"; | ||
import initialState from "../../reducers/initialState"; | ||
import { logoutUser } from "../../actions/authActions/logout"; | ||
|
||
|
||
describe("Root Reducer", () => { | ||
it("should return initial state for unkwon action types", () => { | ||
const action = { type: null }; | ||
const newState = rootReducer(initialState, action); | ||
expect(newState).toEqual(initialState); | ||
}); | ||
|
||
it("handles action of type LOGOUT", () => { | ||
const action = logoutUser(); | ||
const newState = rootReducer(initialState, action); | ||
expect(newState).toEqual(initialState); | ||
}); | ||
}); |
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,66 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import setupModal from './setupModal'; | ||
|
||
|
||
/** | ||
* a modal Component | ||
* @extends Component | ||
*/ | ||
class Modal extends Component { | ||
/** | ||
* lifecycle method called when component mounts the DOM | ||
* @returns {undefined} no return value | ||
*/ | ||
componentDidMount() { | ||
setupModal(); | ||
} | ||
|
||
/** | ||
* renders a Modal to the DOM | ||
* @return {JSX} JSX representation of the Component | ||
*/ | ||
render() { | ||
return <div id="confirm-modal" className="modal admin-form"> | ||
<div className="modal-content center"> | ||
<h4 className="blue-border-bottom bold-text">{this.props.title}</h4> | ||
<h5 className="grey-text text-lighten-2">{this.props.question}</h5> | ||
<p className="bold-text"> | ||
{this.props.subText} | ||
</p> | ||
</div> | ||
<div className="modal-footer admin-form center s12"> | ||
<div className="col s6 offset-s3"> | ||
<button | ||
className={`modal-action btn darken-4 white-text modal-close | ||
s6 action-btn waves-effect waves-red btn-flat | ||
${this.props.confirmColor}`} | ||
onClick={() => this.props.modalAction()} | ||
> | ||
{this.props.confirmText} | ||
</button> | ||
<button | ||
className={`modal-action action-btn btn darken-4 | ||
white-text modal-close waves-effect | ||
waves-green btn-flat ${this.props.cancelColor}`} | ||
> | ||
{this.props.cancelText} | ||
</button> | ||
</div> | ||
</div> | ||
</div>; | ||
} | ||
} | ||
|
||
Modal.propTypes = { | ||
title: PropTypes.string.isRequired, | ||
question: PropTypes.string.isRequired, | ||
subText: PropTypes.string.isRequired, | ||
confirmColor: PropTypes.string.isRequired, | ||
cancelColor: PropTypes.string.isRequired, | ||
confirmText: PropTypes.string.isRequired, | ||
cancelText: PropTypes.string.isRequired, | ||
modalAction: PropTypes.func.isRequired | ||
}; | ||
|
||
export default Modal; |
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,6 @@ | ||
export default () => { | ||
const $ = window.$ || window.jquery; | ||
$(document).ready(() => { | ||
$('.modal').modal(); | ||
}); | ||
}; |
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