Skip to content
Snippets Groups Projects

Additional Gui test for edit quantity

Merged Mohammad Nakhaee requested to merge GUI_Test_EditQuantity into v1.1.0
2 files
+ 43
17
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -19,32 +19,52 @@
@@ -19,32 +19,52 @@
import React from 'react'
import React from 'react'
import {
import {
render,
render,
screen,
screen, wait
startAPI,
closeAPI
} from '../conftest.spec'
} from '../conftest.spec'
import {EditQuantityExamples} from './EditQuantityExamples'
import {EditQuantityExamples} from './EditQuantityExamples'
import {within} from '@testing-library/dom'
import {within} from '@testing-library/dom'
import {fireEvent, waitFor} from '@testing-library/react'
import {fireEvent, waitFor} from '@testing-library/react'
test('correctly renders edit quantities', async () => {
test('correctly renders edit quantities', async () => {
closeAPI()
await startAPI('tests.states.entry.dft', 'tests/data/entry/dft')
render(<EditQuantityExamples />)
render(<EditQuantityExamples />)
// Wait to load the entry metadata, i.e. wait for some texts to appear
// Wait to load the entry metadata, i.e. wait for some texts to appear
await screen.findByText('three')
await screen.findByText('three')
const numberFieldValue = screen.queryAllByTestId('number-edit-quantity-value')
const numberFieldValue = screen.queryAllByTestId('number-edit-quantity-value')
const numberFieldValueInput = within(numberFieldValue[0]).getByRole('textbox')
const numberFieldValueInput = within(numberFieldValue[1]).getByRole('textbox')
 
const numberFieldUnit = screen.queryAllByTestId('number-edit-quantity-unit')
 
const numberFieldUnitInput = within(numberFieldUnit[0]).getByRole('textbox', { hidden: true })
 
const numberFieldCheckBoxs = screen.queryAllByTitle('If checked, numeric value is converted when the unit is changed.')
 
const numberFieldCheckBox = within(numberFieldCheckBoxs[0]).getByRole('checkbox', { hidden: true })
 
await waitFor(() => expect(numberFieldUnitInput.value).toEqual('bohr'))
 
 
// First test read mode
 
await waitFor(() => expect(numberFieldCheckBox.checked).toBe(true))
 
fireEvent.change(numberFieldValueInput, { target: { value: '1.5' } })
fireEvent.change(numberFieldValueInput, { target: { value: '1.5' } })
 
await waitFor(() => expect(screen.queryByText(/"float_unit": 7\.937658163559664e-11/i)).toBeInTheDocument())
 
 
fireEvent.change(numberFieldUnitInput, { target: { value: 'angstrom' } })
 
await waitFor(() => expect(numberFieldValueInput.value).toEqual('0.7937658163559663'))
 
await waitFor(() => expect(screen.queryByText(/"float_unit": 7\.937658163559664e-11/i)).toBeInTheDocument())
 
 
fireEvent.change(numberFieldValueInput, { target: { value: '1.5m' } })
await waitFor(() => expect(numberFieldValueInput.value).toEqual('1.5'))
await waitFor(() => expect(numberFieldValueInput.value).toEqual('1.5'))
 
await waitFor(() => expect(numberFieldUnitInput.value).toEqual('meter'))
 
await waitFor(() => expect(screen.queryByText(/"float_unit": 1\.5/i)).toBeInTheDocument())
const numberFieldUnit = screen.queryAllByTestId('number-edit-quantity-unit')
// now test write mode
const numberFieldUnitButton = within(numberFieldUnit[0]).getByRole('button')
fireEvent.click(numberFieldCheckBox)
fireEvent.click(numberFieldUnitButton)
await wait(undefined, 100)
// fireEvent.change(numberFieldUnit[0], { target: { value: 'm' } })
await waitFor(() => expect(numberFieldCheckBox.checked).toBe(false))
// await waitFor(() => expect(numberFieldValueInput.value).toEqual('7.937658163559664e-11'))
 
fireEvent.change(numberFieldUnitInput, { target: { value: 'bohr' } })
 
await waitFor(() => expect(screen.queryByText(/"float_unit": 7\.937658163559664e-11/i)).toBeInTheDocument())
 
await waitFor(() => expect(numberFieldValueInput.value).toEqual('1.5'))
closeAPI()
fireEvent.change(numberFieldValueInput, { target: { value: '1.5angstrom' } })
 
await waitFor(() => expect(numberFieldValueInput.value).toEqual('1.5'))
 
await waitFor(() => expect(numberFieldUnitInput.value).toEqual('angstrom'))
 
await waitFor(() => expect(screen.queryByText(/"float_unit": 1\.5e-10/i)).toBeInTheDocument())
})
})
Loading