Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Water - Kayla #42

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cb25293
Initial setup for wave 1
Kaylaj89 Jan 6, 2021
0b28b90
Filled in initial Submission form placeholders
Kaylaj89 Jan 6, 2021
2b37a7b
Renamed test file to work properly, added UseState to Playersubmissio…
Kaylaj89 Jan 6, 2021
dd0cb2c
Added values to each input so that react can identiy if an input item…
Kaylaj89 Jan 6, 2021
c5ac8af
Added an event handler + onChange value to each input field
Kaylaj89 Jan 6, 2021
d6a1afe
Changed newSubmission function name to 'newInput' to match overall se…
Kaylaj89 Jan 6, 2021
0333668
added package-lock.sjon to gitignore
Kaylaj89 Jan 6, 2021
b2f5552
Delete package-lock.json
Kaylaj89 Jan 6, 2021
4bab4ac
Dried up OnInputChange function
Kaylaj89 Jan 6, 2021
c775155
Merge branch 'master' of https://github.com/Kaylaj89/exquisite-react …
Kaylaj89 Jan 6, 2021
2f1d964
Dried up OnInputChange function
Kaylaj89 Jan 6, 2021
a9c8bf7
Working through Submit Line Logic
Kaylaj89 Jan 6, 2021
d711e43
Added onFormSubmitLIne logic to html
Kaylaj89 Jan 6, 2021
1900fc0
Added 'onsubmitcallback' function to playersubmissionform
Kaylaj89 Jan 6, 2021
85e29eb
Realized I was adding all my data incorrectly. Have to start over alm…
Kaylaj89 Jan 6, 2021
a612a28
Redoing project. Adding required props to PlayerSubmissionForm in Gam…
Kaylaj89 Jan 6, 2021
fb730c9
Having git issues
Kaylaj89 Jan 7, 2021
38757cc
Merge branch 'master' of https://github.com/Kaylaj89/exquisite-react …
Kaylaj89 Jan 7, 2021
6230f13
Git issues
Kaylaj89 Jan 7, 2021
44b3c82
Wave 1 finished with all tests passing
Kaylaj89 Jan 7, 2021
351ffa4
Added proptype info to Game.js for final poem, recent submissions...a…
Kaylaj89 Jan 7, 2021
cf296bf
Added test changes per Matt mcknett
Kaylaj89 Jan 8, 2021
769b5ac
Added callback feature to FinalPoem
Kaylaj89 Jan 8, 2021
36d10a9
Wave 1 and Wave 2 tests passing but final poem not printing to screen
Kaylaj89 Jan 8, 2021
47468f7
Wave 2 Finished, major refactoring so that data was passed between si…
Kaylaj89 Jan 8, 2021
546ab5b
changed PropType from input to fields to get rid of warning in console
Kaylaj89 Jan 8, 2021
10a366d
Most recent submission is correctly printing to screen
Kaylaj89 Jan 8, 2021
7ac67e2
Form fields not showing once Final Poem submitted
Kaylaj89 Jan 8, 2021
66c1988
Form fields now pink if empty
Kaylaj89 Jan 8, 2021
be70b30
All tests passing, deleted console.logs.
Kaylaj89 Jan 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ yarn-debug.log*
yarn-error.log*
.eslintcache

package-lock.jsonpackage-lock.json
15,279 changes: 0 additions & 15,279 deletions package-lock.json

This file was deleted.

40 changes: 28 additions & 12 deletions src/components/FinalPoem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,36 @@ import PropTypes from 'prop-types';
import './FinalPoem.css';

const FinalPoem = (props) => {
const printLines = props.submissions.map((submission,index) => {
return (
<p key={index}>{submission}</p>
)
});

return (
<div className="FinalPoem">
<section className="FinalPoem__poem">
<h3>Final Poem</h3>

</section>

<div className="FinalPoem__reveal-btn-container">
<input type="button" value="We are finished: Reveal the Poem" className="FinalPoem__reveal-btn" />
if (props.isSubmitted) {
return (
<div className="FinalPoem">
<section className="FinalPoem__poem">
<h3>Final Poem</h3>
{printLines}
</section>
</div>
</div>
);
}
);
} else {
return (
<div className="FinalPoem">
<div className="FinalPoem__reveal-btn-container">
<input
type="button"
value="We are finished: Reveal the Poem"
className="FinalPoem__reveal-btn"
onClick={props.revealPoem} />

</div>
</div>
);
}
};

