Skip to content

Commit

Permalink
Tweak theme query
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Apr 16, 2020
1 parent f5c2ddf commit f89e10f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
9 changes: 3 additions & 6 deletions lib/helpers.js
Expand Up @@ -83,16 +83,13 @@ function generateBodyClass(pathname) {

function selectedTheme(selected) {
const totalThemes = files.bootswatch4.themes.length;
const theme = Number.parseInt(selected, 10);

if (typeof selected === 'undefined' || selected === '' || Number.isNaN(selected) || selected < 0 || selected >= totalThemes) {
if (Number.isNaN(theme) || theme < 0 || theme >= totalThemes) {
return app.theme;
}

const theme = Number.parseInt(selected, 10);

return theme === 0 || theme ?
theme :
app.theme;
return theme;
}

function getTheme(selected) {
Expand Down
14 changes: 7 additions & 7 deletions test/bootswatch4_test.js
Expand Up @@ -46,15 +46,15 @@ describe('bootswatch4', () => {
});

const invalidQueries = [
Number.parseInt(-1, 10),
Number.parseInt(500, 10),
Number.parseInt('5', 10),
Number.parseInt('foobar', 10)
-1,
500,
'5',
'foobar'
];

invalidQueries.forEach((i) => {
it(`handles invalid theme query parameter (${i})`, (done) => {
const invalidUri = helpers.getURI(`bootswatch/?theme=${i}`);
invalidQueries.forEach((query) => {
it(`handles invalid theme query parameter (${query})`, (done) => {
const invalidUri = helpers.getURI(`bootswatch/?theme=${query}`);
let invalidResponse = {};

helpers.prefetch(invalidUri, (res) => {
Expand Down

0 comments on commit f89e10f

Please sign in to comment.