@@ -26,10 +26,12 @@ const HORSE_GLB_PATH = assetPath('models/Horse.glb');
26
26
27
27
suite ( 'Loading' , ( ) => {
28
28
let element : ModelViewerElement ;
29
+ let firstChild : ChildNode | null ;
29
30
30
31
setup ( async ( ) => {
31
32
element = new ModelViewerElement ( ) ;
32
- document . body . insertBefore ( element , document . body . firstChild ) ;
33
+ firstChild = document . body . firstChild ;
34
+ document . body . insertBefore ( element , firstChild ) ;
33
35
element . poster = assetPath ( '../screenshot.png' ) ;
34
36
35
37
// Wait at least a microtask for size calculations
@@ -44,6 +46,57 @@ suite('Loading', () => {
44
46
}
45
47
} ) ;
46
48
49
+ suite ( 'with a second element outside the viewport' , ( ) => {
50
+ let element2 : ModelViewerElement ;
51
+
52
+ setup ( async ( ) => {
53
+ element2 = new ModelViewerElement ( ) ;
54
+ element2 . loading = 'eager' ;
55
+ document . body . insertBefore ( element2 , firstChild ) ;
56
+ element . style . height = '100vh' ;
57
+ element2 . style . height = '100vh' ;
58
+ const load1 = waitForEvent ( element , 'load' ) ;
59
+ const load2 = waitForEvent ( element2 , 'load' ) ;
60
+ element . src = CUBE_GLB_PATH ;
61
+ element2 . src = CUBE_GLB_PATH ;
62
+ await Promise . all ( [ load1 , load2 ] ) ;
63
+ } ) ;
64
+
65
+ teardown ( ( ) => {
66
+ if ( element2 . parentNode != null ) {
67
+ element2 . parentNode . removeChild ( element2 ) ;
68
+ }
69
+ } ) ;
70
+
71
+ test ( 'first element is visible' , ( ) => {
72
+ expect ( element . modelIsVisible ) . to . be . true ;
73
+ } ) ;
74
+
75
+ test ( 'second element is not visible' , ( ) => {
76
+ expect ( element2 . modelIsVisible ) . to . be . false ;
77
+ } ) ;
78
+
79
+ suite ( 'scroll to second element' , ( ) => {
80
+ setup ( ( ) => {
81
+ element2 . scrollIntoView ( ) ;
82
+ } ) ;
83
+
84
+ test ( 'first element is not visible' , async ( ) => {
85
+ await waitForEvent < CustomEvent > (
86
+ element ,
87
+ 'model-visibility' ,
88
+ event => event . detail . visible === false ) ;
89
+ } ) ;
90
+
91
+ test ( 'second element is visible' , async ( ) => {
92
+ await waitForEvent < CustomEvent > (
93
+ element2 ,
94
+ 'model-visibility' ,
95
+ event => event . detail . visible === true ) ;
96
+ } ) ;
97
+ } ) ;
98
+ } ) ;
99
+
47
100
test ( 'creates a poster element that captures interactions' , async ( ) => {
48
101
const picked = pickShadowDescendant ( element ) ;
49
102
expect ( picked ) . to . be . ok ;
0 commit comments