diff --git a/.idea/misc.xml b/.idea/misc.xml index deb38dc9ffe1028a483221c6e4d3c398ddb77a68..f322acf283d0a698d64668ae5b5819bdc7db421d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -9,4 +9,4 @@ </option> </component> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="temurin-17" project-jdk-type="JavaSDK" /> -</project> +</project> \ No newline at end of file diff --git a/src/main/resources/templates/list.html b/src/main/resources/templates/list.html index 7a3ce5c9823b99bd9143dd16dd245b08f188a02d..b3e4bbfc14879d90d64f5d271fdd98d6f7aa65bb 100644 --- a/src/main/resources/templates/list.html +++ b/src/main/resources/templates/list.html @@ -29,4 +29,12 @@ </div> <script th:src="@{/webjars/bootstrap/5.2.1/dist/js/bootstrap.bundle.js}"></script> </body> + +<footer> + <div> + <form> + <p class="text-muted" id="view_count">This list has been viewed 1 time.</p> + </form> + </div> +</footer> </html> diff --git a/src/test/java/com/example/sitodo/controller/TodoListControllerTest.java b/src/test/java/com/example/sitodo/controller/TodoListControllerTest.java index 1f38626d6e9d6219a3ff7ad02d5cbfbf0de215b1..04edff95b21a96c30c7066b74ad5a14eda2be966 100644 --- a/src/test/java/com/example/sitodo/controller/TodoListControllerTest.java +++ b/src/test/java/com/example/sitodo/controller/TodoListControllerTest.java @@ -162,6 +162,38 @@ class TodoListControllerTest { ); } + @Test + @DisplayName("First visit to /list should produce a correct string in the HTML page") + void showList_countFirstVisit() throws Exception { + mockMvc.perform(get("/list")) + .andExpectAll( + status().isOk(), + content().contentTypeCompatibleWith(TEXT_HTML), + content().encoding(UTF_8), + content().string(containsString("This list has been viewed 1 time")) + ); + } + + @Test + @DisplayName("Second visit to /list should produce a correct string in the HTML page") + void showList_countSecondVisit() throws Exception { + mockMvc.perform(get("/list")) + .andExpectAll( + status().isOk(), + content().contentTypeCompatibleWith(TEXT_HTML), + content().encoding(UTF_8), + content().string(containsString("This list has been viewed 1 time")) + ); + + mockMvc.perform(get("/list")) + .andExpectAll( + status().isOk(), + content().contentTypeCompatibleWith(TEXT_HTML), + content().encoding(UTF_8), + content().string(containsString("This list has been viewed 2 time")) + ); + } + private TodoList createMockTodoList(Long id, TodoItem ... items) { TodoList mockTodoList = mock(TodoList.class);