mirror of
https://github.com/TracksApp/tracks.git
synced 2025-09-22 05:50:47 +02:00
add test for cli xml builder
This commit is contained in:
parent
04560370f8
commit
4c73e260e3
2 changed files with 81 additions and 1 deletions
|
@ -33,7 +33,7 @@ module TracksCli
|
|||
end
|
||||
|
||||
def xml_for_context(context_name, context_id)
|
||||
if context_name && context_name.empty?
|
||||
if context_name && !context_name.empty?
|
||||
return "<context><name>#{context_name}</name></context>"
|
||||
else
|
||||
return "<context_id>#{context_id}</context_id>"
|
||||
|
|
80
test/models/tracks_cli/tracks_xml_builder_test.rb
Normal file
80
test/models/tracks_cli/tracks_xml_builder_test.rb
Normal file
|
@ -0,0 +1,80 @@
|
|||
require './test/minimal_test_helper'
|
||||
require './doc/tracks_cli/tracks_xml_builder'
|
||||
|
||||
module TracksCli
|
||||
|
||||
class TimeToCompleteTest < Test::Unit::TestCase
|
||||
def test_all
|
||||
todo = {
|
||||
description: "test action",
|
||||
project_id: 1,
|
||||
show_from: Time.utc(2013,1,1,14,00,00),
|
||||
notes: "action notes",
|
||||
taglist: "one, two",
|
||||
context_name: "@home",
|
||||
is_dependend: true,
|
||||
predecessor: 123
|
||||
}
|
||||
|
||||
xml = TracksCli::TracksXmlBuilder.new.build_todo_xml(todo)
|
||||
expect = "<todo><description>test action</description>" +
|
||||
"<project_id>1</project_id><show-from type=\"datetime\">2013-01-01T14:00:00Z</show-from>" +
|
||||
"<notes>action notes</notes><tags><tag><name>one</name></tag><tag><name>two</name></tag></tags>" +
|
||||
"<context><name>@home</name></context><predecessor_dependencies><predecessor>123</predecessor></predecessor_dependencies></todo>"
|
||||
|
||||
assert_equal expect, xml
|
||||
end
|
||||
|
||||
def test_context_name_is_passed_through
|
||||
todo = {
|
||||
description: "test action",
|
||||
project_id: 1,
|
||||
context_name: "@home",
|
||||
}
|
||||
|
||||
xml = TracksCli::TracksXmlBuilder.new.build_todo_xml(todo)
|
||||
expect = "<todo><description>test action</description><project_id>1</project_id><context><name>@home</name></context></todo>"
|
||||
|
||||
assert_equal expect, xml
|
||||
end
|
||||
|
||||
def test_context_id_is_used_if_no_context_name_given
|
||||
todo = {
|
||||
description: "test action",
|
||||
project_id: 5,
|
||||
context_id: 16,
|
||||
}
|
||||
|
||||
xml = TracksCli::TracksXmlBuilder.new.build_todo_xml(todo)
|
||||
expect = "<todo><description>test action</description><project_id>5</project_id><context_id>16</context_id></todo>"
|
||||
|
||||
assert_equal expect, xml, "only context_id given, so that should be included"
|
||||
|
||||
todo = {
|
||||
description: "test action",
|
||||
project_id: 5,
|
||||
context_id: 16,
|
||||
context_name: "@inbox"
|
||||
}
|
||||
|
||||
xml = TracksCli::TracksXmlBuilder.new.build_todo_xml(todo)
|
||||
expect = "<todo><description>test action</description><project_id>5</project_id><context><name>@inbox</name></context></todo>"
|
||||
|
||||
assert_equal expect, xml, "both context_id and context_name given, then context_name should be used"
|
||||
end
|
||||
|
||||
def test_project_xml_all
|
||||
todo = {
|
||||
description: "test project",
|
||||
default_context_id: 16
|
||||
}
|
||||
|
||||
xml = TracksCli::TracksXmlBuilder.new.build_project_xml(todo)
|
||||
expect = "<project><name>test project</name><default-context-id>16</default-context-id></project>"
|
||||
|
||||
assert_equal expect, xml
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue