test('FormTaskItem New filds', () => {
component.find(".task-item-name").at(0).simulate('change', { target: { value: 'test name' } });
component.find(".task-item-text").at(0).simulate('change', { target: { value: 'test text' } });
console.log(component.find(".task-item-name").at(0));
const btn = component.find(".form-submit");
btn.simulate('click');
expect(actionsetNewTaskItem).toHaveBeenCalledWith({
keychapter: "-Mnu71_BYp_test",
title: 'test name',
text: 'test text'
}, dispatch);
});
<input type="text" className="task-item-name" name="title" placeholder="Enter task item name" required="" ref={c => this.inputTaskItemName = c} />
this.inputTaskItemName.value,
"use strict";
import React from 'react';
import { TaskItemContainer } from '../components/TaskItemContainer.js';
jest.mock('../actions/TaskItem.js');
import {
actionopenFormNewItemEdit,
actionremoveTaskItem,
actionsetTaskItemStyle,
actionsetTaskItemPin
} from '../actions/TaskItem.js';
describe('TaskItemContainer', () => {
let props = {
data: {
name: "Мои заметки № 1",
text: "Мои заметки № 1",
time: 1636283818894,
key: "-Mnu6P7dMJTeVv8VESLh3",
keychapter: "0"
},
keychapter: "0",
keyitem: "-Mnu6P7dMJTeVv8VESLh3",
index: 1,
attrdata: "all",
del: false,
}
let dispatch = jest.fn();
// actionopenFormNewItemEdit.mockReturnValue(data);
actionopenFormNewItemEdit.mockImplementation((data, dispatch) => { return data; });
actionsetTaskItemStyle.mockImplementation((data, dispatch) => { return data; });
const component = shallow(
<TaskItemContainer dispatch={dispatch} data={props.data} keychapter="0" keyitem="-Mnu6P7dMJTeVv8VESLh3" key="-Mnu6P7dMJTeVv8VESLh3" index={1}
attrdata={"all"}
/>
);
const instance = component.instance();
test('TaskItemContainer openFormNewItemEdit', () => {
instance.openFormNewItemEdit();
expect(actionopenFormNewItemEdit).toHaveBeenCalledWith({
name: 'Мои заметки № 1',
text: 'Мои заметки № 1',
activ: true,
keychapter: '0',
keyitem: '-Mnu6P7dMJTeVv8VESLh3'
}, dispatch
);
});
test('TaskItemContainer addDel', () => {
instance.addDel();
expect(component.state().del).toBeTruthy();
});
test('TaskItemContainer setColor', () => {
instance.setColor({ "backgroundColor": "#fff4ba", "border": "1px solid #fbe67b" });
expect(actionsetTaskItemStyle).toHaveBeenCalledWith({
style: { "backgroundColor": "#fff4ba", "border": "1px solid #fbe67b" },
keychapter: '0',
keyitem: '-Mnu6P7dMJTeVv8VESLh3'
}, dispatch
);
});
test('TaskItemContainer setPin', () => {
instance.setPin(true);
expect(actionsetTaskItemPin).toHaveBeenCalledWith({
pin: false,
keychapter: '0',
keyitem: '-Mnu6P7dMJTeVv8VESLh3'
}, dispatch
);
});
test('TaskItemContainer getTime', () => {
instance.getTime(1636283818894);
expect(instance.getTime(1636283818894)).toBe('7/10/2021 14:16');
});
});
const component = mount(
<Provider store={store}><TaskItemContainer dispatch={dispatch} data={props.data} keychapter="0" keyitem="-Mnu6P7dMJTeVv8VESLh3" key="-Mnu6P7dMJTeVv8VESLh3" index={1}
attrdata={"all"}
/></Provider>
);
const instance = component.instance();
jest.mock('../actions/TaskItem.js');
import {
actionsetTaskItemPin
} from '../actions/TaskItem.js';
и перед рендрингом компонента так
actionsetTaskItemPin.mockImplementation((data, dispatch) => { return data; });
test('TaskItemContainer setPin', () => {
instance.setPin(true);
expect(actionsetTaskItemPin).toHaveBeenCalledWith({
pin: false,
keychapter: '0',
keyitem: '-Mnu6P7dMJTeVv8VESLh3'
}, dispatch
);
});
const keyValues = Object.keys(obj).map((key) => {
var camelCased = key.replace(/-[a-z]/g, (g) => g[1].toUpperCase());
return { [camelCased]: obj[key] };
});
CSSstring(string) {
if (string) {
const css_json = `{"${string
.replace(/; /g, '", "')
.replace(/: /g, '": "')
.replace(";", "")}"}`;
const obj = JSON.parse(css_json);
const keyValues = Object.keys(obj).map((key) => {
var camelCased = key.replace(/-[a-z]/g, (g) => g[1].toUpperCase());
return { [camelCased]: obj[key] };
});
return Object.assign({}, ...keyValues);
}
}
get(child(dbRef, "book")).then((snapshot) => {
if (snapshot.exists()) {
let book = { ...snapshot.val() };
console.log("book", book);
dispatch({ type: BOOK_LOAD_REQUEST, data: { book: book } });
}
else {
console.log("no data found");
}
}).catch((error) => {
console.log("unsaccessful error " + error);
});
},
setColor = (e) => {
debugger;
let data = { style: e.target.getAttribute("style"), keychapter: this.state.keychapter, keyitem: this.state.keyitem };
api.setTaskItemStyle(data, this.props.dispatch);
}
делаю так