-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CCMSPUI-468 | Refactor and Add tests
- Loading branch information
1 parent
d037c09
commit d17965d
Showing
5 changed files
with
109 additions
and
37 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...-govuk-dialect/src/main/java/uk/gov/laa/ccms/springboot/dialect/DatePickerAttributes.java
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,19 @@ | ||
package uk.gov.laa.ccms.springboot.dialect; | ||
|
||
/** | ||
* DatePickerAttributes. | ||
*/ | ||
public record DatePickerAttributes( | ||
String id, | ||
String name, | ||
String label, | ||
String hint, | ||
String errorMessage, | ||
String value, | ||
String minDate, | ||
String maxDate) { | ||
|
||
public boolean hasError() { | ||
return !errorMessage.isEmpty(); | ||
} | ||
} |
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
31 changes: 30 additions & 1 deletion
31
...rc/test/java/uk/gov/laa/ccms/springboot/dialect/MoJDatePickerElementTagProcessorTest.java
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 |
---|---|---|
@@ -1,7 +1,36 @@ | ||
package uk.gov.laa.ccms.springboot.dialect; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.thymeleaf.context.Context; | ||
import org.thymeleaf.spring6.SpringTemplateEngine; | ||
|
||
@SpringBootTest(classes = ThymeleafTestConfig.class) | ||
class MoJDatePickerElementTagProcessorTest { | ||
|
||
@Autowired | ||
private SpringTemplateEngine templateEngine; | ||
|
||
@Test | ||
void shouldRenderGovukButton() { | ||
|
||
Context context = new Context(); | ||
String renderedHtml = templateEngine.process("test-datepicker", context); | ||
assertThat(renderedHtml) | ||
.contains( | ||
"<div class=\"moj-datepicker\" data-module=\"moj-date-picker\" data-min-date=\"2000-01-01\" " + | ||
"data-max-date=\"2025-12-31\"><div class=\"govuk-form-group govuk-form-group--error\">" + | ||
"<label class=\"govuk-label\" for=\"dob\">Date of Birth</label><div id=\"dob-hint\" " + | ||
"class=\"govuk-hint\">For example, 01/01/2000.</div><p id=\"dob-error\" " + | ||
"class=\"govuk-error-message\"><span class=\"govuk-visually-hidden\">Error:</span> " + | ||
"Please enter a valid date of birth.</p><input class=\"govuk-input moj-js-datepicker-input " + | ||
"govuk-input--error\" id=\"dob\" name=\"dateOfBirth\" type=\"text\" " + | ||
"aria-describedby=\"dob-hint dob-error\" value=\"2024-01-01\" autocomplete=\"off\">" + | ||
"</div></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
20 changes: 20 additions & 0 deletions
20
...-ccms-spring-boot-starter-govuk-dialect/src/test/resources/templates/test-datepicker.html
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,20 @@ | ||
<!DOCTYPE html> | ||
<html xmlns:moj="http://www.thymeleaf.org" lang="EN"> | ||
<head> | ||
<title>Datepicker Test</title> | ||
</head> | ||
<body> | ||
|
||
<moj:datepicker | ||
id="dob" | ||
name="dateOfBirth" | ||
label="Date of Birth" | ||
hint="For example, 01/01/2000." | ||
errorMessage="Please enter a valid date of birth." | ||
minDate="2000-01-01" | ||
maxDate="2025-12-31" | ||
value="2024-01-01"> | ||
</moj:datepicker> | ||
|
||
</body> | ||
</html> |