Skip to content
Snippets Groups Projects
Commit 35005a99 authored by hudaal's avatar hudaal
Browse files

Added comment test, but it's not working well yet

parent 4390d429
Branches Add_other_tests
No related tags found
1 merge request!2Suggestions in search
/// <reference types="cypress" />
import {Filter, Search} from "../../src/actions/Actions";
import {filter_type, sort_type} from "../../src/components/Navbar/FilterSortTypes";
import {Search} from "../../src/actions/Actions";
describe("SearchChecking", () => {
......
import React from 'react';
import { render, cleanup, waitForElementToBeRemoved} from '@testing-library/react';
import userEvent from '@testing-library/user-event'
import '@testing-library/jest-dom/extend-expect';
import {Provider, useSelector} from "react-redux";
import {applyMiddleware, createStore} from "redux";
import {rootReducer, RootState} from "../reducers/rootReducer";
import thunk from "redux-thunk";
import Article from "../components/Article/Article";
const myStore = createStore(rootReducer, applyMiddleware(thunk));
function ArticleDummyWrapper() {
const search_results = useSelector((state: RootState) => state.search)
return (
<div>
<Article searchQuery={search_results}/>
</div>
);
}
afterEach(() => {
cleanup();
})
beforeEach(() => {
jest.useFakeTimers();
})
it('Add comment test', async () => {
const { getByPlaceholderText, getByTestId, getByText, asFragment } = render(<><Provider store={myStore}><ArticleDummyWrapper/></Provider></>, 10000);
await waitForElementToBeRemoved(() => getByPlaceholderText("Add your comment .."));
await userEvent.type(getByPlaceholderText("Add your comment .."), 'test comment jest')
await userEvent.click(getByTestId("comment-button"));
expect(getByTestId("comments")).toHaveValue("test comment jest");
expect(asFragment()).toMatchSnapshot();
});
......@@ -64,11 +64,12 @@ class CommentInput extends React.Component<CommentProps , CommentState> {
<form>
<div>
{this.props.article.commentConnection.map((comment: any, i: number) =>
<p key={i} className={'comments'}> {comment.text}</p>
<p key={i} data-testid={"comments"} className={'comments'}> {comment.text}</p>
)}
<input type={"text"} id={"comment-input"} name={"comment"} value={this.state.value}
onChange={this.handleChange}/>
<button type={'submit'} className={'add-comment-btn'} onClick={(event) => {
data-testid={"comment-input"} placeholder={"Add your comment .."} onChange={this.handleChange}/>
<button type={'submit'} className={'add-comment-btn'} data-testid={"comment-button"}
onClick={(event) => {
this.handleSubmit(event);
this.setState({value: ""})
}}>Add comment
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment