beforeAll(() => {
  require('../../app/assets/javascripts/autofocus.js');
});

afterAll(() => {
  require('./support/teardown.js');
});

describe('Autofocus', () => {

  let focusHandler;
  let search;

  beforeEach(() => {

    // set up DOM
    document.body.innerHTML =
      `<div>
        <label class="form-label" for="search">
          Search by name
        </label>
        <input autocomplete="off" class="form-control form-control-1-1" id="search" name="search" type="search" value="" data-module="autofocus">
      </div>`;

    focusHandler = jest.fn();
    search = document.getElementById('search');
    search.addEventListener('focus', focusHandler, false);

  });

  afterEach(() => {

    document.body.innerHTML = '';
    search.removeEventListener('focus', focusHandler);
    focusHandler = null;

  });

  test('is focused when modules start', () => {

    // start module
    window.GOVUK.modules.start();

    expect(focusHandler).toHaveBeenCalled();

  });

  test('is not focused if the window has scrolled', () => {

    // mock the window being scrolled 25px
    $.prototype.scrollTop = jest.fn(() => 25);

    // start module
    window.GOVUK.modules.start();

    expect(focusHandler).not.toHaveBeenCalled();

  });

  test('is focused if the window has scrolled but the force-focus flag is set', () => {

    // mock the window being scrolled 25px
    $.prototype.scrollTop = jest.fn(() => 25);

    // set the force-focus flag
    document.querySelector('#search').setAttribute('data-force-focus', true);

    // start module
    window.GOVUK.modules.start();

    expect(focusHandler).toHaveBeenCalled();

  });

});

@@ -1,12 +1,62 @@
+const helpers = require('./support/helpers.js');%0A%0A
 beforeAll(()
@@ -211,16 +211,54 @@
 ) =%3E %7B%0A%0A
+  const labelText = 'Search by name';%0A
   let fo
@@ -298,32 +298,95 @@
 reEach(() =%3E %7B%0A%0A
+    document.title = 'Find services by name - GOV.UK Notify';%0A%0A
     // set up DO
@@ -488,30 +488,28 @@
         
-Search by name
+$%7BlabelText%7D
 %0A       
@@ -1064,32 +1064,32 @@
 dules.start();%0A%0A
-
     expect(focus
@@ -1117,32 +1117,595 @@
 lled();%0A%0A  %7D);%0A%0A
+  test('has a label including the page title when the module starts', () =%3E %7B%0A%0A    // start module%0A    window.GOVUK.modules.start();%0A%0A    expect(search.hasAttribute('aria-label')).toBe(true);%0A    expect(search.getAttribute('aria-label')).toEqual(document.title + ' - ' + labelText);%0A%0A  %7D);%0A%0A  test('gets the original label back when focus moves away', () =%3E %7B%0A%0A    // start module%0A    window.GOVUK.modules.start();%0A%0A    // shift focus away from textbox%0A    helpers.triggerEvent(search, 'blur');%0A%0A    expect(search.hasAttribute('aria-label')).toBe(false);%0A%0A  %7D);%0A%0A
   test('is not f

Add tests for changes to label