Skip to content

Commit

Permalink
Merge branch 'main' into SimpleStyles
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegMoshkovich authored Sep 14, 2023
2 parents 2218e09 + e414495 commit 57168eb
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 27 deletions.
25 changes: 0 additions & 25 deletions cypress/e2e/navigation/navigation.cy.js

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bldrs",
"version": "1.0.0-r705",
"version": "1.0.0-r688",
"main": "src/index.jsx",
"license": "MIT",
"homepage": "https://github.com/bldrs-ai/Share",
Expand Down Expand Up @@ -72,8 +72,8 @@
"@bahmutov/cypress-esbuild-preprocessor": "^2.1.3",
"@mui/types": "^7.2.3",
"@pablo-mayrgundter/cookies.js": "^1.0.0",
"@svgr/webpack": "^8.0.1",
"@svgr/plugin-jsx": "^8.0.1",
"@svgr/webpack": "^8.0.1",
"@testing-library/cypress": "^9.0.0",
"@testing-library/dom": "^8.19.1",
"@testing-library/jest-dom": "^5.16.5",
Expand Down
17 changes: 17 additions & 0 deletions src/Components/InputAutocomplete.fixture.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import FixtureContext from '../FixtureContext'
import InputAutocomplete from './InputAutocomplete'


const elements = [
{title: 'Surfaces'},
{title: 'Case'},
{title: 'Gears'},
{title: 'Electonics'},
]

export default (
<FixtureContext>
<InputAutocomplete elements={elements} placeholder={'IFC property'}/>
</FixtureContext>
)
38 changes: 38 additions & 0 deletions src/Components/InputAutocomplete.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react'
import Autocomplete from '@mui/material/Autocomplete'
import TextField from '@mui/material/TextField'
import Stack from '@mui/material/Stack'
import {assertDefined} from '../utils/assert'

/**
* Input with autocomplete feature.
*
* @property {Array<object>} elements suggested elements used to autocomple input,the object is in a shape of {title:'suggestion'}
* @property {string} placeholder Input placeholder
* @property {string} size MUI size of the input component
* @return {React.Component}
*/
export default function InputAutocomplete({elements, placeholder, size = 'small'}) {
assertDefined(elements, placeholder)
return (
<Stack spacing={3} sx={{minWidth: '280px'}}>
<Autocomplete
multiple
options={elements}
getOptionLabel={(option) => option.title}
filterSelectedOptions
size={size}
renderInput={(params) => {
return (
<TextField
{...params}
placeholder={placeholder}
size={size}
/>
)
}
}
/>
</Stack>
)
}
41 changes: 41 additions & 0 deletions src/Components/InputAutocomplete.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react'
import {render, fireEvent} from '@testing-library/react'
import InputAutocomplete from './InputAutocomplete' // Adjust the import path


describe('InputAutocomplete', () => {
const elements = [
{title: 'Option 1'},
{title: 'Option 2'},
{title: 'Option 3'},
]

it('renders the input with placeholder', () => {
const placeholderText = 'Type something'
const {getByPlaceholderText} = render(
<InputAutocomplete elements={elements} placeholder={placeholderText}/>,
)
const inputElement = getByPlaceholderText(placeholderText)
expect(inputElement).toBeInTheDocument()
})

it('displays suggestions when typing', () => {
const {getByPlaceholderText, getByText} = render(
<InputAutocomplete elements={elements} placeholder="Type something"/>,
)

const inputElement = getByPlaceholderText('Type something')

// Type some text into the input
fireEvent.change(inputElement, {target: {value: 'Option'}})

// Wait for suggestions to appear
const suggestion1 = getByText('Option 1')
const suggestion2 = getByText('Option 2')
const suggestion3 = getByText('Option 3')

expect(suggestion1).toBeInTheDocument()
expect(suggestion2).toBeInTheDocument()
expect(suggestion3).toBeInTheDocument()
})
})

0 comments on commit 57168eb

Please sign in to comment.