Skip to content

Commit

Permalink
Add task description to my specifications table
Browse files Browse the repository at this point in the history
Checking the request path for this seems like it might
lead to future unpleasantness but it’s fine for now.
  • Loading branch information
backspace committed Sep 28, 2024
1 parent f38e9bd commit 0fcfb3a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
defmodule RegistrationsWeb.SpecificationView do
use JSONAPI.View, type: "specifications"

alias RegistrationsWeb.Router.Helpers, as: Routes
alias RegistrationsWeb.SpecificationView

def fields do
[:concept, :start_description, :duration, :placed]
[:concept, :start_description, :duration, :placed, :task_description]
end

def task_description(specification, conn) do
if conn.request_path == Routes.my_specifications_path(conn, :mine) do
specification.task_description
end
end

def placed(specification, _conn) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule RegistrationsWeb.SpecificationControllerTest do
|> put_req_header("content-type", "application/vnd.api+json")}
end

describe "list specifications" do
describe "list specifications not including task description" do
setup do
parent_region =
Repo.insert!(%Region{name: "Parent Region", geom: %Geo.Point{coordinates: {-97.0, 40.1}, srid: 4326}})
Expand Down Expand Up @@ -61,6 +61,7 @@ defmodule RegistrationsWeb.SpecificationControllerTest do
assert placed_specification_data["attributes"]["placed"]
assert placed_specification_data["attributes"]["concept"] == "fill_in_the_blank"
assert placed_specification_data["attributes"]["start_description"] == "Outside the coat check"
refute placed_specification_data["attributes"]["task_description"]
assert placed_specification_data["relationships"]["region"]["data"]["id"] == child_region.id

assert Enum.any?(included, fn item ->
Expand All @@ -85,45 +86,63 @@ defmodule RegistrationsWeb.SpecificationControllerTest do
end
end

describe "list my specifications" do
describe "list my specifications including task description" do
setup do
user = insert(:octavia, admin: true)
my_specification_1 = Repo.insert!(%Specification{creator_id: user.id})
my_specification_2 = Repo.insert!(%Specification{creator_id: user.id})
my_specification_1 = Repo.insert!(%Specification{creator_id: user.id, task_description: "Task description 1"})
my_specification_2 = Repo.insert!(%Specification{creator_id: user.id, task_description: "Task description 2"})
other_specification = Repo.insert!(%Specification{creator_id: insert(:user).id})

authed_conn = build_conn()

authed_conn =
authed_conn
|> post(Routes.api_session_path(authed_conn, :create), %{"user" => %{"email" => user.email, "password" => "Xenogenesis"}})
post(authed_conn, Routes.api_session_path(authed_conn, :create), %{
"user" => %{"email" => user.email, "password" => "Xenogenesis"}
})

json = json_response(authed_conn, 200)
authorization_token = json["data"]["access_token"]

%{authorization_token: authorization_token, my_specification_1: my_specification_1, my_specification_2: my_specification_2, other_specification: other_specification, user: user}
%{
authorization_token: authorization_token,
my_specification_1: my_specification_1,
my_specification_2: my_specification_2,
other_specification: other_specification,
user: user
}
end

test "returns list of specifications for the current user", %{
conn: conn,
authorization_token: authorization_token,
my_specification_1: my_specification_1,
my_specification_2: my_specification_2,
other_specification: other_specification,
other_specification: other_specification
} do
conn =
conn
|> put_req_header("authorization", "#{authorization_token}")
|> get(Routes.my_specifications_path(conn, :mine))

response_specification_ids =
json_response(conn, 200)
conn
|> json_response(200)
|> Map.get("data")
|> Enum.map(fn specification -> specification["id"] end)

response_task_descriptions =
conn
|> json_response(200)
|> Map.get("data")
|> Enum.map(fn specification -> specification["attributes"]["task_description"] end)

assert my_specification_1.id in response_specification_ids
assert my_specification_2.id in response_specification_ids
refute other_specification.id in response_specification_ids

assert my_specification_1.task_description in response_task_descriptions
assert my_specification_2.task_description in response_task_descriptions
refute other_specification.task_description in response_task_descriptions
end
end
end
9 changes: 6 additions & 3 deletions waydowntown_app/lib/models/specification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class Specification {
final int? duration;
final Region? region;
final bool placed;
final String? start;
final String? startDescription;
final String? taskDescription;
final List<Answer>? answers;

const Specification({
Expand All @@ -16,7 +17,8 @@ class Specification {
this.region,
this.duration,
required this.placed,
this.start,
this.startDescription,
this.taskDescription,
this.answers,
});

Expand Down Expand Up @@ -48,7 +50,8 @@ class Specification {
region: region,
placed: attributes['placed'] ?? false,
duration: attributes['duration'],
start: attributes['start'],
startDescription: attributes['start_description'],
taskDescription: attributes['task_description'],
answers: included
.where((item) =>
item['type'] == 'answers' &&
Expand Down
4 changes: 2 additions & 2 deletions waydowntown_app/lib/routes/run_launch_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ class _RunLaunchRouteState extends State<RunLaunchRoute> {
'Instructions',
instructions,
),
if (widget.run.specification.start != null)
if (widget.run.specification.startDescription != null)
_buildInfoCard(
context,
'Starting point',
widget.run.specification.start!,
widget.run.specification.startDescription!,
),
Row(
children: [
Expand Down
7 changes: 5 additions & 2 deletions waydowntown_app/lib/tools/my_specifications_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class _MySpecificationsTableState extends State<MySpecificationsTable> {
child: DataTable(
columns: const [
DataColumn(label: Text('Concept')),
DataColumn(label: Text('Start Description')),
DataColumn(label: Text('Start')),
DataColumn(label: Text('Task')),
DataColumn(label: Text('')),
],
rows: _buildTableRows(),
Expand Down Expand Up @@ -121,12 +122,14 @@ class _MySpecificationsTableState extends State<MySpecificationsTable> {
),
const DataCell(Text('')),
const DataCell(Text('')),
const DataCell(Text('')),
],
));
rows.addAll(specs.map((spec) => DataRow(
cells: [
DataCell(Text(spec.concept)),
DataCell(_truncatedText(spec.start)),
DataCell(_truncatedText(spec.startDescription)),
DataCell(_truncatedText(spec.taskDescription)),
DataCell(IconButton(
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(
Expand Down
2 changes: 1 addition & 1 deletion waydowntown_app/test/test_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class TestHelpers {
id: '0091eb84-85c8-4e63-962b-39e1a19d2781',
placed: true,
concept: concept,
start: start,
startDescription: start,
answers: answers ??
[
const Answer(id: '1', label: 'Answer 1'),
Expand Down

0 comments on commit 0fcfb3a

Please sign in to comment.