Debian Codegraph @

extra/haxelib_src/test/website/controller/HomeControllerTest.hx

raw
1 package website.controller;
2
3 import website.api.ProjectListApi;
4 import website.controller.*;
5 import ufront.web.result.*;
6 import ufront.web.result.ViewResult;
7 import website.Server;
8 using tink.CoreApi;
9 import haxelib.server.SiteDb;
10
11 // These imports are common for our various test-suite tools.
12 import buddy.*;
13 import mockatoo.Mockatoo.*;
14 import ufront.test.TestUtils.NaturalLanguageTests.*;
15 import utest.Assert;
16 using buddy.Should;
17 using ufront.test.TestUtils;
18 using mockatoo.Mockatoo;
19
20 class HomeControllerTest extends BuddySuite {
21 public function new() {
22
23 var haxelibSite = WebsiteTests.getTestApp();
24 var mockApi = mock( ProjectListApi );
25 haxelibSite.injector.map( ProjectListApi ).toValue( mockApi );
26 mockApi.all().returns( Success(new List()) );
27 mockApi.byUser(cast anyString).returns( Success(new List()) );
28 mockApi.byTag(cast anyString).returns( Success(new List()) );
29 mockApi.search(cast anyString).returns( Success(new List()) );
30 mockApi.latest(cast anyInt).returns( Success(new List()) );
31 mockApi.getTagList(cast anyInt).returns( Success(new List()) );
32
33 describe("When I go to the homepage", {
34 it("Should show our homepage view", function (done) {
35
36
37 whenIVisit( "/" )
38 .onTheApp( haxelibSite )
39 .itShouldLoad( HomeController, "homepage", [] )
40 .itShouldReturn( ViewResult, function (result) {
41 var title:String = result.data['title'];
42 (result.data['title']:String).should.be("Haxelib - the Haxe package manager");
43 Assert.same( result.templateSource, TFromEngine("home/homepage") );
44 Assert.same( result.layoutSource, TFromEngine("layout.html") );
45 // TODO: check we have a list of popular projects
46 // TODO: check we have a list of recent projects
47 })
48 .andFinishWith( done );
49 });
50 // TODO: it("Show me my projects if I am logged in");
51 });
52
53 describe("When I load the tags page", {
54 it("Should show me a list of the most popular tags, sorted by popularity", function (done) {
55 whenIVisit( "/t/")
56 .onTheApp( haxelibSite )
57 .itShouldLoad( HomeController, "tagList", [] )
58 .itShouldReturn( ViewResult, function(result) {
59 Assert.same( result.templateSource, TFromEngine("home/tagList") );
60 Assert.same( result.layoutSource, TFromEngine("layout.html") );
61 // TODO: check that the tags are listed...
62 })
63 .andFinishWith( done );
64 });
65 });
66
67 describe("When I load a tag page", {
68 it("Should show the list of projects with that tag", function (done) {
69 whenIVisit( "/t/games")
70 .onTheApp( haxelibSite )
71 .itShouldLoad( HomeController, "tag", ["games"] )
72 .itShouldReturn( ViewResult, function(result) {
73 Assert.same( result.templateSource, TFromEngine("home/tagProjectList.html") );
74 Assert.same( result.layoutSource, TFromEngine("layout.html") );
75 // TODO: check that the matching projects are correct
76 })
77 .andFinishWith( done );
78 });
79 });
80
81 describe("When I load the 'all projects' page", {
82 it("Should show them all", function (done) {
83 whenIVisit( "/all")
84 .onTheApp( haxelibSite )
85 .itShouldLoad( HomeController, "all", [] )
86 .itShouldReturn( ViewResult, function(result) {
87 Assert.same( result.templateSource, TFromEngine("home/projectList.html") );
88 Assert.same( result.layoutSource, TFromEngine("layout.html") );
89 // TODO: check that all projects are loaded
90 })
91 .andFinishWith( done );
92 });
93 });
94
95 describe("When I search", {
96 // TODO: ask Nicolas, should we just use Google?
97 // it("Should show me the search form if there is no search term entered");
98 // it("Should show projects matching the name");
99 // it("Should show projects matching the description");
100 // it("Redirect straight to the project page if there's only 1 search result");
101 });
102
103 describe("When I want to access the data through a JSON API", {
104 it("Should give me search via JSON", function (done) {
105 whenIVisit( "/search.json" )
106 .withTheQueryParams([ "v"=>"web" ])
107 .onTheApp( haxelibSite )
108 .itShouldLoad( HomeController, "searchJson", [{ v: "web" }] )
109 .itShouldReturn( JsonResult, function (result) {
110 // TODO: check the data is good.
111 // TODO: check the JSON is valid.
112 })
113 .andFinishWith( done );
114 });
115 it("Should give me tags via JSON", function (done) {
116 whenIVisit( "/t/games.json" )
117 .onTheApp( haxelibSite )
118 .itShouldLoad( HomeController, "tag", ["games.json"] )
119 .itShouldReturn( JsonResult, function (result) {
120 // TODO: check the data is good.
121 // TODO: check the JSON is valid.
122 })
123 .andFinishWith( done );
124 });
125 it("Should give me all via JSON", function (done) {
126 whenIVisit( "/all.json" )
127 .onTheApp( haxelibSite )
128 .itShouldLoad( HomeController, "allJson", [] )
129 .itShouldReturn( JsonResult, function (result) {
130 // TODO: check the data is good.
131 // TODO: check the JSON is valid.
132 })
133 .andFinishWith( done );
134 });
135 });
136 }
137 }