1
1
import { fireEvent } from "@testing-library/vue"
2
2
3
- import { createApp } from "vue"
3
+ import { createApp , nextTick } from "vue"
4
4
5
5
import { render } from "~~/test/unit/test-utils/render"
6
-
7
- import { i18n } from "~~/test/unit/test-utils/i18n"
8
6
import { getAudioObj } from "~~/test/unit/fixtures/audio"
9
7
10
8
import { useActiveMediaStore } from "~/stores/active-media"
@@ -24,17 +22,31 @@ const RouterLinkStub = createApp({}).component("RouterLink", {
24
22
} ,
25
23
} ,
26
24
} ) . _context . components . RouterLink
25
+
27
26
const stubs = {
28
27
VLicense : true ,
29
28
VWaveform : true ,
30
29
VAudioThumbnail : true ,
31
30
RouterLink : RouterLinkStub ,
32
31
}
33
32
33
+ const captureExceptionMock = vi . fn ( )
34
+
35
+ vi . mock ( "#app" , async ( ) => {
36
+ const original = await import ( "#app" )
37
+ return {
38
+ ...original ,
39
+ useNuxtApp : vi . fn ( ( ) => ( {
40
+ $sentry : {
41
+ captureException : captureExceptionMock ,
42
+ } ,
43
+ } ) ) ,
44
+ }
45
+ } )
46
+
34
47
describe ( "AudioTrack" , ( ) => {
35
48
let options = null
36
49
let props = null
37
- const captureExceptionMock = vi . fn ( )
38
50
39
51
beforeEach ( ( ) => {
40
52
props = {
@@ -54,7 +66,6 @@ describe("AudioTrack", () => {
54
66
options = {
55
67
props : props ,
56
68
global : {
57
- plugins : [ i18n ] ,
58
69
stubs,
59
70
} ,
60
71
}
@@ -94,8 +105,7 @@ describe("AudioTrack", () => {
94
105
expect ( creator ) . toBeTruthy ( )
95
106
} )
96
107
97
- // https://github.com/wordpress/openverse/issues/411
98
- it . skip . each `
108
+ it . each `
99
109
errorType | errorText
100
110
${ "NotAllowedError" } | ${ / R e p r o d u c t i o n n o t a l l o w e d ./ i}
101
111
${ "NotSupportedError" } | ${ / T h i s a u d i o f o r m a t i s n o t s u p p o r t e d b y y o u r b r o w s e r ./ i}
@@ -111,19 +121,22 @@ describe("AudioTrack", () => {
111
121
112
122
vi . clearAllMocks ( )
113
123
114
- const pauseStub = vi
115
- . spyOn ( window . HTMLMediaElement . prototype , "pause" )
116
- . mockImplementation ( ( ) => undefined )
117
-
124
+ const pauseStub = vi . fn ( ( ) => undefined )
125
+ const playStub = vi . fn ( ( ) => Promise . reject ( playError ) )
118
126
const playError = new DOMException ( "msg" , errorType )
119
127
120
- const playStub = vi
121
- . spyOn ( window . HTMLMediaElement . prototype , "play" )
122
- . mockImplementation ( ( ) => Promise . reject ( playError ) )
128
+ vi . spyOn ( window . HTMLMediaElement . prototype , "pause" ) . mockImplementation (
129
+ pauseStub
130
+ )
131
+
132
+ vi . spyOn ( window . HTMLMediaElement . prototype , "play" ) . mockImplementation (
133
+ playStub
134
+ )
123
135
124
136
const { getByRole, getByText } = await render ( VAudioTrack , options )
125
137
126
- await fireEvent . click ( getByRole ( "button" ) )
138
+ await fireEvent . click ( getByRole ( "button" , { name : / p l a y / i } ) )
139
+ await nextTick ( )
127
140
expect ( playStub ) . toHaveBeenCalledTimes ( 1 )
128
141
expect ( pauseStub ) . toHaveBeenCalledTimes ( 1 )
129
142
expect ( getByText ( errorText ) ) . toBeVisible ( )
0 commit comments