Commit 5d7ee195 authored by Nicho's avatar Nicho
Browse files

Started on module tests for search view.

parent eda285cb
/* global require, it, describe, before */
"use strict";
var chai = require("chai"),
expect = chai.expect,
jsdom = require('mocha-jsdom');
describe('PatronClient', function () {
describe('/search', function() {
jsdom();
var Search;
var ractive;
before(function(done) {
var fixture = document.createElement('div');
fixture.setAttribute('id', 'app');
document.body.appendChild(fixture);
Search = require("../public/search.js");
Search.then(function(r){ractive = r; done()});
});
it('should load search hits into browser', function(done) {
ractive.set('hits.total', 1);
expect(document.querySelector('[data-automation-id="hits-total"]').innerHTML).to.eq('1');
done();
//done();
});
});
});
\ No newline at end of file
......@@ -53,7 +53,7 @@
<script src="/axios.min.js"></script>
</head>
<body>
<div id="#app"></div>
<div id="app"></div>
<script src="/search.js"></script>
</body>
</html>
\ No newline at end of file
Ractive.load( 'search_template.html' ).then( function ( SearchResults ) {
(function (root, factory) {
if (typeof module === 'object' && module.exports) {
var Ractive = require("../public/ractive.min.js");
Ractive.events = require("../public/ractive-events-keys.js");
var ractive = new SearchResults({
el: "#app",
data: {
hits: {
total: 0,
hits: []
}
}
});
var axios = require("../public/axios.min.js");
module.exports = factory(Ractive, axios);
} else {
root.Search = factory(root.Ractive, root.axios);
}
}(this, function (Ractive, axios) {
"use strict";
var template = '';
return axios.get( "http://192.168.50.12:8000/search_template.html" ).then( function ( response ) {
return response.data;
}).then(function(data){
console.log(data);
var searchRactive = new Ractive({
el: "#app",
template: data,
data: {
hits: {
total: 0,
hits: []
}
}
});
ractive.on({
search: function(event) {
var q = '"' + ractive.get("search_term") + '"';
searchRactive.on({
search: function (event) {
var q = '"' + searchRactive.get("search_term") + '"';
axios.get('http://192.168.50.12:8200/_search?q='+q)
.then(function (response) {
ractive.set("hits", response.data.hits);
})
.catch(function (response) {
console.log(response);
axios.get('http://192.168.50.12:8200/_search?q=' + q)
.then(function (response) {
searchRactive.set("hits", response.data.hits);
})
.catch(function (response) {
console.log(response);
});
}
});
}
});
}).catch(function(err) {
console.log(err);
});
return searchRactive;
});
}));
\ No newline at end of file
......@@ -6,33 +6,33 @@
</div>
<div class="container">
<div class="row results small-text">
<div class="row">
<div class="column full result-header"><h3>Verk ({{hits.total}})</h3></div>
</div>
{{#hits.hits}}
<div class="result row">
<div class="column fourth result-image">
<div class="cover-inner">
{{#image}}
<img class="cover-image" src="{{.image}}">
{{else}}
<i>et bilde hadde passet fint her</i>
{{/}}
</div>
<div class="row">
<div class="column full result-header"><h3>Verk (<span data-automation-id="hits-total">{{hits.total}}</span>)</h3></div>
</div>
{{#hits.hits}}
<div class="result row">
<div class="column fourth result-image">
<div class="cover-inner">
{{#image}}
<img class="cover-image" src="{{.image}}">
{{else}}
<i>et bilde hadde passet fint her</i>
{{/}}
</div>
</div>
<div class="column fourth result-info">
<p><strong>{{name}}</strong></p>
<p>Forfatter: <strong><a href="">{{creator}}</a></strong></p>
<p>Utgitt første gang: <strong>{{year}}</strong></p>
<p class="green">Ledig (? eks.)</p>
</div>
<div class="column half">
<p><b>Kort beskrivelse av verket:</b></p>
<p>Hadde vært fint å ha her.</p>
<a href="{{.['@id']}}" class="more">les mer ►</a>
</div>
<div class="column fourth result-info">
<p><strong>{{name}}</strong></p>
<p>Forfatter: <strong><a href="">{{creator}}</a></strong></p>
<p>Utgitt første gang: <strong>{{year}}</strong></p>
<p class="green">Ledig (? eks.)</p>
</div>
<div class="column half">
<p><b>Kort beskrivelse av verket:</b></p>
<p>Hadde vært fint å ha her.</p>
<a href="{{.['@id']}}" class="more">les mer ►</a>
</div>
{{/hits}}
</div>
{{/hits}}
</div>
</div>q
\ No newline at end of file
</div>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment