Skip to content

Commit

Permalink
refactored media rule test
Browse files Browse the repository at this point in the history
  • Loading branch information
amartya4256 committed Dec 11, 2023
1 parent fe06271 commit 43a69c6
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.List;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import org.eclipse.e4.ui.tests.css.core.util.ParserTestUtil;
import org.junit.jupiter.api.Test;
Expand All @@ -40,12 +40,16 @@ void testMediaRule() throws Exception {
Label { background-color: #FF0000 }""";
CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css);
assertNotNull(styleSheet);
List<String> cssRules = IntStream.range(0, styleSheet.getCssRules().getLength())
.mapToObj(i -> styleSheet.getCssRules().item(i).getCssText()).toList();
// This one is provided only inside the @media so it shouldn't be there
assertThat(findCssRuleThatContains(styleSheet, "background-color")).isEmpty();
// This one is provided outside the @media and it shouldn't be overwritten by
// any of them
assertThat(findCssRuleThatContains(styleSheet, "line-height")).containsOnly("BODY { line-height: 1.3; }");
}

assertThat(cssRules.stream().filter(it -> it.contains("background-color")).toList())
.containsOnly("Label { background-color: rgb(255, 0, 0); }");
assertThat(cssRules.stream().filter(it -> it.contains("line-height")).toList())
.containsOnly("BODY { line-height: 1.3; }");
private Stream<String> findCssRuleThatContains(CSSStyleSheet styleSheet, String text) {
Stream<String> cssRulesText = IntStream.range(0, styleSheet.getCssRules().getLength())
.mapToObj(i -> styleSheet.getCssRules().item(i).getCssText());
return cssRulesText.filter(r -> r.contains(text));
}
}

0 comments on commit 43a69c6

Please sign in to comment.