Skip to content

Commit

Permalink
adapt server data
Browse files Browse the repository at this point in the history
  • Loading branch information
kalsmic committed Sep 13, 2023
1 parent c1abff6 commit 823da08
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 31 deletions.
31 changes: 15 additions & 16 deletions app/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import Route from '@ember/routing/route';

const COMMUNITY_CATEGORIES = ['Condo', 'TownHouse', 'Apartment'];

export default class IndexRoute extends Route {
async model() {
return {
title: 'Grand Old Mansion',
owner: 'Veruca Salt',
city: 'San Francisco',
location: {
lat: 37.7749,
lng: -122.4194,
},
category: 'Estate',
type: 'Standalone',
bedrooms: 15,
image:
'https://upload.wikimedia.org/wikipedia/commons/c/cb/Crane_estate_(5).jpg',
description:
'This grand old mansion sits on over 100 acres of rolling hills and dense redwood forests.',
};
let response = await fetch('/api/rentals.json');
let { data } = await response.json();
return data.map((model) => {
let { attributes } = model;
let type;
if (COMMUNITY_CATEGORIES.includes(attributes.category)){
type = 'Community';

} else {
type = 'Standalone';
}
return { type, ...attributes}
});
}
}
9 changes: 3 additions & 6 deletions app/templates/index.hbs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<Jumbo>
<h2>Welcome to Super Rentals!</h2>
<p>We hope you find exactly what you're looking for in a place to stay.</p>
<LinkTo @route="about" class="button">
About Us
</LinkTo>
</Jumbo>
<h1>{{@model.title}}</h1>
<div class="rentals">
<ul class="results">
<li><Rental @rental={{@model}}/></li>
<li><Rental @rental={{@model}}/></li>
<li><Rental @rental={{@model}}/></li>
{{#each @model as |rental|}}
<li><Rental @rental={{rental}} /></li>
{{/each}}
</ul>
</div>
1 change: 0 additions & 1 deletion app/templates/rental.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{{yield}}
<article class="rental">
<div class="details">
<h3>{{@rental.title}}</h3>
Expand Down
6 changes: 0 additions & 6 deletions tests/acceptance/super-rentals-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ module('Acceptance | super rentals', function (hooks) {
await visit('/');

assert.strictEqual(currentURL(), '/');
// assert.dom('nav').exists();
assert.dom('h2').hasText('Welcome to Super Rentals!');

assert.dom('.jumbo a.button').hasText('About Us');
await click('.jumbo a.button');

assert.strictEqual(currentURL(), '/about');
});

test('visiting /about', async function (assert) {
Expand Down
7 changes: 5 additions & 2 deletions tests/integration/components/nav-bar-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ module('Integration | Component | nav-bar', function (hooks) {
await click('nav a.menu-contact');
assert.strictEqual(currentURL(), '/getting-in-touch');

await click('nav a.menu-index');
assert.strictEqual(currentURL(), '/');
assert.dom('nav a.menu-index').hasText('SuperRentals');


await click('nav a.menu-about');
assert.strictEqual(currentURL(), '/about');
});
});

0 comments on commit 823da08

Please sign in to comment.