Code Monkey home page Code Monkey logo

building-forms-lab's Introduction

Set List Lab

Objectives

  1. Use forms to create new elements and update the store.
  2. Display a list of the new elements in a separate component.

Overview

Guess what - the bands are back! What we want is an application that allows us to add band names, and then have those band names instantly rendered below. We need to be incorporating Redux by dispatching actions and updating the store each time someone submits a new band.

So we will be creating two different React components, and each of them needs to have access to our Redux store, either directly or through props. One of the components will be a form where we input our band name, and the other component will display the list of bands.

The createStore method and some basic setup have already been implemented for you.

Instructions

  1. You will need to write the BandsContainer component. This component should act as your connection to the Redux store and should be a child of the App component. Any values we want to use from Redux as well as any actions we want to dispatch should be set up and available in BandsContainer so they can be passed down to other components.

  2. You will need to write the BandInput component as a child of BandsContainer. This component should have a form with a text input and submit button. We would like to update this component's state each time the user types a new character in the input, stored as this.state.name. We will only update the Redux store's state when the user hits the submit button. The dispatched action required to initiate this update should be set up in BandsContainer and passed down as the prop addBand to BandInput.

  3. You will also need to fill in the manageBand reducer located under ./src/reducers/manageBand.js. It will need to respond to an action of type 'ADD_BAND' and correspondingly concatenate a new band into the bands array each time the action is dispatched. Each band in the array should be an object with a name key.

  4. Once you've got a form successfully dispatching actions and adding bands to your Redux store, write the necessary code to display each band name from the store. Band names should be listed in individual li elements.

building-forms-lab's People

Contributors

aturkewi avatar curiositypaths avatar dependabot[bot] avatar howardbdev avatar ihollander avatar jeffkatzy avatar kwebster2 avatar lizbur10 avatar lukeghenco avatar maxwellbenton avatar nikymorg avatar rrcobb avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

building-forms-lab's Issues

test does not change input value

I changed test/index-test.js

In the test starting on line 72 i modified this line:

input.simulate('change', { target: { name: "name", value: 'Hello' } })

full code below:

it('updates the store when a form is submitted', () => {
const store = createStore(manageBand)

let spy = sinon.spy(store, "dispatch")

const wrapper = mount(<Provider store={store}><App /></Provider>)

expect(wrapper.find('input').length > 0, "No input elements found in the application").to.equal(true)
let input = wrapper.find('input').first()

let form = wrapper.find('form')

expect(store.getState().bands, "'bands' not found in the store").to.exist
expect(store.getState().bands, "Initial state of 'bands' should be an empty array").to.be.empty

input.simulate('change', { target: { **name: "name"**, value: 'Hello' } })

form.simulate('submit',  { preventDefault() {} })

expect(store.getState().bands[0].name).to.equal("Hello")

});

Solution Fails Test 6

The solution does not pass test 6 "bandsComponent is a child of the app component".

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.
     
TypeError: Cannot read property 'contextTypes' of undefined

Error while running 'learn' and 'npm test'

@Lukeghenco @aturkewi
I was having issues with npm test hanging. I didn't think much about it and finished the lab and just ctrl + c until all the test were passing. As you can see here:

screen shot 2017-02-24 at 1 06 31 pm

In the top left tab - it is showing the running process icon which is currently hanging, however all the test passed.

When i ran 'learn' for it to update on the site i got this error.

screen shot 2017-02-24 at 1 07 05 pm

It was stating that document was not defined.

My theory is perhaps the file structure of the lab? I noticed that in the "root" directory. Index.html is defined. But the index.js in src, would it be able to reference the dom that way? With it not being in the root of src?

screen shot 2017-02-24 at 1 07 19 pm

Just curious. I'm going to go ahead and submit this lab. But wanted to give an update that this lab may be broken as far as running the test goes.

Objects not Strings

This lab tests for strings as opposed to objects. This is confusing, as documentation and lessons have you passing objects in state, and seems like for consistency's sake, this should happen here as well. The next lab goes right back to using objects...

BandInput tests appear to be broken

As written, the BandInput tests that use const wrapper = shallow(<BandInput />) throw an "Invariant Violation: could not find 'store' in either the context or the props...." error. When corrected by passing in the store as a prop, they still don't work -- apparently because you gotta .dive() to get down past the Redux connect() wrapper and into the component (HOCs and .dive())

This works:

    const store = createStore(manageBand)
    const wrapper = shallow(<BandInput store={store} />).dive()

Test descriptions

The second test displays the following upon failure: BandInput has an initial state with text key set to empty string, but the tests are looking for a name key, not a text key.

Test 3 Not Working Correctly

According to the test, "changes the state on a keydown" yet
<input type='text' onKeyDown={(event) => this.handleChange(event)} /> fails
and
<input type='text' onChange={(event) => this.handleChange(event)} /> passes.

User should supply the reducer

According to the Readme the user should be creating the reducer. Do you want to remove some of it to allow for that?

You will also need to fill in the manageBand reducer located under ./src/reducers/manageBand.js. It will need to respond to an action of type 'ADD_BAND' and correspondingly concatenate a new band each time the action is dispatched.

Known Issues

Problem: This lab has tests that pass based on a specific component structure. As Redux removes the need for a particular component structure for passing props, there may be multiple 'valid' component structures for this lab, but only one structure that passes tests as they are currently written. #14

Solution: Either add tests to enforce specific component parent/child structure or modify tests to be open ended on how students can structure the given components

Invariant Violation: Objects are not valid as a React child

The tests contain objects and not an array of strings. That is trying to be submitted to the store. So some of the tests cannot be passed.

One in particular is...

Bands Container
renders each li with the correct name:
Invariant Violation: Objects are not valid as a React child (found: object with keys {name}). If you meant to render a collection of children, use an array instead.

Grammar error

Change: "So we will be creating two different React components each of them need to connect to our Redux store."

To: "So we will be creating two different React components**, and** each of them need to connect to our Redux store.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.