diff --git a/03 Tests samples/README.md b/03 Tests samples/README.md
index 94f645a..66b03af 100644
--- a/03 Tests samples/README.md
+++ b/03 Tests samples/README.md
@@ -21,7 +21,7 @@
- Tests samples for events onScroll
- Test samples for onMouseUp and onMouseDown
- Test samples for onContextMenu
-- Test samples for onSubmit
+- Test samples for onSubmit [onSubmitTest](./src/components/NameForm/NameForm.test.tsx)
- Tests samples for useSuscribeToScroll
- Tests samples using ref an useRef hook
diff --git a/03 Tests samples/src/components/MessageList/MessageList.less b/03 Tests samples/src/components/MessageList/MessageList.less
index 5ad4777..dbab41d 100644
--- a/03 Tests samples/src/components/MessageList/MessageList.less
+++ b/03 Tests samples/src/components/MessageList/MessageList.less
@@ -2,28 +2,37 @@
@headerBackgroundColor: gainsboro;
@evenTrBackgroundColor: #ffe8e8;
@oddTrBackgroundColor: white;
-
-.messages-table{
- border: @tableBorder;
- width: 80%;
- border-collapse: collapse;
- td, th {
+div {
+ width: 100%;
+ display: flex;
+ flex-direction: column;
+ .messages-table{
border: @tableBorder;
- };
- thead{
- tr{
- background-color: @headerBackgroundColor;
- text-align: left;
- }
- }
- tbody{
- tr{
- &:nth-child(even){
- background-color: @evenTrBackgroundColor;
+ width: 80%;
+ border-collapse: collapse;
+ td, th {
+ border: @tableBorder;
+ };
+ thead{
+ tr{
+ background-color: @headerBackgroundColor;
+ text-align: left;
}
- &:nth-child(odd){
- background-color: @oddTrBackgroundColor;
+ }
+ tbody{
+ tr{
+ &:nth-child(even){
+ background-color: @evenTrBackgroundColor;
+ }
+ &:nth-child(odd){
+ background-color: @oddTrBackgroundColor;
+ }
}
}
}
-};
\ No newline at end of file
+ button {
+ width: 20%;
+ background-color: black;
+ color: white;
+ }
+};
diff --git a/03 Tests samples/src/components/MessageList/MessageList.tsx b/03 Tests samples/src/components/MessageList/MessageList.tsx
index 58fd4ad..50fcd0d 100644
--- a/03 Tests samples/src/components/MessageList/MessageList.tsx
+++ b/03 Tests samples/src/components/MessageList/MessageList.tsx
@@ -3,24 +3,30 @@ import './MessageList.less';
import { Message } from '../../model';
interface MessageListProps {
- messages: Message[],
+ messages: Message[];
}
export const MessageList = (props: MessageListProps) => {
- return (
-
-
- | Subject |
- Body |
-
-
-
- {props.messages.map(message => {
- return (
- | {message.subject} |
- {message.body} |
-
);
- })}
-
-
);
+ return (
+
+
+
+
+ | Subject |
+ Body |
+
+
+
+ {props.messages.map((message) => {
+ return (
+
+ | {message.subject} |
+ {message.body} |
+
+ );
+ })}
+
+
+
+ );
};
diff --git a/03 Tests samples/src/components/MessagesSection/MessagesSection.test.tsx b/03 Tests samples/src/components/MessagesSection/MessagesSection.test.tsx
index 2c322a2..b28ba07 100644
--- a/03 Tests samples/src/components/MessagesSection/MessagesSection.test.tsx
+++ b/03 Tests samples/src/components/MessagesSection/MessagesSection.test.tsx
@@ -5,7 +5,6 @@ import Adapter from 'enzyme-adapter-react-16';
import sinon from 'sinon';
import { MessagesSectionComponent } from './MessagesSection';
-
describe('Message List component test', () => {
configure({ adapter: new Adapter() });
diff --git a/03 Tests samples/src/components/MessagesSection/MessagesSection.tsx b/03 Tests samples/src/components/MessagesSection/MessagesSection.tsx
index d25b7f5..1b4180e 100644
--- a/03 Tests samples/src/components/MessagesSection/MessagesSection.tsx
+++ b/03 Tests samples/src/components/MessagesSection/MessagesSection.tsx
@@ -1,5 +1,5 @@
import React from 'react';
-import { MessageForm, MessageList } from '../index';
+import { MessageForm, MessageList, NameForm } from '../index';
import { connect } from 'react-redux';
import { getAllMessages } from '../../redux/actions/MessagesActions';
import './MessagesSection.less';
@@ -36,6 +36,7 @@ export class MessagesSectionComponent extends React.Component<
Messages management sample, deployed
+
);
}
diff --git a/03 Tests samples/src/components/NameForm/NameForm.test.tsx b/03 Tests samples/src/components/NameForm/NameForm.test.tsx
new file mode 100644
index 0000000..b9de289
--- /dev/null
+++ b/03 Tests samples/src/components/NameForm/NameForm.test.tsx
@@ -0,0 +1,26 @@
+import React from 'react';
+import { mount } from 'enzyme';
+import { NameForm } from './NameForm';
+import { configure } from 'enzyme';
+import Adapter from 'enzyme-adapter-react-16';
+
+describe(' {
+ configure({ adapter: new Adapter() });
+ let component;
+ beforeEach(() => {
+ component = mount();
+ });
+ it('Should call alert() when submit button is clicked', () => {
+ window.alert = jest.fn();
+ component.setState({ value: 'Hello' });
+ const expectedValue = 'A name was submitted: Hello';
+ component.find('form').simulate('submit');
+ expect(window.alert).toHaveBeenCalledWith(expectedValue);
+ });
+ it('Should handle state changes', () => {
+ component.setState({clicked: false});
+ expect(component.state().clicked).toBe(false);
+ component.find('form').simulate('submit');
+ expect(component.state().clicked).toBe(true);
+ });
+});
diff --git a/03 Tests samples/src/components/NameForm/NameForm.tsx b/03 Tests samples/src/components/NameForm/NameForm.tsx
new file mode 100644
index 0000000..178984d
--- /dev/null
+++ b/03 Tests samples/src/components/NameForm/NameForm.tsx
@@ -0,0 +1,40 @@
+import React from 'react';
+
+interface MyState {
+ value: string;
+ clicked: boolean;
+}
+export class NameForm extends React.Component<{}, MyState> {
+ constructor(props: MyState) {
+ super(props);
+ this.state = { value: '' , clicked: false };
+ this.handleChange = this.handleChange.bind(this);
+ this.handleSubmit = this.handleSubmit.bind(this);
+ }
+
+ handleChange(event) {
+ this.setState({ value: event.target.value });
+ }
+
+ handleSubmit(event) {
+ alert('A name was submitted: ' + this.state.value);
+ this.setState({clicked: true});
+ event.preventDefault();
+ }
+
+ render() {
+ return (
+
+ );
+ }
+}
diff --git a/03 Tests samples/src/components/index.ts b/03 Tests samples/src/components/index.ts
index 1f29566..d260c22 100644
--- a/03 Tests samples/src/components/index.ts
+++ b/03 Tests samples/src/components/index.ts
@@ -1,11 +1,11 @@
import {MessageList} from './MessageList/MessageList';
import {MessageForm} from './MessageForm/MessageForm';
import {MessagesSection} from './MessagesSection/MessagesSection';
-
-
+import {NameForm} from './NameForm/NameForm';
export {
MessageList,
MessageForm,
MessagesSection,
+ NameForm,
};
\ No newline at end of file