Skip to content

Commit d7115d8

Browse files
Merge pull request #2056 from senid231/fix-rate-management-project-tom-select-flaky-tests
fix flaky rate management project tom-select specs
2 parents babf60c + 0cf2900 commit d7115d8

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

spec/features/rate_management/project/update_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
context 'when project with same scope attributes exists' do
3838
let(:fill_form!) do
3939
fill_in_tom_select 'Vendor', with: another_project.vendor.name, search: true
40-
fill_in_tom_select 'Account', with: another_project.account.name
40+
fill_in_tom_select 'Account', with: another_project.account.name, search: true
4141
fill_in_tom_select 'Routing group', with: another_project.routing_group.name
4242
fill_in_tom_select 'Routeset discriminator', with: another_project.routeset_discriminator.name
4343
fill_in_tom_select 'Gateway', with: another_gateway.name

spec/support/page_objects/section/tom_select.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,19 @@ def add_item_by_text(text, exact:)
209209
if (!ts) { return 'no-instance'; }
210210
var text = String(arguments[1]).trim(), exact = arguments[2];
211211
var labelField = ts.settings.labelField, valueField = ts.settings.valueField;
212-
var match = null;
212+
// Always prefer an exact label match; only when exact is false and no
213+
// exact match exists do we fall back to the first substring match.
214+
// Without this preference a search for "Discriminator 1" could pick
215+
// "Discriminator 10" (whichever option key is enumerated first),
216+
// selecting the wrong record and flaking the spec.
217+
var match = null, substringMatch = null;
213218
Object.keys(ts.options).some(function (key) {
214219
var label = String(ts.options[key][labelField]).trim();
215-
if (exact ? label === text : label.indexOf(text) !== -1) { match = ts.options[key]; return true; }
220+
if (label === text) { match = ts.options[key]; return true; }
221+
if (!exact && substringMatch === null && label.indexOf(text) !== -1) { substringMatch = ts.options[key]; }
216222
return false;
217223
});
224+
if (!match && !exact) { match = substringMatch; }
218225
if (!match) { return 'not-found'; }
219226
ts.addItem(String(match[valueField]), false);
220227
return 'ok';

0 commit comments

Comments
 (0)