Skip to content
Snippets Groups Projects
Commit 434d91d0 authored by Nathan Daelman's avatar Nathan Daelman
Browse files

Add `disabled` status to `Normalize Intensities` option in the DOS kebab menu.

Add tests for when option is enabled and disabled.
parent 79c28d31
No related branches found
No related tags found
1 merge request!1459Add check for `normalization_factors` for the `Normalize intensities` optino...
......@@ -21,7 +21,7 @@ import { useTheme } from '@material-ui/core/styles'
import { MoreVert } from '@material-ui/icons'
import Plot from '../plotting/Plot'
import { add, mergeObjects } from '../../utils'
import { Quantity, Unit } from '../../units'
import { Quantity, Unit, useUnits } from '../../units'
import { withErrorHandler } from '../ErrorHandler'
import { Action } from '../Actions'
import { msgNormalizationWarning } from '../../config'
......@@ -35,11 +35,12 @@ const DOS = React.memo(({
data,
layout,
className,
units,
type,
'data-testid': testID,
...other
}) => {
const units = useUnits()
// Merge custom layout with default layout
const initialLayout = useMemo(() => {
const defaultLayout = {
......@@ -212,7 +213,7 @@ const DOS = React.memo(({
data-testid={testID}
className={className}
actions={
<Action tooltip='Options' onClick={openMenu}>
<Action tooltip='Options' onClick={openMenu} data-testid="dos-options-menu">
<MoreVert/>
</Action>
}
......@@ -220,24 +221,25 @@ const DOS = React.memo(({
>
</Plot>
<Menu
id='settings-menu'
anchorEl={anchorEl}
getContentAnchorEl={null}
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
transformOrigin={{ vertical: 'top', horizontal: 'right' }}
keepMounted
open={open}
onClose={closeMenu}
open={open}
onClose={closeMenu}
>
<MenuItem key='normalization'>
<FormControlLabel control={
<Checkbox
onChange={() => {
setDosNormalize(data[0].normalization_factors ? (dosNormalize) => !dosNormalize : false)
}}
color="primary"
checked={dosNormalize}
/>
<FormControlLabel
control={
<Checkbox
onChange={() => {
setDosNormalize(data[0].normalization_factors ? (dosNormalize) => !dosNormalize : false)
}}
color="primary"
checked={dosNormalize}
disabled={!data?.[0]?.normalization_factors}
/>
}
label='Normalize intensities'
/>
......@@ -259,7 +261,6 @@ DOS.propTypes = {
]),
layout: PropTypes.object,
className: PropTypes.string,
units: PropTypes.object, // Contains the unit configuration
type: PropTypes.string, // Type of band structure: electronic or vibrational
'data-testid': PropTypes.string
}
......
/*
* Copyright The NOMAD Authors.
*
* This file is part of NOMAD. See https://nomad-lab.eu for further info.
*
* Licensed 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 React from 'react'
import userEvent from '@testing-library/user-event'
import { screen, renderNoAPI } from '../conftest.spec'
import DOS from './DOS'
test.each([
[
'no normalization factors',
[{
energies: [0.1, 0.2, 0.3, 0.4, 0.5],
densities: [[0.1, 0.2, 0.3, 0.4, 0.5]],
normalization_factors: undefined
}],
true
],
[
'with normalization factors',
[{
energies: [0.1, 0.2, 0.3, 0.4, 0.5],
densities: [[0.1, 0.2, 0.3, 0.4, 0.5]],
normalization_factors: [2.5]
}],
false
]
])('DOS: %s', async (id, data, normalization_disabled) => {
// Render component
renderNoAPI(<DOS data={data} />)
// Find menu element
const menuButton = screen.getByTestId('dos-options-menu')
// Click on menu to open options
await userEvent.click(menuButton)
// Assert that the normalization option is disabled or not
const normalizationOption = screen.getByLabelText('Normalize intensities')
if (normalization_disabled) {
expect(normalizationOption).toBeDisabled()
} else {
expect(normalizationOption).not.toBeDisabled()
}
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment