-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Discover] Added focus to h1 element when client side routing is executed #133846
Changes from all commits
3154844
e1a1f8a
4ce0331
cadf625
a3b7080
f4d2911
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,11 @@ import { DiscoverServices } from '../../../../build_services'; | |
|
||
setHeaderActionMenuMounter(jest.fn()); | ||
|
||
function mountComponent(indexPattern: DataView, prevSidebarClosed?: boolean) { | ||
function mountComponent( | ||
indexPattern: DataView, | ||
prevSidebarClosed?: boolean, | ||
mountOptions: { attachTo?: HTMLElement } = {} | ||
) { | ||
const searchSourceMock = createSearchSourceMock({}); | ||
const services = { | ||
...discoverServiceMock, | ||
|
@@ -159,7 +163,8 @@ function mountComponent(indexPattern: DataView, prevSidebarClosed?: boolean) { | |
return mountWithIntl( | ||
<KibanaContextProvider services={services}> | ||
<DiscoverLayout {...(props as DiscoverLayoutProps)} /> | ||
</KibanaContextProvider> | ||
</KibanaContextProvider>, | ||
mountOptions | ||
); | ||
} | ||
|
||
|
@@ -174,6 +179,17 @@ describe('Discover component', () => { | |
expect(component.find('[data-test-subj="discoverChartOptionsToggle"]').exists()).toBeTruthy(); | ||
}); | ||
|
||
test('the saved search title h1 gains focus on navigate', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kertal I added some functional tests for accessibility which make this test sort of redundant. Do you think I should rollback changes to this test file or keep it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's fine to keep it as a unit test too |
||
const container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
const component = mountComponent(indexPatternWithTimefieldMock, undefined, { | ||
attachTo: container, | ||
}); | ||
expect( | ||
component.find('[data-test-subj="discoverSavedSearchTitle"]').getDOMNode() | ||
).toHaveFocus(); | ||
}); | ||
|
||
describe('sidebar', () => { | ||
test('should be opened if discover:sidebarClosed was not set', () => { | ||
const component = mountComponent(indexPatternWithTimefieldMock, undefined); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
|
||
import { FtrProviderContext } from '../../ftr_provider_context'; | ||
|
||
export default function ({ getService, getPageObjects }: FtrProviderContext) { | ||
const browser = getService('browser'); | ||
const log = getService('log'); | ||
const esArchiver = getService('esArchiver'); | ||
const kibanaServer = getService('kibanaServer'); | ||
const find = getService('find'); | ||
const testSubjects = getService('testSubjects'); | ||
const PageObjects = getPageObjects(['common', 'discover', 'header', 'timePicker']); | ||
|
||
const defaultSettings = { | ||
defaultIndex: 'logstash-*', | ||
}; | ||
|
||
describe('discover accessibility', () => { | ||
before(async () => { | ||
log.debug('load kibana index with default index pattern'); | ||
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover'); | ||
// and load a set of makelogs data | ||
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional'); | ||
await kibanaServer.uiSettings.replace(defaultSettings); | ||
await PageObjects.common.navigateToApp('discover'); | ||
}); | ||
|
||
after(async () => { | ||
await kibanaServer.savedObjects.clean({ types: ['search', 'index-pattern'] }); | ||
}); | ||
|
||
it('should give focus to the saved search title h1 on navigate', async () => { | ||
const titleElement = await testSubjects.find('discoverSavedSearchTitle'); | ||
const activeElement = await find.activeElement(); | ||
expect(await titleElement.getAttribute('data-test-subj')).to.eql( | ||
await activeElement.getAttribute('data-test-subj') | ||
); | ||
}); | ||
|
||
it('should give focus to the data view switch link when Tab is pressed', async () => { | ||
await browser.pressKeys(browser.keys.TAB); | ||
const dataViewSwitchLink = await testSubjects.find('discover-dataView-switch-link'); | ||
const activeElement = await find.activeElement(); | ||
expect(await dataViewSwitchLink.getAttribute('data-test-subj')).to.eql( | ||
await activeElement.getAttribute('data-test-subj') | ||
); | ||
}); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toHaveFocus
doesn't work without the component being mounted to an element in the body, so I addedmountOptions
to pass in a mount point.