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

Open GitHub link valid link doesnt activate open button #1252

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d41ec01
add call back to the search component that is used to close open dial…
OlegMoshkovich Aug 6, 2024
2303c18
test search box is cleared when the search is closed and reopened
OlegMoshkovich Aug 6, 2024
e0f57ec
test search box is cleared when the search is closed and reopened
OlegMoshkovich Aug 6, 2024
4e93df9
add e2e to open model from open dialog
OlegMoshkovich Aug 6, 2024
c5957e7
clear permalink tests
OlegMoshkovich Aug 6, 2024
f2ed18f
clean up tests
OlegMoshkovich Aug 6, 2024
da2b3a3
clean up
OlegMoshkovich Aug 6, 2024
b311dc1
clean up
OlegMoshkovich Aug 6, 2024
0374b9e
Merge branch 'main' into 1223-open-github-link-valid-link-doesnt-acti…
OlegMoshkovich Aug 6, 2024
841a64e
Merge branch 'main' into 1223-open-github-link-valid-link-doesnt-acti…
OlegMoshkovich Aug 7, 2024
653dbb6
add call back to the search component that is used to close open dial…
OlegMoshkovich Aug 6, 2024
27d4cb7
test search box is cleared when the search is closed and reopened
OlegMoshkovich Aug 6, 2024
1c2ae8b
test search box is cleared when the search is closed and reopened
OlegMoshkovich Aug 6, 2024
a5d4731
add e2e to open model from open dialog
OlegMoshkovich Aug 6, 2024
c34f926
clear permalink tests
OlegMoshkovich Aug 6, 2024
fe5aa78
clean up tests
OlegMoshkovich Aug 6, 2024
dedaf9f
clean up
OlegMoshkovich Aug 6, 2024
fd11f0c
clean up
OlegMoshkovich Aug 6, 2024
0fcc50b
Merge branch '1223-open-github-link-valid-link-doesnt-activate-open-b…
OlegMoshkovich Aug 7, 2024
d7bdb14
add change the data test id
OlegMoshkovich Aug 7, 2024
18f5064
edit the test
OlegMoshkovich Aug 7, 2024
d27af22
adjust the tests to match the story description
OlegMoshkovich Aug 8, 2024
3b8b01a
add search test
OlegMoshkovich Aug 8, 2024
72e9521
clean up search elementName test
OlegMoshkovich Aug 8, 2024
f999024
subtract a minor space
OlegMoshkovich Aug 8, 2024
e755b30
Merge branch 'main' into 1223-open-github-link-valid-link-doesnt-acti…
OlegMoshkovich Aug 12, 2024
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
20 changes: 16 additions & 4 deletions cypress/e2e/open/100/open-project-from-gh-link.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,35 @@ import {
/** {@link https://github.com/bldrs-ai/Share/issues/765} */
describe('Open 100: Open Project From GitHub Link', () => {
beforeEach(homepageSetup)
context('Returning user visits homepage, enters Model URL into search', () => {
context('Returning user visits homepage, and uses URL to open a model', () => {
const interceptTag = 'ghModelLoad'
beforeEach(() => {
setIsReturningUser()
visitHomepageWaitForModel()
cy.get('[data-testid="control-button-search"]').click()
setupVirtualPathIntercept(
'/share/v/gh/Swiss-Property-AG/Momentum-Public/main/Momentum.ifc',
'/Momentum.ifc',
interceptTag,
)
})

it('Activates a search bar by clicking on the search control button, enters Model URL into search - Model loads - Screen', () => {
cy.get('[data-testid="control-button-search"]').click()
// Note this includes {enter} at end to simulate Enter keypress
cy.get('[data-testid="textfield-search-query"]')
.type('https://github.com/Swiss-Property-AG/Momentum-Public/blob/main/Momentum.ifc{enter}')
.type('https://github.com/Swiss-Property-AG/Momentum-Public/blob/main/Momentum.ifc{enter}')
waitForModelReady(interceptTag)
cy.percySnapshot()
})

it('Model loads - Screen', () => {
it(`Activates open dialog by clicking on the open control button,
activates Github tab,
enters Model URL into textbox and clicks activate button - Model loads - Screen`, () => {
cy.get('[data-testid="control-button-open"]').click()
cy.get('[data-testid="tab-github"]').click()
cy.get('[data-testid="textfield-search-query"]')
.type('https://github.com/Swiss-Property-AG/Momentum-Public/blob/main/Momentum.ifc')
cy.get('[data-testid="button-search-activate"]').click()
waitForModelReady(interceptTag)
cy.percySnapshot()
})
Expand Down
34 changes: 34 additions & 0 deletions cypress/e2e/search/100/elementName.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import '@percy/cypress'
import {
homepageSetup,
setIsReturningUser,
visitHomepageWaitForModel,
} from '../../../support/utils'


/** {@link https://github.com/bldrs-ai/Share/issues/1254} */
describe('Search 100: Search model based on element name ', () => {
beforeEach(() => {
homepageSetup()
setIsReturningUser()
})

context('Returning user visits homepage', () => {
beforeEach(() => {
visitHomepageWaitForModel()
cy.get('[data-testid="control-button-search"]').click()
})

it(`Open Search > Enter "together" > Press Enter >
Search box with query visible, "Together" items highlighted in tree and scene - Screen`, () => {
cy.get('[data-testid="textfield-search-query"]').type('together{enter}')
cy.percySnapshot()
})
it(`Open Search > Enter "together" > Click Activate Button >
Search box with query visible, "Together" items highlighted in tree and scene - Screen`, () => {
cy.get('[data-testid="textfield-search-query"]').type('together')
cy.get('[data-testid="button-search-activate"]').click()
cy.percySnapshot()
})
})
})
13 changes: 0 additions & 13 deletions cypress/e2e/search/100/permalink.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {waitForModelReady} from '../../../support/models'
import {
homepageSetup,
setIsReturningUser,
visitHomepageWaitForModel,
} from '../../../support/utils'


Expand All @@ -14,18 +13,6 @@ describe('Search 100: Permalink', () => {
setIsReturningUser()
})

context('Returning user visits homepage, Open Search > Enters "together"', () => {
beforeEach(() => {
visitHomepageWaitForModel()
cy.get('[data-testid="control-button-search"]').click()
cy.get('[data-testid="textfield-search-query"]').type('together{enter}')
})

it('Search box with query visible, "Together" items highlighted in tree and scene - Screen', () => {
cy.percySnapshot()
})
})

context('Returning user visits permalink to "together" search', () => {
beforeEach(() => {
cy.visit('/share/v/p/index.ifc?q=together#n:;s:')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bldrs",
"version": "1.0.1087",
"version": "1.0.1108",
"main": "src/index.jsx",
"license": "AGPL-3.0",
"homepage": "https://github.com/bldrs-ai/Share",
Expand Down
5 changes: 4 additions & 1 deletion src/Components/Open/OpenModelDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ export default function OpenModelDialog({
{ currentTab === 1 &&
<>
<>
<SearchBar placeholder='Model URL'
<SearchBar
placeholder='Model URL'
helperText='Paste GitHub file link to open the model'
cb={() => setIsDialogDisplayed(false)}
clearInput={true}
/>
</>
{isAuthenticated &&
Expand Down
20 changes: 14 additions & 6 deletions src/Components/Search/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import TextField from '@mui/material/TextField'
import {looksLikeLink, githubUrlOrPathToSharePath} from '../../net/github/utils'
import {handleBeforeUnload} from '../../utils/event'
import {navWithSearchParamRemoved} from '../../utils/navigate'
import CloseIcon from '@mui/icons-material/Close'
import ArrowForwardIcon from '@mui/icons-material/ArrowForward'


/**
Expand All @@ -16,17 +16,18 @@ import CloseIcon from '@mui/icons-material/Close'
*
* @property {string} placeholder Text to display when search bar is inactive
* @property {string} helperText Text to display under the TextField
* @property {Function} cb CallBack to be executed when the search is activated
* @property {boolean} clearInput Clear the search when the component is opened
* @return {ReactElement}
*/
export default function SearchBar({placeholder, helperText}) {
export default function SearchBar({placeholder, helperText, cb = {}, clearInput = false}) {
const location = useLocation()
const navigate = useNavigate()
const [searchParams, setSearchParams] = useSearchParams()
const [inputText, setInputText] = useState('')
const [error, setError] = useState('')
const searchInputRef = useRef(null)


useEffect(() => {
if (location.search) {
if (validSearchQuery(searchParams)) {
Expand All @@ -45,6 +46,12 @@ export default function SearchBar({placeholder, helperText}) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [searchParams])

useEffect(() => {
if (clearInput === true) {
setInputText('')
navWithSearchParamRemoved(navigate, location.pathname, QUERY_PARAM)
}
}, [navigate, location.pathname, clearInput])

const onSubmit = (event) => {
// Prevent form event bubbling and causing page reload.
Expand All @@ -59,6 +66,7 @@ export default function SearchBar({placeholder, helperText}) {
const modelPath = githubUrlOrPathToSharePath(inputText)
window.removeEventListener('beforeunload', handleBeforeUnload)
navigate(modelPath, {replace: true})
cb()
} catch (e) {
setError(`Please enter a valid url. Click on the LINK icon to learn more.`)
}
Expand Down Expand Up @@ -99,7 +107,6 @@ export default function SearchBar({placeholder, helperText}) {
value={inputText}
onChange={(_, newValue) => setInputText(newValue || '')}
onInputChange={(_, newInputValue) => setInputText(newInputValue || '')}
clearIcon={<CloseIcon className='icon-share'/>}
inputValue={inputText}
renderInput={(params) => (
<TextField
Expand All @@ -121,10 +128,11 @@ export default function SearchBar({placeholder, helperText}) {
<InputAdornment position="end">
<IconButton
aria-label="clear search"
onClick={() => setInputText('')}
onClick={onSubmit}
data-testid='button-search-activate'
sx={{height: '2em', width: '2em'}}
>
<CloseIcon
<ArrowForwardIcon
className="icon-share"
color='primary'
fontSize="small"
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Search/SearchBar.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ describe( 'SearchBar', () => {
})

it('SeachBar', () => {
// eslint-disable-next-line no-empty-function
render(<SearchBar onClickMenuCb={() => {}} isOpen={true} placeholder={'Search'}/>, {wrapper: RouteThemeCtx})
render(<SearchBar placeholder={'Search'}/>, {wrapper: RouteThemeCtx})
expect(screen.getByPlaceholderText('Search')).toBeInTheDocument()
expect(screen.getByTestId('button-search-activate')).toBeInTheDocument()
})
})
1 change: 0 additions & 1 deletion src/Containers/ControlsGroupAndDrawer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export default function ControlsGroupAndDrawer({
navigate={navigate}
isRepoActive={modelPath.repo !== undefined}
/>

<Box sx={{width: '100%'}}>
{isSearchEnabled && isSearchBarVisible && <SearchBar placeholder='Search'/>}
{isNavTreeEnabled &&
Expand Down
Loading