Skip to content

Commit

Permalink
Merge pull request #44 from mbland/embed-fragment-call-in-strcalc-page
Browse files Browse the repository at this point in the history
Embed fragment() call in StringCalculatorPage
  • Loading branch information
mbland committed Dec 15, 2023
2 parents 3063291 + 41cb787 commit a242a64
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
9 changes: 4 additions & 5 deletions strcalc/src/main/frontend/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
*/
import initApp from './init'
import { describe, expect, test } from 'vitest'
import { fragment } from './test-helpers.js'
import StringCalculatorPage from './test-page.js'
import StringCalculatorPage from './test-page'

// @vitest-environment jsdom
describe('initial state after calling initApp', () => {
test('contains the "Hello, World!" placeholder', async () => {
const document = fragment('<div id="app"></div>')
const page = new StringCalculatorPage()

initApp(window, document)
initApp(window, page.document)

const e = new StringCalculatorPage(document).getPlaceholder()
const e = page.placeholder()
expect(e.textContent).toContain('Hello, World!')
expect(e.href).toContain('%22Hello,_World!%22')
})
Expand Down
6 changes: 3 additions & 3 deletions strcalc/src/main/frontend/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { describe, afterEach, expect, test } from 'vitest'
import { PageLoader } from './test-helpers.js'
import StringCalculatorPage from './test-page.js'
import { PageLoader } from './test-helpers'
import StringCalculatorPage from './test-page'

describe('String Calculator UI on initial page load', () => {
const loader = new PageLoader('/strcalc')
Expand All @@ -15,7 +15,7 @@ describe('String Calculator UI on initial page load', () => {
test('contains the "Hello, World!" placeholder', async () => {
const { document } = await loader.load('index.html')

const e = new StringCalculatorPage(document).getPlaceholder()
const e = new StringCalculatorPage(document).placeholder()
expect(e.textContent).toContain('Hello, World!')
expect(e.href).toContain('%22Hello,_World!%22')
})
Expand Down
10 changes: 6 additions & 4 deletions strcalc/src/main/frontend/test-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

import { fragment } from './test-helpers'

/**
* Represents the StringCalculator web page.
*
Expand All @@ -14,12 +16,12 @@
*/
export default class StringCalculatorPage {
document
#select

constructor(doc) {
this.document = doc
this.document = doc !== undefined ? doc : fragment('<div id="app"></div>')
this.#select = selector => this.document.querySelector(`#app ${selector}`)
}

getPlaceholder() {
return this.document.querySelector('#app .placeholder a')
}
placeholder() { return this.#select('.placeholder a') }
}

0 comments on commit a242a64

Please sign in to comment.