applait / finderjs

Finder and file picker library for Firefox OS
http://finder.js.org
MIT License
14 stars 7 forks source link

Write tests for matchname method #9

Closed kaustavdm closed 9 years ago

kaustavdm commented 9 years ago
kaustavdm commented 9 years ago

@kumarrishav Wanna take this up?

kumarrishav commented 9 years ago

@kaustavdm yeah sure :)

kaustavdm commented 9 years ago

@kumarrishav go ahead!

kaustavdm commented 9 years ago

@kumarrishav Added 2 more test cases. Check issue description.

kumarrishav commented 9 years ago

@kaustavdm
var finder = new Applait.Finder({ hidden: true, searchkey: "ttt"}); var matchname = finder.matchname(".1.jpg", "/sdcard/DCIM/100MZLLA/.1.jpg"); expect(matchname).toBe(true);

expected result is not changing by changing searchkey? why it's happening.

kumarrishav commented 9 years ago

seems i got the solution, will discuss after submitting PR

kaustavdm commented 9 years ago

@kumarrishav Please refer to the updated issue description. Sorry for the goof up. This should make the relation between matchname and checkhidden clearer in the test.

kumarrishav commented 9 years ago

@kaustavdm indirectly this is same as before. for the checkhidden to be true or false..it depends on both this.hidden as well as file is hidden or not. then for checkhidden, what case should i take ? I will suggest, simply change the description in previous PR (like searchkey matches and this.checkhidden() is true/false) because previous PR has all the cases.

kaustavdm commented 9 years ago

@kumarrishav matchname depends on checkhidden. So, it is not reliable to test just this.hidden. checkhidden does other tests as well. So, the idea is, within your test, overwrite the checkhidden method, just for that instance, with a custom function that just returns true or false depending on the usecase that you want to test.

Something like this:

var finder = new Applait.Finder();
// Overwrite checkhidden to return just true
finder.checkhidden = function () {
    return true;
};
finder.casesensitive = true;
finder.matchname("Aa.jpg", "/sdcard/100Mozilla/Aa.jpg"); 

// Overwrite checkhidden to return just false
finder.checkhidden = function () {
    return false;
};
// Test matchname again

Makes sense?