In this exercise, you will implement the home view for the MEAN retail
application, the first view that the user will see when they visit your
site. The view contains a single search bar that searches for products by
text, that is, using the /api/v1/product/text/:query
REST API endpoint.
You will primarily be concerned with writing code that passes the mocha tests
specified in the test.js
file. You will not need to actually run your
code in the browser, you will instead use gulp and karma to run your
tests. The tests in test.js
will provide you faster feedback, and
also will provide you an exact specification for what you need to do to complete
this exercise.
In order to run tests, you should:
Inside server folder:
- Copy your completed
config.json
from the Chapter 3 homework assignment - Run
mongorestore
- Run
npm install
- Run
node index.js
Inside assessment folder:
- Run
npm install
in the provided sample code - Start gulp using
./node_modules/gulp/bin/gulp.js watch
- Start karma using
./node_modules/karma/bin/karma start ./karma.local.conf.js
- You should take a look at the tests in
test.js
to see exactly what your AngularJS code should do. - Modify
controllers.js
andtemplates/search_bar.html
as described below until the tests pass and karma gives you the below output:
LOG: 'Tests Succeeded! Copy/paste the below code to complete this assignment:'
LOG: '<secret code here>'
Chrome 43.0.2357 (Linux): Executed 4 of 4 SUCCESS (0.21 secs / 0.126 secs)
To visit the app open http://localhost:3000/assessment/
using the browser.
Here's what you need to do with controllers.js
and
templates/search_bar.html
to complete this assignment.
- You will have to modify
SearchBarController
incontrollers.js
to fill out theupdate()
function, which will make an HTTP request to the server and expose the server's response to your HTML. - You will have to modify the HTML in
templates/search_bar.html
to add an input field with class 'search-bar-input' that has a two-way data binding to thesearchText
variable, and calls theupdate()
function using the ngChange directive. You will also need tongRepeat
a div element with class 'autocomplete-result' for each search result.