-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dropdown feature for Locale selection (#215)
* Add getLocales method to return locales list in PluginImpl (#211) * Update textbox to dropdown for locale selection (#211) * Add unit tests for PluginImpl (#211) * Add comments to getLocales() method (#211) * Use `f:select` and implement doFillSystemLocaleItems for better UI (#211) * Add `Use Browser Default` Locale option (#211) * Add `Use Browser Default` Locale option (#211) * Fix Unit tests and bug to handle empty systemLocale (#211) * Fix and Add Unit tests (#211) * Fix bug in PluginImpl - MigrationTest is failing (#211) * Add Jenkins supported Locales (#211) * Update test for doFillSystemLocaleItems() method (#211) * Fix the code using Spotless code style run (#211) * Add helper text to locale limit (#211) * Add test for systemLocale empty (#211) * remove ionicons-api dependency (#211)
- Loading branch information
1 parent
79fb6e3
commit d6a0be8
Showing
6 changed files
with
176 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/main/resources/hudson/plugins/locale/PluginImpl/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
<p>Only a limited number of locales are available due to project scope.</p> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package hudson.plugins.locale; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
|
||
import hudson.util.ListBoxModel; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Locale; | ||
import java.util.Set; | ||
import jenkins.model.Jenkins; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
public class PluginImplTest { | ||
|
||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
private PluginImpl plugin; | ||
|
||
@Before | ||
public void setUp() { | ||
plugin = Jenkins.get().getExtensionList(PluginImpl.class).get(0); | ||
} | ||
|
||
// Set of allowed locales for the test | ||
private static final Set<String> ALLOWED_LOCALES = new HashSet<>(Arrays.asList( | ||
"bg", "ca", "cs", "da", "de", "el", "en_GB", "es", "es_AR", "et", "fi", "fr", "he", "hu", "it", "ja", "ko", | ||
"lt", "lv", "nb_NO", "nl", "pl", "pt_BR", "pt_PT", "ro", "ru", "sk", "sl", "sr", "sv_SE", "tr", "uk", | ||
"zh_CN", "zh_TW")); | ||
|
||
@Test | ||
public void testDoFillSystemLocaleItems() { | ||
// Invoke the method | ||
ListBoxModel model = plugin.doFillSystemLocaleItems(); | ||
|
||
// Expected size of the ListBoxModel | ||
int expectedSize = ALLOWED_LOCALES.size() + 1; // +1 for the "Use Browser Locale" option | ||
|
||
// Verify the returned ListBoxModel size | ||
assertEquals("The returned ListBoxModel size is not as expected", expectedSize, model.size()); | ||
|
||
// Verify that the first option is "Use Browser Locale" | ||
String expectedFirstOption = String.format( | ||
"Use Browser Locale - %s (%s)", | ||
Locale.getDefault().getDisplayName(), Locale.getDefault().toString()); | ||
assertEquals("The first option should be 'Use Browser Locale'", expectedFirstOption, model.get(0).name); | ||
|
||
// Verify that the allowed locales are correctly added to the ListBoxModel, excluding the first option | ||
for (String localeStr : ALLOWED_LOCALES) { | ||
Locale locale = Locale.forLanguageTag(localeStr.replace('_', '-')); | ||
String expectedOption = String.format("%s - %s", locale.getDisplayName(), locale.toString()); | ||
|
||
boolean found = false; | ||
for (int i = 1; i < model.size(); i++) { // Start from 1 to skip the "Use Browser Locale" option | ||
if (model.get(i).name.equals(expectedOption)) { | ||
found = true; | ||
break; | ||
} | ||
} | ||
assertEquals("The ListBoxModel does not contain the expected locale: " + locale, true, found); | ||
} | ||
} | ||
|
||
@Test | ||
public void testSetSystemLocale() { | ||
// Test setting systemLocale | ||
String systemLocale = "en_US"; | ||
plugin.setSystemLocale(systemLocale); | ||
assertEquals(systemLocale, plugin.getSystemLocale()); | ||
} | ||
|
||
@Test | ||
public void testSetIgnoreAcceptLanguage() { | ||
// Test setting ignoreAcceptLanguage | ||
boolean ignoreAcceptLanguage = true; | ||
plugin.setIgnoreAcceptLanguage(ignoreAcceptLanguage); | ||
assertEquals(ignoreAcceptLanguage, plugin.isIgnoreAcceptLanguage()); | ||
} | ||
|
||
@Test | ||
public void testNullSystemLocale() { | ||
// Test setting systemLocale to null | ||
plugin.setSystemLocale(null); | ||
assertNull("System locale should be null", plugin.getSystemLocale()); | ||
} | ||
|
||
@Test | ||
public void testEmptySystemLocale() { | ||
// Test setting systemLocale to empty string | ||
plugin.setSystemLocale(""); | ||
assertNull("System locale should be empty", plugin.getSystemLocale()); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/test/resources/hudson/plugins/locale/MigrationTest.dataMigration_UnsetLocale/locale.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<locale plugin="[email protected]"> | ||
<ignoreAcceptLanguage>true</ignoreAcceptLanguage> | ||
</locale> |