From 3ef51afaebccfe97028252f823cb6dcc654abc0c Mon Sep 17 00:00:00 2001 From: Anan Wolf Date: Sat, 19 Jun 2021 12:39:31 -0700 Subject: [PATCH 1/2] Testing suite for Q&A complete --- client/src/QA/QAcomponents/AddQuestion.jsx | 32 ++++---- client/src/QA/Test /QAcomponents.test.js | 88 ++++++++++++++++------ client/src/QA/Test /sampleData.js | 2 + 3 files changed, 86 insertions(+), 36 deletions(-) diff --git a/client/src/QA/QAcomponents/AddQuestion.jsx b/client/src/QA/QAcomponents/AddQuestion.jsx index 814d41b..d1c35c2 100644 --- a/client/src/QA/QAcomponents/AddQuestion.jsx +++ b/client/src/QA/QAcomponents/AddQuestion.jsx @@ -12,7 +12,7 @@ const AddQuestion = ({ productId, handleModalClose, openModal, prodName }) => { }; const regexVerifyEmail = (email) => { - const characterTest = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + const characterTest = /^(([^<>()[\]\\.,;:\s@']+(\.[^<>()[\]\\.,;:\s@']+)*)|('.+'))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return characterTest.test(email); }; @@ -31,7 +31,9 @@ const AddQuestion = ({ productId, handleModalClose, openModal, prodName }) => { body: questionBody, name: name, email: email, + /* eslint-disable */ product_id: productId + /* eslint-enable */ }) .then((response) => { console.log('succesful question post', response.data); @@ -66,11 +68,11 @@ const AddQuestion = ({ productId, handleModalClose, openModal, prodName }) => { { dataFill(event); }} - placeholder="Example: jack@email.com" - type="email" + placeholder='Example: jack@email.com' + type='email' name='email' - maxLength="60" - autoComplete="off" + maxLength='60' + autoComplete='off' value={email} required > @@ -83,11 +85,11 @@ const AddQuestion = ({ productId, handleModalClose, openModal, prodName }) => { { dataFill(event); }} - placeholder="Examples: jackson11!" - type="text" + placeholder='Examples: jackson11!' + type='text' name='name' - maxLength="60" - autoComplete="off" + maxLength='60' + autoComplete='off' value={name} required > @@ -100,12 +102,12 @@ const AddQuestion = ({ productId, handleModalClose, openModal, prodName }) => { diff --git a/client/src/QA/Test /QAcomponents.test.js b/client/src/QA/Test /QAcomponents.test.js index 8b47d1c..f7e4c2b 100644 --- a/client/src/QA/Test /QAcomponents.test.js +++ b/client/src/QA/Test /QAcomponents.test.js @@ -17,6 +17,7 @@ it ('render Q&A Search without crashing', () => { const div = document.createElement('div'); ReactDOM.render(, div); }); + // npm test -- -t 'render Question List without crashing' it ('render Question List without crashing', () => { const div = document.createElement('div'); @@ -25,11 +26,13 @@ it ('render Question List without crashing', () => { searchInput={null} productId={13023}/>, div); }); + // npm test -- -t 'render Add Question Button Modal crashing' it ('render Add Question Button Modal crashing', () => { const div = document.createElement('div'); ReactDOM.render(, div); }); + // npm test -- -t 'render Answer Helpfulness without crashing' it ('render Answer Helpfulness without crashing', () => { const div = document.createElement('div'); @@ -39,6 +42,7 @@ it ('render Answer Helpfulness without crashing', () => { answerDate={'2018-08-18T00:00:00.000Z'} answerName={sample.questions.results[0].answers.answerer_name}/>, div); }); + // npm test -- -t 'render Answer Photos without crashing' it ('render Answer Photos without crashing', () => { const div = document.createElement('div'); @@ -46,34 +50,76 @@ it ('render Answer Photos without crashing', () => { photo={'urlplaceholder/answer_5_photo_number_1.jpg'} key={1}/>, div); }); + // npm test -- -t 'render Answer List without crashing' it ('render Answer List without crashing', () => { const div = document.createElement('div'); ReactDOM.render(, div); + id: 1992060, + photos: [{ + 'id': 1, + 'url': 'urlplaceholder/answer_5_photo_number_1.jpg' + }] + } + }/>, div); }); -// it ('render More Answer button without crashing', () => { -// const div = document.createElement('div'); -// ReactDOM.render(, div); -// }); +// npm test -- -t 'render More Answer button without crashing' +it ('render More Answer button without crashing', () => { + const div = document.createElement('div'); + ReactDOM.render(, div); +}); -// it ('render Individual Questions without crashing', () => { -// const div = document.createElement('div'); -// ReactDOM.render(, div); -// }); +// npm test -- -t 'render Individual Questions without crashing' +it ('render Individual Questions without crashing', () => { + const div = document.createElement('div'); + ReactDOM.render(, div); +}); -// it ('render Question Helpfulness section without crashing', () => { -// const div = document.createElement('div'); -// ReactDOM.render(, div); -// }); +// npm test -- -t 'render Question Helpfulness section without crashing' +it ('render Question Helpfulness section without crashing', () => { + const div = document.createElement('div'); + ReactDOM.render(, div); +}); diff --git a/client/src/QA/Test /sampleData.js b/client/src/QA/Test /sampleData.js index f9a24c0..7d0433e 100644 --- a/client/src/QA/Test /sampleData.js +++ b/client/src/QA/Test /sampleData.js @@ -1,3 +1,4 @@ +/* eslint-disable */ var sample = { "questions": { "product_id": "5", @@ -83,6 +84,7 @@ var sample = { ] } }; +/* eslint-enable */ module.exports = sample; \ No newline at end of file From 92457fee776c8e57cbe7278a77c642a7a1a121b9 Mon Sep 17 00:00:00 2001 From: Anan Wolf Date: Sat, 19 Jun 2021 15:22:35 -0700 Subject: [PATCH 2/2] testing fixed and some cleanup --- client/dist/styles.css | 8 +- client/src/QA/QAcomponents/AddQuestion.jsx | 2 +- client/src/QA/QAcomponents/AnswerHelpful.jsx | 2 +- client/src/QA/QAcomponents/AnswerPhotos.jsx | 2 +- client/src/QA/QAcomponents/Answers.jsx | 2 +- client/src/QA/QAcomponents/MoreAnswers.jsx | 2 +- client/src/QA/QAcomponents/MoreQuestions.jsx | 2 +- client/src/QA/QAcomponents/Question.jsx | 2 +- .../src/QA/QAcomponents/QuestionHelpful.jsx | 8 +- client/src/QA/QAcomponents/QuestionList.jsx | 2 +- client/src/QA/QAcomponents/Search.jsx | 2 +- client/src/QA/Test /QAcomponents.test.js | 96 ++++++++++++------- 12 files changed, 78 insertions(+), 52 deletions(-) diff --git a/client/dist/styles.css b/client/dist/styles.css index 1be02e5..efbde70 100644 --- a/client/dist/styles.css +++ b/client/dist/styles.css @@ -548,9 +548,15 @@ input:checked+.slider:before { margin-top: 20px; border-bottom: solid grey 2px; } + +.question-helpful-div { + display: inline-flex; + flex-direction: row; + font-size: 15px; +} /* .question-list { width: auto; - height: 40vh; + height: 50vh; overflow-y: scroll; } */ .question-control { diff --git a/client/src/QA/QAcomponents/AddQuestion.jsx b/client/src/QA/QAcomponents/AddQuestion.jsx index d1c35c2..b762781 100644 --- a/client/src/QA/QAcomponents/AddQuestion.jsx +++ b/client/src/QA/QAcomponents/AddQuestion.jsx @@ -45,7 +45,7 @@ const AddQuestion = ({ productId, handleModalClose, openModal, prodName }) => { : null; }; const QuestionModalForm = ( -
selectModal(event)} > diff --git a/client/src/QA/QAcomponents/AnswerHelpful.jsx b/client/src/QA/QAcomponents/AnswerHelpful.jsx index ea42b64..50a35ab 100644 --- a/client/src/QA/QAcomponents/AnswerHelpful.jsx +++ b/client/src/QA/QAcomponents/AnswerHelpful.jsx @@ -33,7 +33,7 @@ const AnswerHelpful = ({ answerHelpfulness, answerDate, answerId, answerName }) : null; }; return ( -
+
<>by {answerName}, {convertDate(answerDate)} |  Helpful? 

{ ); return ( -

+
( -
+
A: {answer.body}
{answer.photos.length ? answer.photos.map((photo, id) => ( diff --git a/client/src/QA/QAcomponents/MoreAnswers.jsx b/client/src/QA/QAcomponents/MoreAnswers.jsx index afef56f..f7ea939 100644 --- a/client/src/QA/QAcomponents/MoreAnswers.jsx +++ b/client/src/QA/QAcomponents/MoreAnswers.jsx @@ -5,7 +5,7 @@ const MoreAnswers = ({ answer, answerList }) => { const [collapseAnswers, setCollapseAnswers] = useState(true); return ( -
+
{ collapseAnswers ? <> diff --git a/client/src/QA/QAcomponents/MoreQuestions.jsx b/client/src/QA/QAcomponents/MoreQuestions.jsx index 018feda..00b7cbe 100644 --- a/client/src/QA/QAcomponents/MoreQuestions.jsx +++ b/client/src/QA/QAcomponents/MoreQuestions.jsx @@ -5,7 +5,7 @@ const MoreQuestions = ({ questions }) => { const [collapseQuestions, setCollapseQuestions] = useState(true); return ( -
+
{ collapseQuestions ? <> diff --git a/client/src/QA/QAcomponents/Question.jsx b/client/src/QA/QAcomponents/Question.jsx index 9a1f50d..8e65d08 100644 --- a/client/src/QA/QAcomponents/Question.jsx +++ b/client/src/QA/QAcomponents/Question.jsx @@ -8,7 +8,7 @@ const Question = ({ question, productId }) => { let answerList = answerKey.map(Ans => question.answers[Ans]); return ( -
+
Q: {question.question_body} -
-
); return ( -
+
Helpful? 

( -

+
{ searchInput === null ? diff --git a/client/src/QA/QAcomponents/Search.jsx b/client/src/QA/QAcomponents/Search.jsx index 6d66a28..5661e9f 100644 --- a/client/src/QA/QAcomponents/Search.jsx +++ b/client/src/QA/QAcomponents/Search.jsx @@ -9,7 +9,7 @@ const Search = ({ handleSearch, searchInput }) => { }; return ( -
+
{ + cleanup(); +}); // npm test -- -t 'render Q&A Search without crashing' -it ('render Q&A Search without crashing', () => { - const div = document.createElement('div'); - ReactDOM.render(, div); +test ('render Q&A Search without crashing', () => { + render(); + const searchElement = screen.getByTestId('search-test'); + expect(searchElement).toBeInTheDocument(); }); // npm test -- -t 'render Question List without crashing' -it ('render Question List without crashing', () => { - const div = document.createElement('div'); - ReactDOM.render( { + render(, div); + productId={13023}/>); + const questionListElement = screen.getByTestId('qa-list-test'); + expect(questionListElement).toBeInTheDocument(); }); // npm test -- -t 'render Add Question Button Modal crashing' -it ('render Add Question Button Modal crashing', () => { - const div = document.createElement('div'); - ReactDOM.render(, div); +test ('render Add Question Button Modal crashing', () => { + render(); + const addQuestionElement = screen.getByTestId('add-question-test'); + expect(addQuestionElement).toBeInTheDocument(); }); // npm test -- -t 'render Answer Helpfulness without crashing' -it ('render Answer Helpfulness without crashing', () => { - const div = document.createElement('div'); - ReactDOM.render( { + render(, div); + answerName={sample.questions.results[0].answers.answerer_name}/>); + const answerHelpfulElement = screen.getByTestId('answer-helpful-test'); + expect(answerHelpfulElement).toBeInTheDocument(); }); // npm test -- -t 'render Answer Photos without crashing' -it ('render Answer Photos without crashing', () => { - const div = document.createElement('div'); - ReactDOM.render( { + render(, div); + key={1}/>); + const answerPhotosElement = screen.getByTestId('answer-photo-test'); + expect(answerPhotosElement).toBeInTheDocument(); }); // npm test -- -t 'render Answer List without crashing' -it ('render Answer List without crashing', () => { - const div = document.createElement('div'); - ReactDOM.render( { + render( { 'url': 'urlplaceholder/answer_5_photo_number_1.jpg' }] } - }/>, div); + }/>); + const answerListElement = screen.getByTestId('answer-list-test'); + expect(answerListElement).toBeInTheDocument(); }); // npm test -- -t 'render More Answer button without crashing' -it ('render More Answer button without crashing', () => { - const div = document.createElement('div'); - ReactDOM.render( { + render( { 'id': 1, 'url': 'urlplaceholder/answer_5_photo_number_1.jpg' }] - }}/>, div); + }}/>); + const moreAnswersElement = screen.getByTestId('more-answer-test'); + expect(moreAnswersElement).toBeInTheDocument(); }); // npm test -- -t 'render Individual Questions without crashing' -it ('render Individual Questions without crashing', () => { - const div = document.createElement('div'); - ReactDOM.render( { + render(, div); + key={sample.questions.results[0].question_id}/>); + const individualQuestionElement = screen.getByTestId('individual-question-test'); + expect(individualQuestionElement).toBeInTheDocument(); }); // npm test -- -t 'render Question Helpfulness section without crashing' -it ('render Question Helpfulness section without crashing', () => { - const div = document.createElement('div'); - ReactDOM.render( { + render(, div); + questionId={sample.questions.results[0].question_id}/>); + const questionHelpfulElement = screen.getByTestId('question-helpful-test'); + expect(questionHelpfulElement).toBeInTheDocument(); }); + +// npm test -- -t 'render More Questions without crashing' +test ('render More Questions without crashing', () => { + render(); + const moreQuestionsElement = screen.getByTestId('more-questions-test'); + expect(moreQuestionsElement).toBeInTheDocument(); +}); \ No newline at end of file