Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13,669 changes: 13,669 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"version": "0.1.0",
"private": true,
"devDependencies": {
"enzyme": "^3.6.0",
"enzyme-adapter-react-16": "^1.5.0",
"react-scripts": "1.1.0"
},
"dependencies": {
Expand Down
26 changes: 25 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
import React, { Component } from 'react';
import './App.css';
import CardContainer from './CardContainer'
import DistrictRepository from './helper';
import kinderData from './data/kindergartners_in_full_day_program.js';



class App extends Component {
constructor() {
super()

this.state = {
districts: []
}
}

componentDidMount = () => {
const districts = new DistrictRepository(kinderData)
const districtData = districts.findAllMatches()

this.setState({
districts: districtData
})
}

render() {
return (
<div>Welcome To Headcount 2.0</div>
<div>
<CardContainer districts={this.state.districts}/>
</div>
);
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/CardContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import DistrictCard from './DistrictCard';
// import './CardContainer.css'

const CardContainer = (props) => {
const cards = props.districts.map(district => {
return (<DistrictCard district={district.location}
stats={district.stats}
key={district.location}/>)
})

return(
<div>
{ cards }
</div>
)
}

export default CardContainer;
12 changes: 12 additions & 0 deletions src/DistrictCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';


const DistrictCard = (props) => {
return (
<div>
<p>I'm a card</p>
</div>
)
}

export default DistrictCard;
47 changes: 46 additions & 1 deletion src/helper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
export default class DistrictRepository {
class DistrictRepository {
constructor(data) {
this.stats = this.sanitizeData(data);
}

sanitizeData = (data) => {
return data.reduce((schoolData, school) => {
const upperLocation = school.Location.toUpperCase();
const data = (parseFloat(parseFloat(school.Data).toFixed(3)))

if (!Object.keys(schoolData).includes(upperLocation)) {
schoolData[upperLocation] = { data: {[school.TimeFrame]: data || 0}};
} else {
schoolData[upperLocation].data[school.TimeFrame] = data || 0;
}
return schoolData;
}, {})
}

findByName = (name) => {
if (name) {
const upperName = name.toUpperCase();

if (this.stats[upperName]) {
const foundSchoolData = this.stats[upperName];
const result = {location: upperName, stats: foundSchoolData.data}
return result;
} else {
return undefined;
}
}
}

findAllMatches = (query) => {
if(!query) {
return Object.keys(this.stats).map(key => {
return {location: key, stats: this.stats[key]};
})
} else {
const upperQuery = query.toUpperCase();

return Object.keys(this.stats).filter(key =>
key.includes(upperQuery));
}
}
}

export default DistrictRepository;
3 changes: 1 addition & 2 deletions src/test/unit/iteration-0.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ describe('DistrictRepository iteration 0', () => {
// expect(district.stats.length).toBe(181);
expect(Object.keys(district.stats).length).toBe(181);
});

});
});
4 changes: 2 additions & 2 deletions src/test/unit/iteration-1-part2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe('DistrictRepository iteration 1 - part 2', () => {
const district = new DistrictRepository(kinderData);

test('findAllMatches defaults to returning all data in an array', () => {
// console.log(district.stats)
expect(district.findAllMatches().length).toBe(181);
});

Expand All @@ -17,5 +18,4 @@ describe('DistrictRepository iteration 1 - part 2', () => {
expect(district.findAllMatches('packers').length).toBe(0);
expect(district.findAllMatches('df').length).toBe(0);
});

});
});
23 changes: 23 additions & 0 deletions src/test/unit/iteration-2.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { shallow } from 'enzyme';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
Enzyme.configure({ adapter: new Adapter() });
import CardContainer from '../../CardContainer'

describe('CardContainer iteration 2', () => {

// test('should have 181 district cards initially', () => {
// const wrapper = shallow(<CardContainer />);

// expect(wrapper).toMatchSnapshot();
// });

test('should have a default state', () => {
const wrapper = shallow(<CardContainer />)
const expected = { cards: [] }

expect(wrapper.state()).toEqual(expected);
})
})
Empty file.
1 change: 1 addition & 0 deletions src/test/unit/iteration-4.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('DistrictRepository iteration 0', () => {
test('compareDistrictAverages ACADEMY 20 against Colorado', () => {
const result = { "ACADEMY 20": 0.407, "COLORADO": 0.53, "compared": 0.768}
expect(district.compareDistrictAverages('ACADEMY 20', 'Colorado')).toEqual(result);
// avg1 / avg2
});

});
Empty file.