1
1
import htmlKeyboardResponse from "@jspsych/plugin-html-keyboard-response" ;
2
2
import { pressKey , startTimeline } from "@jspsych/test-utils" ;
3
3
4
- import { initJsPsych } from "../../src" ;
4
+ import { initJsPsych , JsPsych } from "../../src" ;
5
5
6
6
describe ( "automatic progress bar" , ( ) => {
7
7
test ( "progress bar does not display by default" , async ( ) => {
8
- await startTimeline ( [
8
+ const { jsPsych } = await startTimeline ( [
9
9
{
10
10
type : htmlKeyboardResponse ,
11
11
stimulus : "foo" ,
12
12
} ,
13
13
] ) ;
14
14
15
- expect ( document . querySelector ( "#jspsych-progressbar-container" ) ) . toBeNull ( ) ;
15
+ expect ( jsPsych . getDisplayContainerElement ( ) . querySelector ( "#jspsych-progressbar-container" ) )
16
+ . toBeNull ( ) ;
16
17
await pressKey ( "a" ) ;
17
18
} ) ;
18
19
19
20
test ( "progress bar displays when show_progress_bar is true" , async ( ) => {
20
- await startTimeline (
21
+ const { jsPsych } = await startTimeline (
21
22
[
22
23
{
23
24
type : htmlKeyboardResponse ,
@@ -27,9 +28,10 @@ describe("automatic progress bar", () => {
27
28
{ show_progress_bar : true }
28
29
) ;
29
30
30
- expect ( document . querySelector ( "#jspsych-progressbar-container" ) . innerHTML ) . toMatch (
31
- '<span>Completion Progress</span><div id="jspsych-progressbar-outer"><div id="jspsych-progressbar-inner" style="width: 0%;"></div></div>'
32
- ) ;
31
+ expect ( jsPsych . getDisplayContainerElement ( ) . querySelector ( "#jspsych-progressbar-container" ) . innerHTML )
32
+ . toMatch (
33
+ '<span>Completion Progress</span><div id="jspsych-progressbar-outer"><div id="jspsych-progressbar-inner" style="width: 0%;"></div></div>'
34
+ ) ;
33
35
} ) ;
34
36
35
37
test ( "progress bar automatically updates by default" , async ( ) => {
@@ -38,9 +40,13 @@ describe("automatic progress bar", () => {
38
40
stimulus : "foo" ,
39
41
} ;
40
42
41
- await startTimeline ( [ trial , trial , trial , trial ] , { show_progress_bar : true } ) ;
43
+ const { jsPsych } = await startTimeline (
44
+ [ trial , trial , trial , trial ] ,
45
+ { show_progress_bar : true }
46
+ ) ;
42
47
43
- const progressbarElement = document . querySelector < HTMLElement > ( "#jspsych-progressbar-inner" ) ;
48
+ const progressbarElement =
49
+ jsPsych . getDisplayContainerElement ( ) . querySelector < HTMLElement > ( "#jspsych-progressbar-inner" ) ;
44
50
45
51
expect ( progressbarElement . style . width ) . toEqual ( "0%" ) ;
46
52
await pressKey ( "a" ) ;
@@ -59,12 +65,13 @@ describe("automatic progress bar", () => {
59
65
stimulus : "foo" ,
60
66
} ;
61
67
62
- await startTimeline ( [ trial , trial , trial , trial ] , {
68
+ const { jsPsych } = await startTimeline ( [ trial , trial , trial , trial ] , {
63
69
show_progress_bar : true ,
64
70
auto_update_progress_bar : false ,
65
71
} ) ;
66
72
67
- const progressbarElement = document . querySelector < HTMLElement > ( "#jspsych-progressbar-inner" ) ;
73
+ const progressbarElement =
74
+ jsPsych . getDisplayContainerElement ( ) . querySelector < HTMLElement > ( "#jspsych-progressbar-inner" ) ;
68
75
69
76
for ( let i = 0 ; i < 4 ; i ++ ) {
70
77
expect ( progressbarElement . style . width ) . toEqual ( "0%" ) ;
@@ -74,7 +81,7 @@ describe("automatic progress bar", () => {
74
81
} ) ;
75
82
76
83
test ( "set `progressBar.progress` manually" , async ( ) => {
77
- const jsPsych = initJsPsych ( {
84
+ const jsPsychObject = initJsPsych ( {
78
85
show_progress_bar : true ,
79
86
auto_update_progress_bar : false ,
80
87
} ) ;
@@ -96,9 +103,10 @@ describe("automatic progress bar", () => {
96
103
} ,
97
104
] ;
98
105
99
- await startTimeline ( timeline , jsPsych ) ;
106
+ const { jsPsych } = await startTimeline ( timeline , jsPsychObject ) ;
100
107
101
- const progressbarElement = document . querySelector < HTMLElement > ( "#jspsych-progressbar-inner" ) ;
108
+ const progressbarElement =
109
+ jsPsych . getDisplayContainerElement ( ) . querySelector < HTMLElement > ( "#jspsych-progressbar-inner" ) ;
102
110
103
111
expect ( progressbarElement . style . width ) . toEqual ( "0%" ) ;
104
112
await pressKey ( "a" ) ;
0 commit comments