Skip to content

Commit

Permalink
Merge pull request #60 from mbland/change-placeholder-to-introduction
Browse files Browse the repository at this point in the history
Change Placeholder component to Introduction
  • Loading branch information
mbland authored Dec 18, 2023
2 parents 71f43f1 + 09204d6 commit 91b3040
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 26 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ Source: <https://github.com/mbland/tomcat-servlet-testing-example>
[![Test results](https://github.com/mbland/tomcat-servlet-testing-example/actions/workflows/publish-test-results.yaml/badge.svg)](https://github.com/mbland/tomcat-servlet-testing-example/actions/workflows/publish-test-results.yaml?branch=main)
[![Coverage Status](https://coveralls.io/repos/github/mbland/tomcat-servlet-testing-example/badge.svg?branch=main)][coveralls-tste]

This project will eventually incorporate the [String Calculator kata][] to
demonstrate Test-Driven Development and small unit tests in general. However, it
will illustrate a full, balanced, [Test Pyramid][] based testing strategy
incorporating developer written automated tests of all sizes (small, medium, and
large).
This project incorporates the [String Calculator kata][] to
demonstrate Test-Driven Development in the context of a [Test
Pyramid][]-based testing strategy.

Though I've been a programmer for years across many other programming languages,
I'm learning a lot about the Java ecosystem for the first time. It will take
Expand Down
4 changes: 2 additions & 2 deletions strcalc/src/main/frontend/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @module init
*/

import Placeholder from './placeholder'
import Introduction from './introduction'
import Calculator from './calculator'

export default class App {
Expand Down Expand Up @@ -39,7 +39,7 @@ export default class App {
// - Call init() on each object to do the actual work of setting up its
// initial application state within the document.
const components = [
new Placeholder(),
new Introduction(),
new Calculator()
]
components.forEach(c => c.init(params))
Expand Down
2 changes: 1 addition & 1 deletion strcalc/src/main/frontend/components/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('initial state after calling App.init()', () => {
test('contains the "Hello, World!" placeholder', async () => {
new App().init({ appElem: page.appElem })

const e = page.placeholder()
const e = page.title()
expect(e.textContent).toContain('Hello, World!')
expect(e.href).toContain('%22Hello,_World!%22')
})
Expand Down
18 changes: 18 additions & 0 deletions strcalc/src/main/frontend/components/introduction.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{!--
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/.
This is an example of a Handlebars template that invokes a partial template
via '{{>'. See: https://handlebarsjs.com/guide/partials.html#basic-partials
--}}
<h1 class="title">{{> message-link }}</h1>
<p class="introduction">
This <a href="https://github.com/mbland/tomcat-servlet-testing-example">Tomcat
servlet testing example</a> incorporates the
<a href="https://osherove.com/tdd-kata-1">String Calculator kata</a> to
demonstrate Test-Driven Development in the context of a
<a href="https://mike-bland.com/2023/08/31/the-test-pyramid-and-the-chain-reaction.html">Test
Pyramid</a>-based testing strategy.
</p>
<hr/>
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
* @module placeholder
*/

import Template from './placeholder.hbs'
import Template from './introduction.hbs'

export default class Placeholder {
export default class Introduction {
/**
* Initializes the Placeholder within the document.
* Initializes the Introduction within the document.
* @param {object} params - parameters made available to all initializers
* @param {Element} params.appElem - parent Element containing all components
*/
Expand Down
9 changes: 0 additions & 9 deletions strcalc/src/main/frontend/components/placeholder.hbs

This file was deleted.

2 changes: 1 addition & 1 deletion strcalc/src/main/frontend/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('String Calculator UI on initial page load', () => {
const { document } = await loader.load('index.html')
const appElem = document.querySelector('#app')

const e = new StringCalculatorPage(appElem, document).placeholder()
const e = new StringCalculatorPage(appElem, document).title()
expect(e.textContent).toContain('Hello, World!')
expect(e.href).toContain('%22Hello,_World!%22')
})
Expand Down
2 changes: 1 addition & 1 deletion strcalc/src/main/frontend/test/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class StringCalculatorPage {
clear() { this.appElem.replaceChildren() }
remove() { this.appElem.remove() }

placeholder() { return this.#select('.placeholder a') }
title() { return this.#select('.title a') }
form() { return this.#select('form') }
input() { return this.#select('form input[name="numbers"]') }
submit() { return this.#select('form input[type="submit"]') }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ String endpoint(String relPath) {
.toString();
}

// This placeholder test exists solely to allow the Gradle "test-large"
// task to pass until actual @LargeTests are present:
// This title test exists solely to allow the Gradle "test-large" task to
// pass until actual @LargeTests are present:
//
// - https://docs.gradle.org/8.4/userguide/upgrading_version_8.html#test_task_fail_on_no_test_executed
//
// Please replace or delete it when you're ready to add actual tests.
@LargeTest
void testPlaceholder() {
void testTitle() {
driver.get(endpoint("/"));

WebElement elem = driver.findElement(By.cssSelector("p.placeholder a"));
WebElement elem = driver.findElement(By.cssSelector("h1.title a"));

assertEquals("Hello, World!", elem.getText());
assertThat(
Expand Down

0 comments on commit 91b3040

Please sign in to comment.