forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(a11y): allow user to pass custom description for screen readers (o…
…pensearch-project#1111) Fixes #1097
- Loading branch information
Showing
10 changed files
with
185 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+27 KB
...all-stories-test-cases-add-custom-description-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/osd-charts/src/chart_types/xy_chart/state/chart_state.a11y.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { Store } from 'redux'; | ||
|
||
import { MockGlobalSpec, MockSeriesSpec } from '../../../mocks/specs'; | ||
import { MockStore } from '../../../mocks/store/store'; | ||
import { GlobalChartState } from '../../../state/chart_state'; | ||
import { getSettingsSpecSelector } from '../../../state/selectors/get_settings_specs'; | ||
|
||
describe('custom description for screen readers', () => { | ||
let store: Store<GlobalChartState>; | ||
beforeEach(() => { | ||
store = MockStore.default(); | ||
MockStore.addSpecs( | ||
[ | ||
MockSeriesSpec.bar({ | ||
data: [ | ||
{ x: 1, y: 10 }, | ||
{ x: 2, y: 5 }, | ||
], | ||
}), | ||
MockGlobalSpec.settings(), | ||
], | ||
store, | ||
); | ||
}); | ||
it('should test defaults', () => { | ||
const state = store.getState(); | ||
const { description, useDefaultSummary } = getSettingsSpecSelector(state); | ||
expect(description).toBeUndefined(); | ||
expect(useDefaultSummary).toBeTrue(); | ||
}); | ||
it('should allow user to set a custom description for chart', () => { | ||
MockStore.addSpecs( | ||
[ | ||
MockGlobalSpec.settings({ | ||
description: 'This is sample Kibana data', | ||
}), | ||
], | ||
store, | ||
); | ||
const state = store.getState(); | ||
const { description } = getSettingsSpecSelector(state); | ||
expect(description).toBe('This is sample Kibana data'); | ||
}); | ||
it('should be able to disable generated descriptions', () => { | ||
MockStore.addSpecs( | ||
[ | ||
MockGlobalSpec.settings({ | ||
useDefaultSummary: false, | ||
}), | ||
], | ||
store, | ||
); | ||
const state = store.getState(); | ||
const { useDefaultSummary } = getSettingsSpecSelector(state); | ||
expect(useDefaultSummary).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/osd-charts/stories/test_cases/6_a11y_custom_description.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { boolean, text } from '@storybook/addon-knobs'; | ||
import React from 'react'; | ||
|
||
import { AreaSeries, Chart, ScaleType, Settings } from '../../src'; | ||
import { KIBANA_METRICS } from '../../src/utils/data_samples/test_dataset_kibana'; | ||
|
||
export const Example = () => { | ||
const automatedSeries = boolean('Use the default generated series types of charts for screen readers', true); | ||
const customDescriptionForScreenReaders = text('custom description for screen readers', ''); | ||
return ( | ||
<Chart className="story-chart"> | ||
<Settings description={customDescriptionForScreenReaders} useDefaultSummary={automatedSeries} /> | ||
<AreaSeries | ||
id="area" | ||
xScaleType={ScaleType.Time} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor={0} | ||
yAccessors={[1]} | ||
data={KIBANA_METRICS.metrics.kibana_os_load[0].data} | ||
/> | ||
</Chart> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters