|
| 1 | +package de.codescape.bitvunit.rule.page; |
| 2 | + |
| 3 | +import de.codescape.bitvunit.rule.Violations; |
| 4 | +import org.junit.Test; |
| 5 | + |
| 6 | +import static de.codescape.bitvunit.test.Assertions.assertNoViolations; |
| 7 | +import static de.codescape.bitvunit.test.Assertions.assertViolations; |
| 8 | +import static de.codescape.bitvunit.util.html.HtmlPageUtil.toHtmlPage; |
| 9 | +import static org.junit.Assert.assertEquals; |
| 10 | +import static org.junit.Assert.assertNotNull; |
| 11 | + |
| 12 | +public class AvoidAbstractRoleRuleTest { |
| 13 | + |
| 14 | + private AvoidAbstractRoleRule rule = new AvoidAbstractRoleRule(); |
| 15 | + |
| 16 | + @Test |
| 17 | + public void ruleHasAName() throws Exception { |
| 18 | + assertNotNull(rule.getName()); |
| 19 | + assertEquals("AvoidAbstractRole", rule.getName()); |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + public void abstractRoleCommandPresentCausesViolation() throws Exception { |
| 24 | + abstractRoleWithRoleNamePresentCausesViolation("command"); |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + public void abstractRoleCompositePresentCausesViolation() throws Exception { |
| 29 | + abstractRoleWithRoleNamePresentCausesViolation("composite"); |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + public void abstractRoleInputPresentCausesViolation() throws Exception { |
| 34 | + abstractRoleWithRoleNamePresentCausesViolation("input"); |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + public void abstractRoleLandmarkPresentCausesViolation() throws Exception { |
| 39 | + abstractRoleWithRoleNamePresentCausesViolation("landmark"); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + public void abstractRoleRangePresentCausesViolation() throws Exception { |
| 44 | + abstractRoleWithRoleNamePresentCausesViolation("range"); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void abstractRoleRoletypePresentCausesViolation() throws Exception { |
| 49 | + abstractRoleWithRoleNamePresentCausesViolation("roletype"); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void abstractRoleSectionPresentCausesViolation() throws Exception { |
| 54 | + abstractRoleWithRoleNamePresentCausesViolation("section"); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + public void abstractRoleSectionheadPresentCausesViolation() throws Exception { |
| 59 | + abstractRoleWithRoleNamePresentCausesViolation("sectionhead"); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public void abstractRoleSelectPresentCausesViolation() throws Exception { |
| 64 | + abstractRoleWithRoleNamePresentCausesViolation("select"); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + public void abstractRoleStructurePresentCausesViolation() throws Exception { |
| 69 | + abstractRoleWithRoleNamePresentCausesViolation("structure"); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + public void abstractRoleWidgetPresentCausesViolation() throws Exception { |
| 74 | + abstractRoleWithRoleNamePresentCausesViolation("widget"); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + public void abstractRoleWindowPresentCausesViolation() throws Exception { |
| 79 | + abstractRoleWithRoleNamePresentCausesViolation("window"); |
| 80 | + } |
| 81 | + |
| 82 | + private void abstractRoleWithRoleNamePresentCausesViolation(String roleName) { |
| 83 | + String content = "<html><body><div role=\"" + roleName + "\">Content</div></body></html>"; |
| 84 | + Violations violations = rule.applyTo(toHtmlPage(content)); |
| 85 | + assertViolations(violations, rule, 1); |
| 86 | + } |
| 87 | + |
| 88 | + @Test |
| 89 | + public void landmarkRoleBannerPresentCausesNoViolation() throws Exception { |
| 90 | + String content = "<html><body><div role=\"banner\">Content</div></body></html>"; |
| 91 | + Violations violations = rule.applyTo(toHtmlPage(content)); |
| 92 | + assertNoViolations(violations, rule); |
| 93 | + } |
| 94 | + |
| 95 | +} |
0 commit comments