Skip to content

Commit

Permalink
Fix cropper not loading correctly
Browse files Browse the repository at this point in the history
* try to fix flaky test
  • Loading branch information
strangelookingnerd committed Nov 28, 2024
1 parent 814555b commit 33dc6f0
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/test/java/jenkins/plugins/foldericon/UITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.cloudbees.hudson.plugins.folder.Folder;
import hudson.FilePath;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.htmlunit.WebAssert;
Expand All @@ -19,6 +20,7 @@
import org.htmlunit.html.HtmlOption;
import org.htmlunit.html.HtmlPage;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;

Expand Down Expand Up @@ -87,6 +89,7 @@ void customFolderIconOption(JenkinsRule r) throws Throwable {
* @throws Throwable in case anything goes wrong
*/
@Test
@Timeout(value = 60, unit = TimeUnit.SECONDS)
void customFolderIconCroppieLoaded(JenkinsRule r) throws Throwable {
Folder project = r.jenkins.createProject(Folder.class, "folder");

Expand All @@ -106,13 +109,21 @@ void customFolderIconCroppieLoaded(JenkinsRule r) throws Throwable {
assertTrue(selection.isSelected());
r.submit(form);

configure = (HtmlPage) configure.refresh();
DomElement cropper = configure.getElementById("custom-icon-cropper");
assertNotNull(cropper);
String src = null;

// the test is a little flaky for reasons I do not understand
while (StringUtils.isEmpty(src)) {
configure = (HtmlPage) configure.refresh();
DomElement cropper = configure.getElementById("custom-icon-cropper");
assertNotNull(cropper);

if (!cropper.getElementsByTagName("img").isEmpty()) {
DomElement image = cropper.getElementsByTagName("img").get(0);
src = image.getAttribute("src");
}
}

DomElement image = cropper.getElementsByTagName("img").get(0);
assertNotNull(image);
assertEquals("/jenkins/plugin/custom-folder-icon/icons/default.svg", image.getAttribute("src"));
assertEquals("/jenkins/plugin/custom-folder-icon/icons/default.svg", src);
}
}

Expand Down

0 comments on commit 33dc6f0

Please sign in to comment.