| 1 |
package website.controller; |
| 2 |
|
| 3 |
import haxe.io.Bytes; |
| 4 |
import website.api.ProjectApi; |
| 5 |
import website.controller.*; |
| 6 |
import ufront.web.result.*; |
| 7 |
import ufront.web.result.ViewResult; |
| 8 |
import website.Server; |
| 9 |
import haxe.ds.Option; |
| 10 |
using tink.CoreApi; |
| 11 |
|
| 12 |
// These imports are common for our various test-suite tools. |
| 13 |
import buddy.*; |
| 14 |
import mockatoo.Mockatoo.*; |
| 15 |
import ufront.test.TestUtils.NaturalLanguageTests.*; |
| 16 |
import utest.Assert; |
| 17 |
using buddy.Should; |
| 18 |
using ufront.test.TestUtils; |
| 19 |
using mockatoo.Mockatoo; |
| 20 |
|
| 21 |
class ProjectControllerTest extends BuddySuite { |
| 22 |
public function new() { |
| 23 |
|
| 24 |
var haxelibSite = WebsiteTests.getTestApp(); |
| 25 |
var mockApi = mock( ProjectApi ); |
| 26 |
haxelibSite.injector.map( ProjectApi ).toValue( mockApi ); |
| 27 |
mockApi.projectInfo(cast anyString).returns( Success({ |
| 28 |
name: "detox", |
| 29 |
desc: "Detox Description", |
| 30 |
website: "https://github.com/jasononeil/detox", |
| 31 |
owner: "jason", |
| 32 |
license: "MIT", |
| 33 |
curversion: "1.0.0-rc.8", |
| 34 |
versions: [{ date: "2010-01-01 34:56:12", name:"1.0.0-rc.8", downloads:150, comments:"Breaking changes everywhere." }], |
| 35 |
tags: new List(), |
| 36 |
}) ); |
| 37 |
mockApi.readContentFromZip(cast anyString, cast anyString, cast anyString).returns( Success(Some("content")) ); |
| 38 |
mockApi.readBytesFromZip(cast anyString, cast anyString, cast anyString).returns( Success(Some(Bytes.ofString(""))) ); |
| 39 |
mockApi.getInfoForPath(cast anyString, cast anyString, cast anyString).returns( Success(Binary(12)) ); |
| 40 |
|
| 41 |
describe("When I view a project", { |
| 42 |
it("Should show the project view for the latest version", function (done) { |
| 43 |
whenIVisit( "/p/detox" ) |
| 44 |
.onTheApp( haxelibSite ) |
| 45 |
.itShouldLoad( ProjectController, "project", ["detox"] ) |
| 46 |
.itShouldReturn( ViewResult, function (result) { |
| 47 |
// TODO: Check we got the latest version. |
| 48 |
// TODO: Check we got the correct project. |
| 49 |
Assert.same( TFromEngine("project/version.html"), result.templateSource ); |
| 50 |
Assert.same( TFromEngine("layout.html"), result.layoutSource ); |
| 51 |
}) |
| 52 |
.andFinishWith( done ); |
| 53 |
}); |
| 54 |
}); |
| 55 |
|
| 56 |
describe("When I view a project version", { |
| 57 |
|
| 58 |
var whenILoadAProjectVersion = whenIVisit( "/p/detox/1.0.0-rc.8/" ).onTheApp( haxelibSite ); |
| 59 |
it("Should load the correct layout / view", function (done) { |
| 60 |
whenILoadAProjectVersion |
| 61 |
.itShouldLoad( ProjectController, "version", ["detox","1.0.0-rc.8"] ) |
| 62 |
.itShouldReturn( ViewResult, function(result) { |
| 63 |
Assert.same( TFromEngine("project/version.html"), result.templateSource ); |
| 64 |
Assert.same( TFromEngine("layout.html"), result.layoutSource ); |
| 65 |
}).andFinishWith( done ); |
| 66 |
}); |
| 67 |
it("Should show me the README for the current version", function (done) { |
| 68 |
whenILoadAProjectVersion.itShouldReturn( ViewResult, function(result) { |
| 69 |
// TODO: add appropriate tests here... |
| 70 |
}).andFinishWith( done ); |
| 71 |
}); |
| 72 |
it("Should show me the file list for the current version", function (done) { |
| 73 |
whenILoadAProjectVersion.itShouldReturn( ViewResult, function(result) { |
| 74 |
// TODO: add appropriate tests here... |
| 75 |
}).andFinishWith( done ); |
| 76 |
}); |
| 77 |
it("Should show me a list of all versions", function (done) { |
| 78 |
whenILoadAProjectVersion.itShouldReturn( ViewResult, function(result) { |
| 79 |
// TODO: add appropriate tests here... |
| 80 |
}).andFinishWith( done ); |
| 81 |
}); |
| 82 |
it("Should show me the haxelibs this depends on", function (done) { |
| 83 |
whenILoadAProjectVersion.itShouldReturn( ViewResult, function(result) { |
| 84 |
// TODO: add appropriate tests here... |
| 85 |
}).andFinishWith( done ); |
| 86 |
}); |
| 87 |
it("Should show me the haxelibs that depend on this", function (done) { |
| 88 |
whenILoadAProjectVersion.itShouldReturn( ViewResult, function(result) { |
| 89 |
// TODO: add appropriate tests here... |
| 90 |
}).andFinishWith( done ); |
| 91 |
}); |
| 92 |
it("Should let me know if there is a more recent version", function (done) { |
| 93 |
whenILoadAProjectVersion.itShouldReturn( ViewResult, function(result) { |
| 94 |
// TODO: add appropriate tests here... |
| 95 |
}).andFinishWith( done ); |
| 96 |
}); |
| 97 |
it("Should let me know if this version is not considered stable", function (done) { |
| 98 |
whenILoadAProjectVersion.itShouldReturn( ViewResult, function(result) { |
| 99 |
// TODO: add appropriate tests here... |
| 100 |
}).andFinishWith( done ); |
| 101 |
}); |
| 102 |
}); |
| 103 |
|
| 104 |
describe("When I view a project's versions", { |
| 105 |
it("Should show me a list of all the versions of that project, with the ability to show stable releases only.", function(done) { |
| 106 |
whenIVisit( "/p/detox/versions" ) |
| 107 |
.onTheApp( haxelibSite ) |
| 108 |
.itShouldLoad( ProjectController, "versionList", ["detox"] ) |
| 109 |
.itShouldReturn( ViewResult, function (result) { |
| 110 |
// TODO: Check it shows the list of versions. |
| 111 |
}) |
| 112 |
.andFinishWith( done ); |
| 113 |
}); |
| 114 |
}); |
| 115 |
|
| 116 |
describe("When I view a project's files", { |
| 117 |
it("Should show me that file's source code in line", function (done) { |
| 118 |
whenIVisit( "/p/detox/1.0.0-rc.8/files/src/Detox.hx" ) |
| 119 |
.onTheApp( haxelibSite ) |
| 120 |
.itShouldLoad( ProjectController, "file", ["detox","1.0.0-rc.8",["src","Detox.hx"]] ) |
| 121 |
.itShouldReturn( ViewResult, function (result) { |
| 122 |
// TODO: Check it shows the source code for the file. |
| 123 |
}) |
| 124 |
.andFinishWith( done ); |
| 125 |
}); |
| 126 |
it("Should render markdown files as HTML", function (done) { |
| 127 |
whenIVisit( "/p/detox/1.0.0-rc.8/files/README.md" ) |
| 128 |
.onTheApp( haxelibSite ) |
| 129 |
.itShouldLoad( ProjectController, "file", ["detox","1.0.0-rc.8",["README.md"]] ) |
| 130 |
.itShouldReturn( ViewResult, function (result) { |
| 131 |
// TODO: Check it shows the rendered markdown. |
| 132 |
}) |
| 133 |
.andFinishWith( done ); |
| 134 |
}); |
| 135 |
it("Should show binary files size and a link to download it", function (done) { |
| 136 |
whenIVisit( "/p/hxssl/3.0.0-alpha/files/ndll/Linux64/hxssl.ndll" ) |
| 137 |
.onTheApp( haxelibSite ) |
| 138 |
.itShouldLoad( ProjectController, "file", ["hxssl","3.0.0-alpha",["ndll","Linux64","hxssl.ndll"]] ) |
| 139 |
.itShouldReturn( ViewResult, function (result) { |
| 140 |
// TODO: Check it shows the file name and download size. |
| 141 |
}) |
| 142 |
.andFinishWith( done ); |
| 143 |
}); |
| 144 |
}); |
| 145 |
|
| 146 |
describe("When I view a projects docs", { |
| 147 |
it("Should show the correct documentation for this version", function(done) { |
| 148 |
whenIVisit( "/p/detox/1.0.0-rc.8/doc/dtx.widget.Widget" ) |
| 149 |
.onTheApp( haxelibSite ) |
| 150 |
.itShouldLoad( ProjectController, "docs", ["detox","1.0.0-rc.8","dtx.widget.Widget"] ) |
| 151 |
.itShouldReturn( ViewResult, function (result) { |
| 152 |
// TODO: Check it loads the correct view, documentation is rendered, etc. |
| 153 |
}) |
| 154 |
.andFinishWith( done ); |
| 155 |
}); |
| 156 |
}); |
| 157 |
} |
| 158 |
} |