From 86154cb831120e8c264215c0f8bcd57b1227b41a Mon Sep 17 00:00:00 2001 From: Stephanie Frankian Date: Mon, 28 May 2018 08:03:09 -0400 Subject: [PATCH] #3 added person profile page. Still need to add links to related resources --- cypress/integration/home_spec.js | 17 +++++ src/components/Person.vue | 113 ++++++++++++++++++------------- src/store/people.js | 20 +++++- 3 files changed, 99 insertions(+), 51 deletions(-) diff --git a/cypress/integration/home_spec.js b/cypress/integration/home_spec.js index fd8385bf..092547a6 100644 --- a/cypress/integration/home_spec.js +++ b/cypress/integration/home_spec.js @@ -3,3 +3,20 @@ describe('Home', () => { cy.visit('/') }) }) +describe('PageNotFound', () => { + it('should load error page', () => { + cy.visit('/#/thisisnotavalidpath') + }) +}) + +describe('People', () => { + it('should load', () => { + cy.visit('/#/people/1') + }) +}) + +describe('People', () => { + it('should flash notification banner', () => { + cy.visit('/#/people/234234') + }) +}) diff --git a/src/components/Person.vue b/src/components/Person.vue index dfcc5372..1617b8e6 100644 --- a/src/components/Person.vue +++ b/src/components/Person.vue @@ -1,64 +1,81 @@ diff --git a/src/store/people.js b/src/store/people.js index 4990ac1b..1adfb780 100644 --- a/src/store/people.js +++ b/src/store/people.js @@ -23,6 +23,7 @@ export default { const { results } = await response.json() if (response.ok) { // If the response is OK commit the data to the store. + console.log('RESULTS: ' + results) commit('results', results) } else { // If the response is not OK, log the response to the console. @@ -31,17 +32,30 @@ export default { }, async getPerson ({ commit }, id) { // Fetch People from SWAPI and await the response. - const apiUrl = 'https://swapi.co/api/people/' + const apiUrl = 'https://swapi.co/api/people/' + id return new Promise((resolve, reject) => { - fetch(apiUrl + id) + fetch(apiUrl) .then(function (response) { - resolve(response) + if (response.ok) { + response.json() + .then(results => { + console.log({results}) + commit('results', results) + resolve(response) + }) + } }) .catch(function (error) { reject(error) }) }) } + }, + getters: { + getResults: state => { + console.log(state.results) + return state.results + } } }