diff --git a/README.md b/README.md index 13afdab..d61d768 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,9 @@ Source: [![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 diff --git a/strcalc/src/main/frontend/components/app.js b/strcalc/src/main/frontend/components/app.js index e909093..d923a57 100644 --- a/strcalc/src/main/frontend/components/app.js +++ b/strcalc/src/main/frontend/components/app.js @@ -10,7 +10,7 @@ * @module init */ -import Placeholder from './placeholder' +import Introduction from './introduction' import Calculator from './calculator' export default class App { @@ -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)) diff --git a/strcalc/src/main/frontend/components/app.test.js b/strcalc/src/main/frontend/components/app.test.js index 657d2ef..23ff050 100644 --- a/strcalc/src/main/frontend/components/app.test.js +++ b/strcalc/src/main/frontend/components/app.test.js @@ -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') }) diff --git a/strcalc/src/main/frontend/components/introduction.hbs b/strcalc/src/main/frontend/components/introduction.hbs new file mode 100644 index 0000000..98b6415 --- /dev/null +++ b/strcalc/src/main/frontend/components/introduction.hbs @@ -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 +--}} +

{{> message-link }}

+

+ This Tomcat + servlet testing example incorporates the + String Calculator kata to + demonstrate Test-Driven Development in the context of a + Test + Pyramid-based testing strategy. +

+
diff --git a/strcalc/src/main/frontend/components/placeholder.js b/strcalc/src/main/frontend/components/introduction.js similarity index 86% rename from strcalc/src/main/frontend/components/placeholder.js rename to strcalc/src/main/frontend/components/introduction.js index eb1e10e..a4fab77 100644 --- a/strcalc/src/main/frontend/components/placeholder.js +++ b/strcalc/src/main/frontend/components/introduction.js @@ -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 */ diff --git a/strcalc/src/main/frontend/components/placeholder.hbs b/strcalc/src/main/frontend/components/placeholder.hbs deleted file mode 100644 index 6c945b9..0000000 --- a/strcalc/src/main/frontend/components/placeholder.hbs +++ /dev/null @@ -1,9 +0,0 @@ -{{!-- - 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 ---}} -

{{> message-link }}

diff --git a/strcalc/src/main/frontend/main.test.js b/strcalc/src/main/frontend/main.test.js index 5aa130c..147b1f3 100644 --- a/strcalc/src/main/frontend/main.test.js +++ b/strcalc/src/main/frontend/main.test.js @@ -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') }) diff --git a/strcalc/src/main/frontend/test/page.js b/strcalc/src/main/frontend/test/page.js index 514a2b3..1b81d91 100644 --- a/strcalc/src/main/frontend/test/page.js +++ b/strcalc/src/main/frontend/test/page.js @@ -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"]') } diff --git a/strcalc/src/test/java/com/mike_bland/training/testing/stringcalculator/WebApplicationTest.java b/strcalc/src/test/java/com/mike_bland/training/testing/stringcalculator/WebApplicationTest.java index cd4ff6e..bca0596 100644 --- a/strcalc/src/test/java/com/mike_bland/training/testing/stringcalculator/WebApplicationTest.java +++ b/strcalc/src/test/java/com/mike_bland/training/testing/stringcalculator/WebApplicationTest.java @@ -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(