diff --git a/frontend_tests/casper_tests/03-narrow.js b/frontend_tests/casper_tests/03-narrow.js index 4daab3c258..b835d59965 100644 --- a/frontend_tests/casper_tests/03-narrow.js +++ b/frontend_tests/casper_tests/03-narrow.js @@ -447,15 +447,35 @@ casper.waitWhileVisible('#stream_filters [data-stream-name="Denmark"]', function un_narrow(); +function assert_in_list(name) { + casper.test.assertExists( + '#user_presences li [data-name="' + name + '"]', + 'User ' + name + ' is IN buddy list' + ); +} + +function assert_selected(name) { + casper.test.assertExists( + '#user_presences li.highlighted_user [data-name="' + name + '"]', + 'User ' + name + ' is SELECTED IN buddy list' + ); +} + +function assert_not_selected(name) { + assert_in_list(name); + casper.test.assertDoesntExist( + '#user_presences li.highlighted_user [data-name="' + name + '"]', + 'User ' + name + ' is NOT SELECTED buddy list' + ); +} + + // User search at the right sidebar casper.then(function () { casper.test.info('Search users using right sidebar'); - casper.test.assertExists('#user_presences li [data-name="Cordelia Lear"]', - 'User Cordelia Lear exists'); - casper.test.assertExists('#user_presences li [data-name="King Hamlet"]', - 'User King Hamlet exists'); - casper.test.assertExists('#user_presences li [data-name="aaron"]', - 'User aaron exists'); + assert_in_list('Cordelia Lear'); + assert_in_list('King Hamlet'); + assert_in_list('aaron'); }); // Enter the search box and test selected suggestion navigation @@ -470,12 +490,9 @@ casper.then(function () { casper.waitForSelector('#user_presences .highlighted_user', function () { casper.test.info('Suggestion highlighting - initial situation'); - casper.test.assertExist('#user_presences li.highlighted_user [data-name="Cordelia Lear"]', - 'User Cordelia Lear is selected'); - casper.test.assertDoesntExist('#user_presences li.highlighted_user [data-name="King Hamlet"]', - 'User King Hamlet is not selected'); - casper.test.assertDoesntExist('#user_presences li.highlighted_user [data-name="aaron"]', - 'User aaron is not selected'); + assert_selected('Cordelia Lear'); + assert_not_selected('King Hamlet'); + assert_not_selected('aaron'); }); // Use arrow keys to navigate through suggestions @@ -493,10 +510,8 @@ casper.then(function () { casper.waitForSelector('#user_presences li.highlighted_user [data-name="King Hamlet"]', function () { casper.test.info('Suggestion highlighting - after arrow key navigation'); - casper.test.assertDoesntExist('#user_presences li.highlighted_user [data-name="Cordelia Lear"]', - 'User Cordelia Lear not is selected'); - casper.test.assertExist('#user_presences li.highlighted_user [data-name="King Hamlet"]', - 'User King Hamlet is selected'); + assert_not_selected('Cordelia Lear'); + assert_selected('King Hamlet'); }); common.then_log_out();