Skip to content
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

fix: input: ensure id passed from props does not append uuid #532

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/components/Inputs/TextArea/TextArea.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Enzyme, { mount } from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import MatchMediaMock from 'jest-matchmedia-mock';
import { TextArea } from './TextArea';
import { render } from '@testing-library/react';

Enzyme.configure({ adapter: new Adapter() });

Expand All @@ -15,11 +16,16 @@ describe('TextArea', () => {
afterEach(() => {
matchMedia.clear();
});
/*
* Functionality Tests
*/
test('text input renders', () => {

test('text area renders', () => {
const wrapper = mount(<TextArea />);
expect(wrapper.containsMatchingElement(<TextArea />)).toEqual(true);
});

test('text area id does not append uuid when from props', () => {
const { container } = render(<TextArea id="textAreaTest" />);
expect(
container.getElementsByTagName('textarea')[0].getAttribute('id')
).toBe('textAreaTest');
});
});
2 changes: 1 addition & 1 deletion src/components/Inputs/TextArea/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const TextArea: FC<TextAreaProps> = React.forwardRef(

const htmlDir: string = useCanvasDirection();

const textAreaId: string = uniqueId(id || 'textarea-');
const textAreaId: string = !!id ? id : uniqueId('textarea-');
const [inputValue, setInputValue] = useState(value);

const {
Expand Down
12 changes: 9 additions & 3 deletions src/components/Inputs/TextInput/TextInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Enzyme, { mount } from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import MatchMediaMock from 'jest-matchmedia-mock';
import { TextInput } from './TextInput';
import { render } from '@testing-library/react';

Enzyme.configure({ adapter: new Adapter() });

Expand All @@ -15,11 +16,16 @@ describe('TextInput', () => {
afterEach(() => {
matchMedia.clear();
});
/*
* Functionality Tests
*/

test('text input renders', () => {
const wrapper = mount(<TextInput />);
expect(wrapper.containsMatchingElement(<TextInput />)).toEqual(true);
});

test('text input id does not append uuid when from props', () => {
const { container } = render(<TextInput id="textInputTest" />);
expect(container.getElementsByTagName('input')[0].getAttribute('id')).toBe(
'textInputTest'
);
});
});
2 changes: 1 addition & 1 deletion src/components/Inputs/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const TextInput: FC<TextInputProps> = React.forwardRef(
const [inputValue, setInputValue] = useState(value);

const [clearButtonShown, _setClearButtonShown] = useState<boolean>(false);
const inputId: string = uniqueId(id || 'input-');
const inputId: string = !!id ? id : uniqueId('input-');

const clearButtonRef: React.MutableRefObject<HTMLButtonElement> =
useRef<HTMLButtonElement>(null);
Expand Down