BoolNordicAB / sharepoint-utilities

Makes client side SharePoint a bit nicer to work with (that's the plan, at least)
https://boolnordicab.github.io/sharepoint-utilities/doc/index.html
MIT License
14 stars 3 forks source link

add downloadContent helper #43

Closed mirontoli closed 8 years ago

mirontoli commented 8 years ago

I created a helper function for downloading a file, a csv file or text. This works even with utf-8 and opening it directly in Excel - a very common need in SharePoint development. An example is an "Export to Excel" button in Search based applications. Some more info can be found on my blog post:

mirontoli commented 8 years ago

There were some errors in sputils.list functions. I am not sure how to fix them to satifsy travis :)

roobie commented 8 years ago

From what I can see, the CI build worked fine.

Would it be possible to test this in some way? I'm thinking we could at least stub the browser functionality, and check that the function does validation as expected. E.g. test that options.content actually is validated in the function to be defined.

Also, I think we should use a more generic default file name (instead of "tolle.txt" =)

mirontoli commented 8 years ago

Thanks for the feedback. "tolle.txt" will be "download.txt" instead. I'll try to set up a test.

mirontoli commented 8 years ago

Now I have added a test that checks that an Error is thrown when content is not provided. Perhaps there is more that could be tested if we rewrite the function, but I don't know how, yet.

roobie commented 8 years ago

This is quite the difficult function to unit test, since it is heavily dependent on browser functionality and user interaction (like checking the downloaded file). Maybe we cannot test more than this, automatically. I think, regarding testing, the test you supplied is sufficient.

I've one more comment, though. the else is on a new line like:

if (...) {
}
else {
}

To keep the style consistent, we should put the else on the same line as } as such:

if (...) {
} else {
}
roobie commented 8 years ago

as a relevant aside, we should perhaps include the rule disallowNewlineBeforeBlockStatements in jscs, to catch these types of stylistic matters

roobie commented 8 years ago

the rule I was referring to is disallowKeywordsOnNewLine

mirontoli commented 8 years ago

Wow, that's perfectionism. I like it. I moved the "else" up to the } and I also added the rule disallowKeywordsOnNewLine to the .jscs.json.

mirontoli commented 8 years ago

@roobie can we merge it now?