Skip to content

coder36/fivedays

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

5 day forecast

"Build a single HTML page displaying the 5 day weather forecast for a location of your choice."

My Solution

I developed the app primarily for a mobile phone display, though it looks great on a desktop:

On a desktop you get the added benefit of tooltips. Hovering over the wind icon, will give you the wind direction. Hovering over a weather image will give you a worded description.

Technology stack

Building

Assuming node 6.5.0

npm install
npm start

This will start up the app in development mode. Navigate to http://localhost:3000

Testing with Jest

Using Jest:

CI=true npm test -- --coverage

You can launch Jest in watch mode which is great during development:

npm test

Testing with Cucumber

Assuming ruby 2.2.3 and chromedriver are installed

Start up server in cucumber mode:

npm run start_in_cucumber_mode

In another shell run cucumber

cd cucumber
bundle install
cucumber

It also supports running in a headless browser. Assummg Phantomjs is installed:

cucumber browser=phantom

Deployment

  heroku create fivedays --buildpack https://github.com/mars/create-react-app-buildpack.git
  git push heroku master

In static.json I've set the static assets to be cached in the browser using the max-age cache-control setting. Since I expect the final javascript minified file to be over 100K, this will make a great optimisation - on a slow internet connection ie. 3g there would otherwise be a visible delay whilst downloading the assets. For continous deployments, need to make sure the static assets have a unique name - create-react-app does this for us by appending a hash (awesome!).

To get an idea of the size of the production javascript bundle run:

npm run build

If I had more time...

Test and code for error conditions

What would happen if the openweatherapi end point was unavailable ? At the moment you would just get a blank page. Also Jest (the test framework I used) kind of assumes your react components are pure functions with no side effects. Given that I've used the ES6 fetch api with Promises, means that I would have to find some other way to test this (I would probably do it as a cucumber with mirage test).

Caching

The openweather api says that the api should only be called every 10 minutes. My code does not enforce this. A really simple/fudge would be to create an express server endpoint which proxies the call to the openweather api adding in a cache-control header setting the max-age to 10 minutes. Crude, but it would be an immediate win.

GraphQL

The openweather api could be exposed as a graphql end point. Not really appropriate for this exercise, but for a bigger app I would absolutely consider using GraphQL over REST.

Cucumber / BDD

I would create a set of cucumber tests as I think the gherkin BDD approach better documents the way end users would see and use the system. It would also allow me to tie business value to my design decisions. Implementation wise, I would use Ruby/Capybara/Selenium to write the tests as it seems to work really well with react. Mirage is a great way to programatically mock REST endpoints within the cucumber stepdefs.

Enivonment configuration

I've hard coded the openweather api url into the code. This could be externalised and injected at deployment time. create-react-app has a really nice way to allow environment variables to be embedded into the react code.

Search for location

A nice feature would be the ability to search for a location. At the moment its hardcoded to Newcastle.

Notes

  • Only tested on the chrome browser.

About

5 day weather forecast using Open Weather Map API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published