Skip to content

Commit

Permalink
feat(client): add single locations page
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlatz committed May 2, 2024
1 parent f7a732e commit 1a03eb8
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 15 deletions.
1 change: 1 addition & 0 deletions client/app/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Router.map(function () {
});
this.route('locations', function () {
this.route('list', { path: '/' });
this.route('get', { path: '/:id' });
});
this.route('about');

Expand Down
11 changes: 11 additions & 0 deletions client/app/routes/locations/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Route from '@ember/routing/route';
import { service } from '@ember/service';
import type Store from '@ember-data/store';

export default class LocationGetRoute extends Route {
@service declare store: Store;

model(params: { id: number }) {
return this.store.findRecord('location', params.id);
}
}
10 changes: 10 additions & 0 deletions client/app/templates/locations/get.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{page-title @model.name " · Locations"}}

<h2>{{ @model.name }}</h2>

<dl>
<dt id="current-position">Current position</dt>
<dd aria-labelledby="current-position">
<Position @position={{@model.position}} />
</dd>
</dl>
4 changes: 3 additions & 1 deletion client/app/templates/locations/list.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
{{#each @model as |location| }}
<tr>
<td>
{{location.name}}
<LinkTo @route="locations.get" @model={{location}}>
{{location.name}}
</LinkTo>
</td>
<td>
<Position @position={{location.position}} />
Expand Down
52 changes: 38 additions & 14 deletions client/tests/acceptance/locations-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { module, test } from 'qunit';
import { visit } from '@1024pix/ember-testing-library';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { click } from '@ember/test-helpers';
import 'qunit-dom';

import { setupApplicationTest } from 'sokown-client/tests/helpers';
Expand All @@ -9,20 +10,43 @@ module('Acceptance | locations', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);

test('it displays locations list', async function (assert) {
// when
const screen = await visit('/locations');
module('visiting /locations/', function () {
test('it displays locations list', async function (assert) {
// when
const screen = await visit('/locations');

// then
assert
.dom(
screen.getByRole('heading', {
name: 'Locations',
level: 2,
}),
)
.exists();
assert.dom(screen.getByRole('cell', { name: 'Earth' })).exists();
assert.dom(screen.getByRole('cell', { name: 'Moon' })).exists();
// then
assert
.dom(
screen.getByRole('heading', {
name: 'Locations',
level: 2,
}),
)
.exists();
assert.dom(screen.getByRole('cell', { name: 'Earth' })).exists();
assert.dom(screen.getByRole('cell', { name: 'Moon' })).exists();
});
});

module('visiting /locations/:id', function () {
test('it displays a single location', async function (assert) {
// when
const screen = await visit('/locations');
await click(screen.getByRole('link', { name: 'Moon' }));

// then
assert
.dom(
screen.getByRole('heading', {
name: 'Moon',
level: 2,
}),
)
.exists();
assert
.dom(screen.getByRole('definition', { name: 'Current position' }))
.hasText('1.000 2.000');
});
});
});

0 comments on commit 1a03eb8

Please sign in to comment.