FinalPoem.propTypes = {
isSubmitted: PropTypes.bool.isRequired,
Expand Down
2 changes: 1 addition & 1 deletion src/components/FinalPoem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import userEvent from '@testing-library/user-event';

import FinalPoem from './FinalPoem';

describe.skip('FinalPoem', () => {
describe('FinalPoem', () => {
describe('before the poem is finished', () => {
test('it renders with a button when isSubmitted is false', () => {
// Act
Expand Down
43 changes: 37 additions & 6 deletions src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,33 @@ import FinalPoem from './FinalPoem';
import RecentSubmission from './RecentSubmission';

const Game = () => {
const exampleFormat = FIELDS.map((field) => {
const [playerCount, setPlayerCount] = useState(1); //set count at 1
const [submissions, setSubmissions] = useState([]);
const [isSubmitted, setIsSubmitted] = useState(false);

const exampleFormat = FIELDS.map((field) => {
if (field.key) {
return field.placeholder;
} else {
return field;
}
}).join(' ');


const lineSubmission = (submission) => {
const newLineSubmission = [...submissions]
newLineSubmission.push(submission)

setSubmissions(newLineSubmission)
setPlayerCount(playerCount + 1)
}

const revealPoem = () => {
setIsSubmitted(true);
}

const revealLastSubmission = submissions[submissions.length - 1]

return (
<div className="Game">
<h2>Game</h2>
Expand All @@ -25,18 +44,30 @@ const Game = () => {
{ exampleFormat }
</p>

<RecentSubmission />
{ (!isSubmitted) ?
<PlayerSubmissionForm
index={playerCount}
sendSubmission={lineSubmission}
fields={FIELDS} />
: ''}

<PlayerSubmissionForm />
{(!isSubmitted && submissions.length > 0) ?
<RecentSubmission submission={revealLastSubmission}/>
: '' }

<FinalPoem />
<FinalPoem
isSubmitted={isSubmitted}
submissions={submissions}
revealPoem={revealPoem}
/>


</div>
);
}


const FIELDS = [
//ading export here per Matt Mcknett suggestion
export const FIELDS = [
'The',
{
key: 'adj1',
Expand Down
2 changes: 1 addition & 1 deletion src/components/Game.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const FIELDS = [

const INPUT_FIELDS = FIELDS.filter((element) => typeof element !== 'string');

describe.skip('Game', () => {
describe('Game', () => {

describe('Wave 1: Rendering Game', () => {

Expand Down
90 changes: 79 additions & 11 deletions src/components/PlayerSubmissionForm.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,92 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';

import './PlayerSubmissionForm.css';

const PlayerSubmissionForm = () => {
const PlayerSubmissionForm = (props) => {
//set form entries with initial empty values
const [entry, setEntry] = useState ({

adj1: '',
noun1: '',
adv: '',
verb: '',
adj2: '',
noun2: '',
})

const onEntryChange = (event) => {
const newEntryValues = {
...entry,
}
const {name, value} = event.target;

newEntryValues[name] = value;
setEntry(newEntryValues);
};


const onFormSubmit = (event) => {
event.preventDefault();

const poemData = props.fields.map(field => {
const submittedData = {...entry};
if (field.key) {
return submittedData[field.key];
} else {
return field;
}
}).join(' ');

props.sendSubmission(poemData);

//TODO: Should have found way to validate entries so that blank entries could not be submitted
// if (
// input.adj1 !== '' &&
// input.noun1 !== '' &&
// input.adverb !== '' &&
// input.verb !== '' &&
// input.adj2 !== '' &&
// input.noun2 !== ''
// ) {

setEntry({
adj1: '',
noun1: '',
adv: '',
verb: '',
adj2: '',
noun2: '',
});
}


return (
<div className="PlayerSubmissionForm">
<h3>Player Submission Form for Player #{ }</h3>
<h3>Player Submission Form for Player #{props.index }</h3>

<form className="PlayerSubmissionForm__form" >
<form
className="PlayerSubmissionForm__form" onSubmit={onFormSubmit}>

<div className="PlayerSubmissionForm__poem-inputs">

{
// Put your form inputs here... We've put in one below as an example
}
<input
placeholder="hm..."
type="text" />

props.fields.map((field, i) => {
if (field.key) {
return (
<input
key={field.key}
name={field.key}
placeholder={field.placeholder}
value={entry[field.key] || ''}
onChange={onEntryChange}
data-testid={field.key}
type="text"
className={entry[field.key] === '' ? 'PlayerSubmissionFormt__input--invalid' : ''}
/>)
} else {
return field;
}
})
}
</div>

<div className="PlayerSubmissionForm__submit">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,11 @@ import '@testing-library/jest-dom/extend-expect';
import { render, screen, cleanup } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import PlayerSubmissionForm from './PlayerSubmissionForm';
import { FIELDS } from './Game';


describe('Wave 1: PlayerSubmissionForm', () => {
// Arrange

const FIELDS = [
'The',
{
key: 'adj1',
placeholder: 'adjective1',
},
'Test',
{
key: 'noun1',
placeholder: 'noun1',
},
'Better',
{
key: 'verb1',
placeholder: 'verb1',
},
'Pass',
{
key: 'adverb1',
placeholder: 'adverb1',
},
];

test('renders with the proper input fields and a submit button', () => {
// Act
Expand All @@ -42,8 +21,8 @@ describe('Wave 1: PlayerSubmissionForm', () => {

// Assert
inputFields.forEach(field => {
const regex = new RegExp('^' + field.placeholder + '$', 'i');
const inputField = screen.getByPlaceholderText(regex);
const regex = new RegExp('^' + field.key + '$', 'i');
const inputField = screen.getByTestId(regex);
expect(inputField).toBeInTheDocument();
});
});
Expand All @@ -64,9 +43,8 @@ describe('Wave 1: PlayerSubmissionForm', () => {
// Assert
inputFields.forEach(async field => {
// Find the input field
const regex = new RegExp('^' + field.placeholder + '$', 'i');
const inputField = screen.getByPlaceholderText(regex)

const regex = new RegExp('^' + field.key + '$', 'i');
const inputField = screen.getByTestId(regex)
// Type in that input field
userEvent.type(inputField, letters.charAt(index));
// assert that the field now has the current letter
Expand Down
4 changes: 3 additions & 1 deletion src/components/RecentSubmission.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const RecentSubmission = (props) => {
return (
<div className="RecentSubmission">
<h3>The Most Recent Submission</h3>
<p className="RecentSubmission__submission">{ }</p>
<p className="RecentSubmission__submission">
{props.submission}
</p>
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/RecentSubmission.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { render, screen } from '@testing-library/react';
import RecentSubmission from './RecentSubmission';


describe.skip('Wave 2: RecentSubmission', () => {
describe('Wave 2: RecentSubmission', () => {
test('It renders with a submission and shows the text', () => {
// Act
render(<RecentSubmission submission={'This is a submission'} />);
Expand Down