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

chore(tests): add array attach case #3068

Closed
wants to merge 4 commits into from
Closed
Changes from all 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
60 changes: 56 additions & 4 deletions packages/fiber/tests/core/renderer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,10 @@ describe('renderer', () => {

it('can swap 4 array primitives', async () => {
let state: RootState = null!
const a = new THREE.Group()
const b = new THREE.Group()
const c = new THREE.Group()
const d = new THREE.Group()
const a = Object.assign(new THREE.Group(), { name: 'a' })
const b = Object.assign(new THREE.Group(), { name: 'b' })
const c = Object.assign(new THREE.Group(), { name: 'c' })
const d = Object.assign(new THREE.Group(), { name: 'd' })
const array = [a, b, c, d]

const Test = ({ array }: { array: THREE.Group[] }) => (
Expand Down Expand Up @@ -546,6 +546,58 @@ describe('renderer', () => {
expect(state.scene.children[3]).toBe(c)
})

it('can swap 4 array primitives via attach', async () => {
let state: RootState = null!
const a = Object.assign(new THREE.Group(), { name: 'a' })
const b = Object.assign(new THREE.Group(), { name: 'b' })
const c = Object.assign(new THREE.Group(), { name: 'c' })
const d = Object.assign(new THREE.Group(), { name: 'd' })
const array = [a, b, c, d]

const Test = ({ array }: { array: THREE.Group[] }) => (
<>
{array.map((group, i) => (
<primitive key={i} attach={`userData-objects-${i}`} object={group} />
))}
</>
)

await act(async () => {
state = root.render(<Test array={array} />).getState()
})

expect(state.scene.children.length).toBe(0)
console.log(state.scene.userData.objects.map((o: any) => o.name))
expect(state.scene.userData.objects[0]).toBe(a)
expect(state.scene.userData.objects[1]).toBe(b)
expect(state.scene.userData.objects[2]).toBe(c)
expect(state.scene.userData.objects[3]).toBe(d)

const reversedArray = [...array.reverse()]

await act(async () => {
state = root.render(<Test array={reversedArray} />).getState()
})

expect(state.scene.children.length).toBe(0)
expect(state.scene.userData.objects[0]).toBe(d)
expect(state.scene.userData.objects[1]).toBe(c)
expect(state.scene.userData.objects[2]).toBe(b)
expect(state.scene.userData.objects[3]).toBe(a)

const mixedArray = [b, a, d, c]

await act(async () => {
state = root.render(<Test array={mixedArray} />).getState()
})

expect(state.scene.children.length).toBe(0)
expect(state.scene.userData.objects[0]).toBe(b)
expect(state.scene.userData.objects[1]).toBe(a)
expect(state.scene.userData.objects[2]).toBe(d)
expect(state.scene.userData.objects[3]).toBe(c)
})

it('will make an Orthographic Camera & set the position', async () => {
let camera: THREE.Camera = null!

Expand Down
Loading