Skip to content

Commit

Permalink
feat: add HasOrderedComponents in HTML layout elements (#9734)
Browse files Browse the repository at this point in the history
Closes #8188

This PR implements HasOrderedComponents for all common HTML layout elements:

- Aside
- Article
- Div
- Footer
- Header
- Main
- Nav
- Section

The test is created in the base test class to simplify the unit testing of all components. To make sure that the interface isn't removed by accident, every class implements the test explicitly and fails if the interface is removed.
  • Loading branch information
knoobie authored Jan 13, 2021
1 parent 36d4675 commit 46118cc
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.vaadin.flow.component.ClickNotifier;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasOrderedComponents;
import com.vaadin.flow.component.HtmlContainer;
import com.vaadin.flow.component.Tag;

Expand All @@ -27,7 +28,7 @@
* @since 1.0
*/
@Tag(Tag.ARTICLE)
public class Article extends HtmlContainer implements ClickNotifier<Article> {
public class Article extends HtmlContainer implements ClickNotifier<Article>, HasOrderedComponents {

/**
* Creates a new empty article.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.vaadin.flow.component.ClickNotifier;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasOrderedComponents;
import com.vaadin.flow.component.HtmlContainer;
import com.vaadin.flow.component.Tag;

Expand All @@ -27,7 +28,7 @@
* @since 1.0
*/
@Tag(Tag.ASIDE)
public class Aside extends HtmlContainer implements ClickNotifier<Aside> {
public class Aside extends HtmlContainer implements ClickNotifier<Aside>, HasOrderedComponents {

/**
* Creates a new empty aside.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.vaadin.flow.component.ClickNotifier;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasOrderedComponents;
import com.vaadin.flow.component.HtmlContainer;
import com.vaadin.flow.component.Tag;

Expand All @@ -27,7 +28,7 @@
* @since 1.0
*/
@Tag(Tag.DIV)
public class Div extends HtmlContainer implements ClickNotifier<Div> {
public class Div extends HtmlContainer implements ClickNotifier<Div>, HasOrderedComponents {

/**
* Creates a new empty div.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.vaadin.flow.component.ClickNotifier;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasOrderedComponents;
import com.vaadin.flow.component.HtmlContainer;
import com.vaadin.flow.component.Tag;

Expand All @@ -27,7 +28,7 @@
* @since 1.0
*/
@Tag(Tag.FOOTER)
public class Footer extends HtmlContainer implements ClickNotifier<Footer> {
public class Footer extends HtmlContainer implements ClickNotifier<Footer>, HasOrderedComponents {

/**
* Creates a new empty footer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.vaadin.flow.component.ClickNotifier;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasOrderedComponents;
import com.vaadin.flow.component.HtmlContainer;
import com.vaadin.flow.component.Tag;

Expand All @@ -27,7 +28,7 @@
* @since 1.0
*/
@Tag(Tag.HEADER)
public class Header extends HtmlContainer implements ClickNotifier<Header> {
public class Header extends HtmlContainer implements ClickNotifier<Header>, HasOrderedComponents {

/**
* Creates a new empty header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.vaadin.flow.component.ClickNotifier;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasOrderedComponents;
import com.vaadin.flow.component.HtmlContainer;
import com.vaadin.flow.component.Tag;

Expand All @@ -27,7 +28,7 @@
* @since 1.0
*/
@Tag(Tag.MAIN)
public class Main extends HtmlContainer implements ClickNotifier<Main> {
public class Main extends HtmlContainer implements ClickNotifier<Main>, HasOrderedComponents {

/**
* Creates a new empty main.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.vaadin.flow.component.ClickNotifier;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasOrderedComponents;
import com.vaadin.flow.component.HtmlContainer;
import com.vaadin.flow.component.Tag;

Expand All @@ -27,7 +28,7 @@
* @since 1.0
*/
@Tag(Tag.NAV)
public class Nav extends HtmlContainer implements ClickNotifier<Nav> {
public class Nav extends HtmlContainer implements ClickNotifier<Nav>, HasOrderedComponents {

/**
* Creates a new empty nav.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.vaadin.flow.component.ClickNotifier;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasOrderedComponents;
import com.vaadin.flow.component.HtmlContainer;
import com.vaadin.flow.component.Tag;

Expand All @@ -27,7 +28,7 @@
* @since 1.0
*/
@Tag(Tag.SECTION)
public class Section extends HtmlContainer implements ClickNotifier<Section> {
public class Section extends HtmlContainer implements ClickNotifier<Section>, HasOrderedComponents {

/**
* Creates a new empty section.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.vaadin.flow.component.html;

import org.junit.Test;

public class ArticleTest extends ComponentTest {
// Actual test methods in super class

Expand All @@ -23,4 +25,10 @@ protected void addProperties() {
// Component defines no new properties
}

@Test
@Override
public void testHasOrderedComponents() {
super.testHasOrderedComponents();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.vaadin.flow.component.html;

import org.junit.Test;

public class AsideTest extends ComponentTest {
// Actual test methods in super class

Expand All @@ -23,4 +25,10 @@ protected void addProperties() {
// Component defines no new properties
}

@Test
@Override
public void testHasOrderedComponents() {
super.testHasOrderedComponents();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.vaadin.flow.component.html;

import com.vaadin.flow.component.HasOrderedComponents;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
Expand Down Expand Up @@ -117,6 +118,25 @@ protected Component getComponent() {
return component;
}

protected void testHasOrderedComponents() {
if (!(component instanceof HasOrderedComponents)) {
Assert.fail("Component " + component.getClass() + " did not implement HasOrderedComponents anymore.");
}

HasOrderedComponents component = (HasOrderedComponents) this.component;
Assert.assertEquals(0, component.getComponentCount());

Paragraph firstChildren = new Paragraph("first children");
component.add(firstChildren);
Assert.assertEquals(firstChildren, component.getComponentAt(0));

Paragraph newFirstChildren = new Paragraph("new first children");
component.addComponentAtIndex(0, newFirstChildren);
Assert.assertEquals(newFirstChildren, component.getComponentAt(0));

Assert.assertEquals(1, component.indexOf(firstChildren));
}

@Test
public void testSetterGetterTypes() throws Exception {
for (ComponentProperty property : properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.vaadin.flow.component.html;

import org.junit.Test;

public class DivTest extends ComponentTest {

// Actual test methods in super class
Expand All @@ -24,4 +26,10 @@ protected void addProperties() {
// Component defines no new properties
}

@Test
@Override
public void testHasOrderedComponents() {
super.testHasOrderedComponents();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.vaadin.flow.component.html;

import org.junit.Test;

public class FooterTest extends ComponentTest {
// Actual test methods in super class

Expand All @@ -23,4 +25,10 @@ protected void addProperties() {
// Component defines no new properties
}

@Test
@Override
public void testHasOrderedComponents() {
super.testHasOrderedComponents();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.vaadin.flow.component.html;

import org.junit.Test;

public class HeaderTest extends ComponentTest {
// Actual test methods in super class

Expand All @@ -23,4 +25,10 @@ protected void addProperties() {
// Component defines no new properties
}

@Test
@Override
public void testHasOrderedComponents() {
super.testHasOrderedComponents();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.vaadin.flow.component.html;

import org.junit.Test;

public class MainTest extends ComponentTest {
// Actual test methods in super class

Expand All @@ -23,4 +25,10 @@ protected void addProperties() {
// Component defines no new properties
}

@Test
@Override
public void testHasOrderedComponents() {
super.testHasOrderedComponents();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.vaadin.flow.component.html;

import org.junit.Test;

public class NavTest extends ComponentTest {
// Actual test methods in super class

Expand All @@ -23,4 +25,10 @@ protected void addProperties() {
// Component defines no new properties
}

@Test
@Override
public void testHasOrderedComponents() {
super.testHasOrderedComponents();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.vaadin.flow.component.html;

import org.junit.Test;

public class SectionTest extends ComponentTest {
// Actual test methods in super class

Expand All @@ -23,4 +25,10 @@ protected void addProperties() {
// Component defines no new properties
}

@Test
@Override
public void testHasOrderedComponents() {
super.testHasOrderedComponents();
}

}

0 comments on commit 46118cc

Please sign in to comment.