Skip to content

Commit 3cb1d26

Browse files
committed
Fix unit test warnings
1 parent 8af6691 commit 3cb1d26

23 files changed

+69
-246
lines changed

eslint.config.mjs

-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ const eslintIgnores = [
5454
"frontend/.output/**",
5555
"frontend/.remake/**",
5656
"frontend/src/locales/*.json",
57-
// Vendored module. See explanation in file
58-
"frontend/test/unit/test-utils/render-suspended.ts",
5957
"**/coverage/**",
6058
"frontend/test/tapes/**",
6159
"frontend/storybook-static/**",

frontend/src/components/VButton.vue

+5
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ const disabledAttribute = computed<true | undefined>(() => {
191191
return (trulyDisabled && supportsDisabledAttribute.value) || undefined
192192
})
193193
194+
const linkProps = computed(() =>
195+
props.as === "VLink" ? { href: attrs.href } : {}
196+
)
197+
194198
watch(
195199
() => props.as,
196200
(as) => {
@@ -229,6 +233,7 @@ watch(
229233
:aria-pressed="pressed"
230234
:aria-disabled="ariaDisabled"
231235
:disabled="disabledAttribute"
236+
v-bind="linkProps"
232237
@click="$emit('click', $event)"
233238
@mousedown="$emit('mousedown', $event)"
234239
@keydown="$emit('keydown', $event)"

frontend/src/components/VHeader/VHomeLink.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ withDefaults(
1515
*
1616
* @default 'light'
1717
*/
18-
variant: "light" | "dark"
18+
variant?: "light" | "dark"
1919
}>(),
2020
{ variant: "light" }
2121
)

frontend/src/components/VHeader/VWordPressLink.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import VSvg from "~/components/VSvg/VSvg.vue"
44
55
withDefaults(
66
defineProps<{
7-
mode: "dark" | "light"
7+
mode?: "dark" | "light"
88
}>(),
99
{ mode: "light" }
1010
)

frontend/src/components/VLogoLoader/VLogoLoader.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useReducedMotion } from "~/composables/use-reduced-motion"
33
44
withDefaults(
55
defineProps<{
6-
status: "loading" | "idle"
6+
status?: "loading" | "idle"
77
}>(),
88
{
99
status: "idle",

frontend/src/components/VTag/VTag.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import VButton from "~/components/VButton.vue"
33
4-
defineProps<{ href: string }>()
4+
const props = defineProps<{ href: string }>()
55
</script>
66

77
<template>
@@ -10,7 +10,7 @@ defineProps<{ href: string }>()
1010
size="small"
1111
variant="filled-gray"
1212
class="label-bold"
13-
v-bind="$props"
13+
v-bind="props"
1414
><slot
1515
/></VButton>
1616
</template>

frontend/test/unit/specs/components/AudioTrack/v-audio-track.spec.js

+28-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { fireEvent } from "@testing-library/vue"
22

3-
import { createApp } from "vue"
3+
import { createApp, nextTick } from "vue"
44

55
import { render } from "~~/test/unit/test-utils/render"
6-
7-
import { i18n } from "~~/test/unit/test-utils/i18n"
86
import { getAudioObj } from "~~/test/unit/fixtures/audio"
97

108
import { useActiveMediaStore } from "~/stores/active-media"
@@ -24,17 +22,31 @@ const RouterLinkStub = createApp({}).component("RouterLink", {
2422
},
2523
},
2624
})._context.components.RouterLink
25+
2726
const stubs = {
2827
VLicense: true,
2928
VWaveform: true,
3029
VAudioThumbnail: true,
3130
RouterLink: RouterLinkStub,
3231
}
3332

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+
3447
describe("AudioTrack", () => {
3548
let options = null
3649
let props = null
37-
const captureExceptionMock = vi.fn()
3850

3951
beforeEach(() => {
4052
props = {
@@ -54,7 +66,6 @@ describe("AudioTrack", () => {
5466
options = {
5567
props: props,
5668
global: {
57-
plugins: [i18n],
5869
stubs,
5970
},
6071
}
@@ -94,8 +105,7 @@ describe("AudioTrack", () => {
94105
expect(creator).toBeTruthy()
95106
})
96107

97-
// https://github.com/wordpress/openverse/issues/411
98-
it.skip.each`
108+
it.each`
99109
errorType | errorText
100110
${"NotAllowedError"} | ${/Reproduction not allowed./i}
101111
${"NotSupportedError"} | ${/This audio format is not supported by your browser./i}
@@ -111,19 +121,22 @@ describe("AudioTrack", () => {
111121

112122
vi.clearAllMocks()
113123

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))
118126
const playError = new DOMException("msg", errorType)
119127

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+
)
123135

124136
const { getByRole, getByText } = await render(VAudioTrack, options)
125137

126-
await fireEvent.click(getByRole("button"))
138+
await fireEvent.click(getByRole("button", { name: /play/i }))
139+
await nextTick()
127140
expect(playStub).toHaveBeenCalledTimes(1)
128141
expect(pauseStub).toHaveBeenCalledTimes(1)
129142
expect(getByText(errorText)).toBeVisible()

frontend/test/unit/specs/components/ImageDetails/v-copy-license.spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ describe("VCopyLicense", () => {
2222
creator_url: "http://creator.com",
2323
frontendMediaType: "image",
2424
},
25-
fullLicenseName: "LICENSE",
2625
}
2726
options = { props }
2827
})

frontend/test/unit/specs/components/InputField/input-field.spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import VInputField from "~/components/VInputField/VInputField.vue"
99
const props = {
1010
fieldId: "input-id",
1111
labelText: "Label",
12-
size: "medium",
1312
}
1413

1514
describe("VInputField", () => {

frontend/test/unit/specs/components/VMediaInfo/v-media-details.spec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe("VMediaDetails", () => {
2828
}
2929
})
3030

31-
// https://github.com/wordpress/openverse/issues/411
31+
// https://github.com/wordpress/openverse/issues/5171
3232
it.skip("renders the album title", async () => {
3333
await render(VMediaDetails, options)
3434

@@ -39,27 +39,27 @@ describe("VMediaDetails", () => {
3939
)
4040
})
4141

42-
// https://github.com/wordpress/openverse/issues/411
42+
// https://github.com/wordpress/openverse/issues/5171
4343
it.skip("hides the album title tag when it does not exists", async () => {
4444
options.props.media.audio_set = null
4545
await render(VMediaDetails, options)
4646
expect(screen.queryByText("Album")).toBeNull()
4747
})
4848

49-
// https://github.com/wordpress/openverse/issues/411
49+
// https://github.com/wordpress/openverse/issues/5171
5050
it.skip("displays the main filetype when no alternative files are available", async () => {
5151
await render(VMediaDetails, options)
5252
expect(screen.queryByText("MP32")).toBeVisible()
5353
})
5454

55-
// https://github.com/wordpress/openverse/issues/411
55+
// https://github.com/wordpress/openverse/issues/5171
5656
it.skip("displays multiple filetypes when they are available in alt_files", async () => {
5757
options.props.media.alt_files = [{ filetype: "wav" }, { filetype: "ogg" }]
5858
await render(VMediaDetails, options)
5959
expect(screen.queryByText("MP32, WAV, OGG")).toBeVisible()
6060
})
6161

62-
// https://github.com/wordpress/openverse/issues/411
62+
// https://github.com/wordpress/openverse/issues/5171
6363
it.skip("displays only distinct filetypes", async () => {
6464
options.props.media.alt_files = [{ filetype: "ogg" }, { filetype: "ogg" }]
6565
await render(VMediaDetails, options)

frontend/test/unit/specs/components/VSafetyWall/v-safety-wall.spec.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { createApp } from "vue"
44

55
import { render } from "~~/test/unit/test-utils/render"
66

7-
import { i18n } from "~~/test/unit/test-utils/i18n"
8-
97
import { useSearchStore } from "~/stores/search"
108

119
import VSafetyWall from "~/components/VSafetyWall/VSafetyWall.vue"
@@ -25,17 +23,15 @@ describe("VSafetyWall.vue", () => {
2523
beforeEach(() => {
2624
options = {
2725
global: {
28-
plugins: [i18n],
2926
stubs: { RouterLink: RouterLinkStub },
3027
},
3128
props: {
32-
media: {
33-
sensitivity: [
34-
"sensitive_text",
35-
"provider_supplied_sensitive",
36-
"user_reported_sensitive",
37-
],
38-
},
29+
sensitivity: [
30+
"sensitive_text",
31+
"provider_supplied_sensitive",
32+
"user_reported_sensitive",
33+
],
34+
id: "123",
3935
},
4036
}
4137
})

frontend/test/unit/specs/components/VTag/v-tag.spec.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ describe("VTag", () => {
2121
expect(link.href).toEqual("https://example.com/")
2222
})
2323

24-
// https://github.com/wordpress/openverse/issues/411
25-
it.skip("renders slot content", async () => {
24+
it("renders slot content", async () => {
2625
const slotText = "Slot test"
27-
options.slots = { default: () => `<div>${slotText}</div>` }
26+
// Using a non-function value for the slot causes a Vue warning,
27+
// but a function value is not rendered correctly by the unit tests.
28+
options.slots = { default: `<div>${slotText}</div>` }
2829

2930
await render(VTag, options)
3031
expect(screen.getByText(slotText)).toBeDefined()

frontend/test/unit/specs/components/scroll-button.spec.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@ import { screen } from "@testing-library/vue"
22

33
import { render } from "~~/test/unit/test-utils/render"
44

5-
import { i18n } from "~~/test/unit/test-utils/i18n"
6-
75
import VScrollButton from "~/components/VScrollButton.vue"
86

97
describe("Scroll button", () => {
108
it("should render a scroll button", async () => {
11-
const { container } = await render(VScrollButton, {
12-
global: { plugins: [i18n] },
13-
})
9+
const { container } = await render(VScrollButton)
1410
expect(screen.getByRole("button")).toBeTruthy()
1511
expect(screen.getByLabelText(/scroll/i)).toBeTruthy()
1612
expect(container.querySelectorAll("svg").length).toEqual(1)

frontend/test/unit/specs/components/v-content-link.spec.js

-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { createApp } from "vue"
66

77
import { render } from "~~/test/unit/test-utils/render"
88

9-
import { i18n } from "~~/test/unit/test-utils/i18n"
10-
119
import VContentLink from "~/components/VContentLink/VContentLink.vue"
1210

1311
const RouterLinkStub = createApp({}).component("RouterLink", {
@@ -26,7 +24,6 @@ describe("VContentLink", () => {
2624
beforeEach(() => {
2725
options = {
2826
global: {
29-
plugins: [i18n],
3027
stubs: { RouterLink: RouterLinkStub },
3128
},
3229
props: {

frontend/test/unit/specs/components/v-image-cell.spec.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { createApp } from "vue"
22

33
import { image } from "~~/test/unit/fixtures/image"
44
import { render } from "~~/test/unit/test-utils/render"
5-
import { i18n } from "~~/test/unit/test-utils/i18n"
65

76
import VImageCell from "~/components/VImageCell/VImageCell.vue"
87

@@ -21,13 +20,13 @@ describe("VImageCell", () => {
2120
beforeEach(() => {
2221
options = {
2322
global: {
24-
plugins: [i18n],
2523
stubs: {
2624
RouterLink: RouterLinkStub,
2725
},
2826
},
2927
props: {
3028
image,
29+
kind: "search",
3130
searchTerm: "cat",
3231
relatedTo: null,
3332
},

frontend/test/unit/specs/utils/api-token/api-token-missing-credentials.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getApiAccessToken } from "~/plugins/01.api-token.server"
44

55
describe("missing client credentials", () => {
66
describe("completely missing", () => {
7-
// https://github.com/wordpress/openverse/issues/411
7+
// https://github.com/wordpress/openverse/issues/5171
88
it.skip("should not make any requests and fall back to tokenless", async () => {
99
const token = await getApiAccessToken()
1010

@@ -13,7 +13,7 @@ describe("missing client credentials", () => {
1313
})
1414

1515
describe("explicitly undefined", () => {
16-
// https://github.com/wordpress/openverse/issues/411
16+
// https://github.com/wordpress/openverse/issues/5171
1717
it.skip("should not make any requests and fall back to tokenless", async () => {
1818
const accessToken = await getApiAccessToken({
1919
apiClientId: undefined,

frontend/test/unit/specs/utils/api-token/api-token-parallel.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ vi.mock("#app/nuxt", async () => {
3333
}
3434
})
3535

36-
// https://github.com/wordpress/openverse/issues/411
36+
// https://github.com/wordpress/openverse/issues/5171
3737
it.skip("subsequent requests should all block on the same token retrieval promise", async () => {
3838
/**
3939
* This test is pretty complicated because we need to simulate

frontend/test/unit/specs/utils/api-token/api-token-successful.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe.sequential("api-token", () => {
5151
})
5252

5353
describe("successful token retrieval", () => {
54-
// https://github.com/wordpress/openverse/issues/411
54+
// https://github.com/wordpress/openverse/issues/5171
5555
it.skip("should save the token into the process and inject into the context", async () => {
5656
const mockTokenResponse = getMockTokenResponse()
5757
axios.post.mockImplementationOnce(() =>
@@ -67,7 +67,7 @@ describe.sequential("api-token", () => {
6767
})
6868
})
6969

70-
// https://github.com/wordpress/openverse/issues/411
70+
// https://github.com/wordpress/openverse/issues/5171
7171
it.skip("should re-retrieve the token when about to expire", async () => {
7272
const mockTokenResponse = getMockTokenResponse(expiryThreshold - 1)
7373
const nextMockTokenResponse = getMockTokenResponse()
@@ -89,7 +89,7 @@ describe.sequential("api-token", () => {
8989
})
9090
})
9191

92-
// https://github.com/wordpress/openverse/issues/411
92+
// https://github.com/wordpress/openverse/issues/5171
9393
it.skip("should not request a new token if the token is not about to expire", async () => {
9494
const mockTokenResponse = getMockTokenResponse(twelveHoursInSeconds)
9595
const nextMockTokenResponse = getMockTokenResponse()

0 commit comments

Comments
 (0)