-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1459 from alliance-genome/SCRUM-3794
SCRUM-3794
- Loading branch information
Showing
10 changed files
with
164 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { useState } from 'react'; | ||
import { Dropdown } from "primereact/dropdown"; | ||
|
||
export function NotEditor({ props, value, editorChange }) { | ||
const [selectedValue, setSelectedValue] = useState(value); | ||
const textString = selectedValue ? "NOT" : ""; | ||
const options = [ | ||
{ label: "NOT", value: true }, | ||
]; | ||
|
||
const onChange = (e) => { | ||
let event; | ||
if(e.value === undefined){ | ||
event = { | ||
target: { | ||
value: false, | ||
name: e.target.name | ||
} | ||
} | ||
} else { | ||
event = e; | ||
} | ||
setSelectedValue(event.target.value); | ||
editorChange(event, props); | ||
} | ||
|
||
return ( | ||
<> | ||
<Dropdown | ||
aria-label='dropdown' | ||
name="negated" | ||
value={selectedValue} | ||
options={options} | ||
onChange={(e) => onChange(e)} | ||
showClear={true} | ||
placeholder={textString} | ||
style={{ width: '100%' }} | ||
/> | ||
</> | ||
); | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/cliapp/src/components/Editors/__tests__/NotEditor.test.js
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,64 @@ | ||
import { render, fireEvent, within } from '@testing-library/react'; | ||
import { NotEditor } from '../NotEditor'; | ||
import '../../../tools/jest/setupTests'; | ||
|
||
describe('NotEditor', () => { | ||
it('should display "NOT" as the placeholder text when the initial value is true', () => { | ||
const props = {}; | ||
const value = true; | ||
const editorChange = jest.fn(); | ||
|
||
const result = render(<NotEditor props={props} value={value} editorChange={editorChange} />); | ||
|
||
expect(result.getAllByText("NOT")).toHaveLength(2); | ||
}); | ||
|
||
it('should render a Dropdown component with no options when value prop is undefined', () => { | ||
const props = {}; | ||
const value = undefined; | ||
const editorChange = jest.fn(); | ||
|
||
const result = render(<NotEditor props={props} value={value} editorChange={editorChange} />); | ||
|
||
|
||
expect(result.getByText("empty")).toBeInTheDocument(); | ||
}); | ||
|
||
it('should update the selected value when an option is selected', () => { | ||
const props = {}; | ||
const value = false; | ||
const editorChange = jest.fn(); | ||
|
||
|
||
const result = render(<NotEditor props={props} value={value} editorChange={editorChange} />); | ||
const span = result.container.getElementsByTagName('span')[0]; | ||
|
||
expect(within(span).getByText('empty')).toBeInTheDocument(); | ||
|
||
fireEvent.click(span); | ||
|
||
const option = result.getAllByText('NOT'); | ||
fireEvent.click(option[0]); | ||
const updatedSpan = result.container.getElementsByTagName('span')[0]; | ||
|
||
|
||
expect(within(updatedSpan).getByText('NOT')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call editorChange when an option is selected', () => { | ||
const props = {}; | ||
const value = false; | ||
const editorChange = jest.fn(); | ||
const result = render(<NotEditor props={props} value={value} editorChange={editorChange} />); | ||
const span = result.container.getElementsByTagName('span')[0]; | ||
|
||
fireEvent.click(span); | ||
|
||
|
||
const option = result.getAllByText('NOT'); | ||
fireEvent.click(option[0]); | ||
|
||
expect(editorChange).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react' | ||
import { EllipsisTableCell } from '../EllipsisTableCell'; | ||
|
||
export const NotTemplate = ({ value }) => { | ||
if (value === null || value === undefined || typeof value !== 'boolean') return null; | ||
const textString = value ? "NOT" : ""; | ||
return <EllipsisTableCell>{textString}</EllipsisTableCell>; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/cliapp/src/components/Templates/__tests__/NotTemplate.test.js
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,25 @@ | ||
import { render } from '@testing-library/react'; | ||
import { NotTemplate } from '../NotTemplate'; | ||
import '../../../tools/jest/setupTests'; | ||
|
||
describe('NotTemplate', () => { | ||
|
||
it('should return null when value is null', () => { | ||
const { container } = render(<NotTemplate value={null} />); | ||
expect(container.firstChild).toBeNull(); | ||
}); | ||
|
||
it('should return a component with the text "NOT" when the value is true', () => { | ||
const { getByText } = render(<NotTemplate value={true} />); | ||
expect(getByText("NOT")).toBeInTheDocument(); | ||
}); | ||
it('should return a component with an empty string when the value is false', () => { | ||
const { container } = render(<NotTemplate value={false} />); | ||
expect(container.textContent).toBe(''); | ||
}); | ||
|
||
it('should return null when value is not a boolean', () => { | ||
const { container } = render(<NotTemplate value={123} />); | ||
expect(container.firstChild).toBeNull(); | ||
}); | ||
}); |
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
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