Skip to content

Commit

Permalink
Fixed bugs found while adding testscases
Browse files Browse the repository at this point in the history
  • Loading branch information
ravise5 committed Nov 27, 2023
1 parent f333b12 commit b191a5c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,44 @@ function testFunction1()
{
return "test";
}

/**
* Returns 3 enum values
* @name getEnum1 Get_Enum_1
* @return {OPTIONS}
*/
function getEnum1() {
var enums = [];
enums[0] = 'one';
enums[1] = 'two';
enums[2] = 'three';
return enums;
}

/**
* Return 3 enum Name values
* @name getEnumNames1 Get_Enum_Names_1
* @return {OPTIONS}
*/
function getEnumNames1() {
var enumNames = [];
enumNames[0] = 'India';
enumNames[1] = 'US';
enumNames[2] = 'Singapore';
return enumNames;
}

/**
* clears the enums
* @name clearEnums clear_enum
* @return {OPTIONS}
*/
function clearEnums() {
var enums = [];
return enums;
}





Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@
newEnumNames.forEach((value) => {
this.getWidgets().appendChild(this.#createCheckBoxItem(value, value));
})
} else if(currentEnumNameSize > newEnumNames.length) {
[...this.getOptions()].forEach((option, index) => {
let span = option.querySelector('span');
let input = option.querySelector('input');
if(index < newEnumNames.length) {
span.textContent = newEnumNames[index];
} else {
span.textContent = input.value;
}
});
} else {
[...this.getOptions()].forEach((option, index) => {
let span = option.querySelector('span');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@
return option
}

#removeAllOptions() {
while(this.getOptions().length !== 0) {
this.getWidget().remove(this.getOptions().length) // not removing the blank option
}
}

updateEnum(newEnums) {
let options = this.getOptions();
let currentEnumSize = options.length;
Expand All @@ -142,11 +148,13 @@
newEnums.forEach(value => {
this.getWidget().add(this.#createDropDownOptions(value, value));
});
} else if(currentEnumSize === newEnums.length) { // case 2: replace existing enums
} else if(newEnums.length === 0) { // case 2: remove all options
this.#removeAllOptions();
} else if(currentEnumSize === newEnums.length) { // case 3: replace existing enums
options.forEach((option, index) => {
option.value = newEnums[index];
});
} else if(currentEnumSize < newEnums.length) { // case 3: replace existing enums and create new options with remaining
} else if(currentEnumSize < newEnums.length) { // case 4: replace existing enums and create new options with remaining
options.forEach((option, index) => {
option.value = newEnums[index];
});
Expand All @@ -156,7 +164,7 @@
}
});
} else {
options.forEach((option, index) => { // case 4: replace existing enums and remove extra options
options.forEach((option, index) => { // case 5: replace existing enums and remove extra options
if(index < newEnums.length) {
option.value = newEnums[index];
} else {
Expand All @@ -169,11 +177,21 @@
updateEnumNames(newEnumNames) {
let options = this.getOptions();
let currentEnumNameSize = options.length;
if(currentEnumNameSize === 0) {
if(currentEnumNameSize === 0) { // case 1: Create all dropdown new options
newEnumNames.forEach((value) => {
this.getWidget().add(this.#createDropDownOptions((value, value)));
this.getWidget().add(this.#createDropDownOptions(value, value));
})
} else {
} else if(currentEnumNameSize > newEnumNames.length) { // case 2: Replace existing enumNames, remaining enumNames = enums
newEnumNames.forEach((value, index) => {
options[index].text = value;
});

options.forEach((option, index) => {
if(index >= newEnumNames.length) {
option.text = option.value;
}
})
} else { // case 3: Replace all existing enumNames
options.forEach((option, index) => {
option.text = newEnumNames[index];
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@
newEnumNames.forEach((value) => {
this.getWidgets().appendChild(this.#createRadioOption(value, value));
})
} else if(currentEnumNameSize > newEnumNames.length) {
[...this.getOptions()].forEach((option, index) => {
let span = option.querySelector('span');
let input = option.querySelector('input');
if(index < newEnumNames.length) {
span.textContent = newEnumNames[index];
} else {
span.textContent = input.value;
}
});
} else {
[...this.getOptions()].forEach((option, index) => {
let span = option.querySelector('span');
Expand Down

0 comments on commit b191a5c

Please sign in to comment.