Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tupaschoal committed Jan 4, 2025
1 parent d21554c commit 6b19ce2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
47 changes: 36 additions & 11 deletions __tests__/__renderer__/preferences.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ let listenerLanguage;
let populateLanguages;
let refreshContent;
let renderPreferencesWindow;
let setupListeners;
let resetContent;

describe('Test Preferences Window', () =>
Expand All @@ -101,14 +102,15 @@ describe('Test Preferences Window', () =>

// Stub methods
window.mainApi.notifyNewPreferences = () => {};
window.mainApi.getLanguageDatePromise = () => {};
window.mainApi.showDialogSync = () => { return new Promise((resolve) => resolve({ response: 0 })); };

// TODO: add the necessary values here for the reset test to work
// window.mainApi.getLanguageDataPromise = () => { return new Promise((resolve) => resolve({
// 'language': 'en',
// 'data': {}
// })); };
window.mainApi.getLanguageDataPromise = () =>
{
return new Promise((resolve) => resolve({
'language': 'en',
'data': {}
}));
};

resetPreferenceFile();

Expand All @@ -120,6 +122,7 @@ describe('Test Preferences Window', () =>
populateLanguages = file.populateLanguages;
refreshContent = file.refreshContent;
renderPreferencesWindow = file.renderPreferencesWindow;
setupListeners = file.setupListeners;
resetContent = file.resetContent;
});

Expand Down Expand Up @@ -289,7 +292,7 @@ describe('Test Preferences Window', () =>
});
});

describe('Checking if reset button is responsive', () =>
describe('Checking reset logic', () =>
{
beforeEach(async function()
{
Expand All @@ -299,12 +302,34 @@ describe('Test Preferences Window', () =>
listenerLanguage();
});

it('Click reset and check that setting was restored', () =>
it('Check reset function restores setting', () =>
{
changeItemValue('count-today', true);
checkRenderedItem('count-today');
changeItemInputValue('count-today', true);
checkRenderedItem('count-today', isCheckBox);
resetContent();
$('input[name*=\'count-today\']').prop('checked', (i, val) =>
{
assert.strictEqual(val, false);
});
});

it('Click reset and check that reset function is being called', (done) =>
{
changeItemInputValue('count-today', true);
checkRenderedItem('count-today', isCheckBox);
// For some reason listeners are not set-up when we get to this point
// despite them being called at the beginning of the test
setupListeners();
$('#reset-button').trigger('click');
assert.strictEqual($('#count-today').val(), false);
// Need to briefly timeout so the click actions can propagate
setTimeout(() =>
{
$('input[name*=\'count-today\']').prop('checked', (i, val) =>
{
assert.strictEqual(val, false);
});
done();
}, 1);
});
});
});
3 changes: 1 addition & 2 deletions src/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,8 @@ function setupListeners()

$('#reset-button').on('click', function()
{
console.log("1");
window.mainApi.getLanguageDataPromise().then(languageData =>
{
console.log("2");
const options = {
type: 'question',
buttons: [getTranslationInLanguageData(languageData.data, '$Preferences.yes-please'), getTranslationInLanguageData(languageData.data, '$Preferences.no-thanks')],
Expand Down Expand Up @@ -295,5 +293,6 @@ export {
resetContent,
populateLanguages,
listenerLanguage,
setupListeners,
renderPreferencesWindow,
};

0 comments on commit 6b19ce2

Please sign in to comment.