pageTitle.mjs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { describe, it, before, after } from 'mocha'
  2. import { expect } from 'chai'
  3. import { By } from 'selenium-webdriver'
  4. import {
  5. getRootAndWait,
  6. takeScreenshotOnFailure,
  7. } from '../../lib/elements.js'
  8. describe('config: pageTitle', function () {
  9. before(async function () {
  10. await runner.start('pageTitle')
  11. })
  12. after(async () => {
  13. await runner.stop()
  14. })
  15. afterEach(function () {
  16. takeScreenshotOnFailure(this.currentTest, webdriver);
  17. });
  18. it('Init API returns custom pageTitle from config', async function () {
  19. await getRootAndWait()
  20. // Check that the Init API response (available via window.initResponse) contains pageTitle
  21. // This is how the frontend accesses it, so it's the most reliable way to test
  22. const initResponse = await webdriver.executeScript('return window.initResponse')
  23. expect(initResponse).to.not.be.null
  24. expect(initResponse).to.have.own.property('pageTitle')
  25. expect(initResponse.pageTitle).to.equal('Custom Test Title')
  26. })
  27. it('Header displays custom pageTitle from init response', async function () {
  28. await getRootAndWait()
  29. // Check that the pageTitle from init response is used in the header
  30. // First verify the init response has the correct pageTitle
  31. const pageTitle = await webdriver.executeScript('return window.initResponse?.pageTitle')
  32. expect(pageTitle).to.equal('Custom Test Title')
  33. // The Header component from picocrank should render the title prop
  34. // Check for the title in the header element
  35. const header = await webdriver.findElement(By.tagName('header'))
  36. const headerText = await header.getText()
  37. // The header should contain the custom page title
  38. expect(headerText).to.include('Custom Test Title')
  39. })
  40. })