-
Notifications
You must be signed in to change notification settings - Fork 22
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 #116 from bamlab/fix-error-when-recreating-node
fix(core): fix error when recreating node
- Loading branch information
Showing
8 changed files
with
166 additions
and
6 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ThemeProvider } from '@emotion/react'; | ||
import { render } from '@testing-library/react-native'; | ||
import { theme } from '../design-system/theme/theme'; | ||
import { ListWithVariableSize } from './ListWithVariableSize'; | ||
import { NavigationContainer } from '@react-navigation/native'; | ||
import '../components/tests/helpers/configureTestRemoteControl'; | ||
import testRemoteControlManager from '../components/tests/helpers/testRemoteControlManager'; | ||
|
||
jest.mock('../modules/program/infra/programInfos', () => ({ | ||
getPrograms: () => { | ||
return jest.requireActual('../modules/program/infra/programInfos').programInfos; | ||
}, | ||
})); | ||
|
||
const renderWithProviders = (page: JSX.Element) => { | ||
return render( | ||
<NavigationContainer> | ||
<ThemeProvider theme={theme}>{page}</ThemeProvider> | ||
</NavigationContainer>, | ||
); | ||
}; | ||
describe('ListWithVariableSize', () => { | ||
it('node is still focusable after being removed', () => { | ||
const screen = renderWithProviders(<ListWithVariableSize />); | ||
|
||
// Go to last programd and focus it | ||
testRemoteControlManager.handleRight(); | ||
testRemoteControlManager.handleRight(); | ||
testRemoteControlManager.handleRight(); | ||
expect(screen.getByLabelText('Program 4')).toBeSelected(); | ||
|
||
// Go back to first position | ||
testRemoteControlManager.handleLeft(); | ||
testRemoteControlManager.handleLeft(); | ||
testRemoteControlManager.handleLeft(); | ||
|
||
// Remove last item | ||
testRemoteControlManager.handleDown(); | ||
testRemoteControlManager.handleDown(); | ||
testRemoteControlManager.handleEnter(); | ||
|
||
expect(screen.queryByLabelText('Program 4')).not.toBeOnTheScreen(); | ||
|
||
// Add back last item | ||
testRemoteControlManager.handleUp(); | ||
testRemoteControlManager.handleEnter(); | ||
expect(screen.getByLabelText('Program 4')).toBeOnTheScreen(); | ||
|
||
// Focus last item | ||
testRemoteControlManager.handleUp(); | ||
testRemoteControlManager.handleRight(); | ||
testRemoteControlManager.handleRight(); | ||
testRemoteControlManager.handleRight(); | ||
|
||
expect(screen.getByLabelText('Program 4')).toBeSelected(); | ||
}); | ||
}); |
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,79 @@ | ||
import styled from '@emotion/native'; | ||
import { Page } from '../components/Page'; | ||
import { getPrograms } from '../modules/program/infra/programInfos'; | ||
import { SpatialNavigationView } from '../../../lib/src/spatial-navigation/components/View'; | ||
import { scaledPixels } from '../design-system/helpers/scaledPixels'; | ||
import { DefaultFocus } from '../../../lib/src/spatial-navigation/context/DefaultFocusContext'; | ||
import { SpatialNavigationNode } from '../../../lib/src/spatial-navigation/components/Node'; | ||
import { Spacer } from '../design-system/components/Spacer'; | ||
import { Button } from '../design-system/components/Button'; | ||
import { useState } from 'react'; | ||
import { ProgramList } from '../modules/program/view/ProgramList'; | ||
import { useTheme } from '@emotion/react'; | ||
|
||
const ROW_PADDING = scaledPixels(70); | ||
|
||
const MAX = 1000; | ||
|
||
export const ListWithVariableSize = () => { | ||
const theme = useTheme(); | ||
const [programsBase, setProgramsBase] = useState(getPrograms(MAX)); | ||
|
||
const [numberOfPrograms, setNumberOfPrograms] = useState(4); | ||
|
||
const addItem = () => { | ||
setNumberOfPrograms((prev) => { | ||
if (prev === MAX) return prev; | ||
|
||
return prev + 1; | ||
}); | ||
}; | ||
|
||
const removeItem = () => { | ||
setNumberOfPrograms((prev) => { | ||
if (prev === 0) return prev; | ||
return prev - 1; | ||
}); | ||
}; | ||
|
||
const shuffleItems = () => { | ||
setProgramsBase((prev) => [...prev].sort(() => Math.random() - 0.5)); | ||
}; | ||
|
||
const programs = programsBase.slice(0, numberOfPrograms); | ||
|
||
return ( | ||
<Page> | ||
<DefaultFocus> | ||
<Container> | ||
<SpatialNavigationNode orientation="horizontal"> | ||
<ListContainer> | ||
<ProgramList | ||
data={programs} | ||
listRef={null} | ||
containerStyle={{ height: theme.sizes.program.portrait.height + ROW_PADDING }} | ||
/> | ||
</ListContainer> | ||
</SpatialNavigationNode> | ||
<Spacer gap="$6" /> | ||
<SpatialNavigationView direction="vertical"> | ||
<Button label="Add item" onSelect={addItem} /> | ||
<Button label="Remove item" onSelect={removeItem} /> | ||
<Button label="Shuffle items" onSelect={shuffleItems} /> | ||
</SpatialNavigationView> | ||
</Container> | ||
</DefaultFocus> | ||
</Page> | ||
); | ||
}; | ||
|
||
const Container = styled.View({ | ||
flex: 1, | ||
padding: scaledPixels(30), | ||
}); | ||
|
||
const ListContainer = styled.View(({ theme }) => ({ | ||
flexDirection: 'row', | ||
gap: theme.spacings.$4, | ||
padding: theme.spacings.$4, | ||
})); |
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