mirror of
https://github.com/wassname/keywordshitter2.git
synced 2026-06-27 16:10:23 +08:00
Tests
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/responsive/2.0.0/css/responsive.dataTables.min.css"/>
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/scroller/1.4.0/css/scroller.dataTables.min.css"/>
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
|
||||
</head>
|
||||
@@ -461,6 +463,10 @@ lying internet</textarea>
|
||||
<script src="//cdn.datatables.net/s/bs/jszip-2.5.0,dt-1.10.10,b-1.1.0,b-colvis-1.1.0,b-html5-1.1.0,b-print-1.1.0,cr-1.3.0,fh-3.1.0,kt-2.1.0,r-2.0.0,se-1.1.0/datatables.min.js" crossorigin="anonymous"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/4.2.0/lodash.min.js"></script>
|
||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2014-11-29/FileSaver.min.js"></script>
|
||||
<!-- <script src="//cdnjs.cloudflare.com/ajax/libs/localforage/1.3.3/localforage.js"></script> -->
|
||||
|
||||
|
||||
|
||||
<script type="text/javascript" src="js/main.js"></script>
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ function parseServiceResponse(res,options){
|
||||
return _.map(res.gossip.results, 'key');
|
||||
},
|
||||
"ebay": function (res) {
|
||||
return res.res ? res.res.sug : undefined;
|
||||
return res.res ? res.res.sug : [];
|
||||
},
|
||||
"twitter": function (res) {
|
||||
return _.concat(res.users, _.map(res.topics, 'topic'), res.hashtags, res.oneclick);
|
||||
|
||||
+64
-38
@@ -1,14 +1,27 @@
|
||||
var expect = chai.expect;
|
||||
var assert = chai.assert;
|
||||
|
||||
// TODO describe('permute', function(){
|
||||
// it('should correctly permute results and add to queue', function() {
|
||||
// });
|
||||
// });
|
||||
|
||||
// TODO use localForage or most popular promise wrapper for indexedDB then test
|
||||
// describe('exportDB', function(){
|
||||
// });
|
||||
|
||||
describe('db', function() {
|
||||
it('should correctly set up db', function() {
|
||||
it('should correctly set up db', function(done) {
|
||||
var dbReq=setUpDb();
|
||||
var oldonsuccess=dbReq.onsuccess;
|
||||
dbReq.onsuccess=function(event){
|
||||
// override onld onsucess because it doesn't use promises
|
||||
var db=oldonsuccess.bind(dbReq)(event);
|
||||
assert(db);
|
||||
assert(db.objectStoreNames.contains('suggestions'),'db should contain suggestons store');
|
||||
var indexNames =db.transaction('suggestions','readonly').objectStore('suggestions').indexNames;
|
||||
assert(indexNames.contains('keyword','search'));
|
||||
done();
|
||||
};
|
||||
});
|
||||
});
|
||||
@@ -16,41 +29,23 @@ describe('db', function() {
|
||||
|
||||
describe('extractDomain', function(){
|
||||
|
||||
it('should correctly extract domain from url', function() {
|
||||
for (var expectedDomain in testData.domainUrls) {
|
||||
if (testData.domainUrls.hasOwnProperty(expectedDomain)) {
|
||||
for (var expectedDomain in testData.domainUrls) {
|
||||
if (testData.domainUrls.hasOwnProperty(expectedDomain)) {
|
||||
it('should correctly extract domain from url, domain='+expectedDomain, function() {
|
||||
var url = testData.domainUrls[expectedDomain];
|
||||
var domain = extractDomain(url);
|
||||
assert.equal(expectedDomain,domain);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// describe('permute', function(){
|
||||
// it('should correctly permute results and add to queue', function() {
|
||||
// });
|
||||
// });
|
||||
|
||||
// TODO use localForage or most popular promise wrapper for indexedDB then test
|
||||
// describe('exportDB', function(){
|
||||
// before(function() {
|
||||
// // setup up test db
|
||||
// });
|
||||
//
|
||||
// after(function() {
|
||||
// // tear down test db
|
||||
// });
|
||||
//
|
||||
// it('should correctly download json file', function() {
|
||||
// exportDB();
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('responses', function(){
|
||||
it('should correctly parse test data', function() {
|
||||
for (var service in testData.responses) {
|
||||
if (testData.responses.hasOwnProperty(service)) {
|
||||
for (var service in testData.responses) {
|
||||
if (testData.responses.hasOwnProperty(service)) {
|
||||
it('should correctly parse test data for service='+service, function() {
|
||||
var res = testData.responses[service];
|
||||
var options = {service:service};
|
||||
var parsedRes = parseServiceResponse(res,options);
|
||||
@@ -58,18 +53,22 @@ describe('responses', function(){
|
||||
assert.typeOf(parsedRes,'array');
|
||||
expect(parsedRes).to.have.length.above(1);
|
||||
parsedRes.map(r => assert.typeOf(r, 'string'));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe('services', function() {
|
||||
'use strict';
|
||||
// TODO test for each language and country and assert results!=default res
|
||||
this.timeout(10000);
|
||||
this.slow(2000);
|
||||
|
||||
// data
|
||||
var services = ["google", "google news", "google shopping", "google books", "youtube", "google videos", "google images", "yahoo", "bing", "ebay", "amazon", "twitter", "baidu", "yandex"];
|
||||
var searches = ["where"];
|
||||
var searches2 = [""," "," * ",":)","❥","غرف شات","汉字"];
|
||||
var searchesDifficult = [" * ", "❥"];
|
||||
|
||||
|
||||
before(function() {
|
||||
|
||||
@@ -79,12 +78,40 @@ describe('services', function() {
|
||||
|
||||
});
|
||||
|
||||
it('should correctly get and parse data', function() {
|
||||
services.forEach(function(service){
|
||||
searches.forEach(function(search){
|
||||
services.forEach(function(service){
|
||||
searches.forEach(function(search){
|
||||
it('should correctly get and parse data'+'. Service="'+service+'" search="'+search+'"', function(done) {
|
||||
var options = {service:service};
|
||||
var url = getUrl(options)+search;
|
||||
$.ajax({
|
||||
return $.ajax({
|
||||
url: url,
|
||||
async: false,
|
||||
jsonp: "jsonp",
|
||||
dataType: "jsonp",
|
||||
success: function (res, statusText, jqXHR) {
|
||||
assert(statusText=="success");
|
||||
assert(res!==[]);
|
||||
var parsedRes = parseServiceResponse(res,options);
|
||||
assert.typeOf(parsedRes,'array');
|
||||
parsedRes.map(r => assert.typeOf(r, 'string'));
|
||||
done();
|
||||
},
|
||||
error: function(jqXHR,textStatus,err){
|
||||
done(err);
|
||||
return err;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
services.forEach(function(service){
|
||||
searchesDifficult.forEach(function(search){
|
||||
it('should get and parse difficult data'+'. Service="'+service+'" search="'+search+'"', function(done) {
|
||||
var options = {service:service};
|
||||
var url = getUrl(options)+search;
|
||||
return $.ajax({
|
||||
url: url,
|
||||
async: false,
|
||||
jsonp: "jsonp",
|
||||
@@ -93,15 +120,14 @@ describe('services', function() {
|
||||
assert(statusText=="success");
|
||||
assert(res!==[]);
|
||||
|
||||
|
||||
var parsedRes = parseServiceResponse(res,options);
|
||||
assert.typeOf(parsedRes,'array');
|
||||
expect(parsedRes).to.have.length.above(1);
|
||||
parsedRes.map(r => assert.typeOf(r, 'string'));
|
||||
return done();
|
||||
|
||||
},
|
||||
error: function(jqXHR,textStatus,err){
|
||||
throw(err);
|
||||
return done(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
function testData() {
|
||||
var testData = function () {
|
||||
return {
|
||||
domainUrls: {
|
||||
"api.bing.com": "http://api.bing.com/osjson.aspx?JsonType=callback&JsonCallback=jQuery111&query=a &_=11111",
|
||||
@@ -565,4 +565,4 @@ function testData() {
|
||||
}]
|
||||
}
|
||||
};
|
||||
}
|
||||
}();
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/4.2.0/lodash.min.js"></script>
|
||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2014-11-29/FileSaver.min.js"></script>
|
||||
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/localforage/1.3.3/localforage.js"></script>
|
||||
|
||||
<script src="js/main.js"></script>
|
||||
<script src="js/testData.js"></script>
|
||||
<script src="js/test.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user