lint & cleanup

This commit is contained in:
Henry Jameson 2026-09-16 20:53:15 +03:00
commit 83f009cfed
5 changed files with 148 additions and 90 deletions

View file

@ -1,5 +1,5 @@
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import { computed, nextTick, ref, watch, toValue } from 'vue' import { computed, nextTick, ref, toValue, watch } from 'vue'
import { useMergedConfigStore } from 'src/stores/merged_config.js' import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useOAuthStore } from 'src/stores/oauth.js' import { useOAuthStore } from 'src/stores/oauth.js'
@ -181,7 +181,7 @@ export function useConversation(statusId, expanded) {
watch(statusId, (val) => setFocused(val), { immediate: true }) watch(statusId, (val) => setFocused(val), { immediate: true })
const focusedId = computed(() => const focusedId = computed(() =>
(toValue(expanded) && fullyLoaded.value) ? focusedStatus.value?.id : null, toValue(expanded) && fullyLoaded.value ? focusedStatus.value?.id : null,
) )
watch( watch(

View file

@ -1,7 +1,5 @@
import { onMounted, onUnmounted, ref } from 'vue' import { onMounted, onUnmounted, ref } from 'vue'
import { useWindowSize } from 'src/composables/useWindowSize.js'
export function useScrollPosition() { export function useScrollPosition() {
const x = ref(0) const x = ref(0)
const y = ref(0) const y = ref(0)

View file

@ -73,7 +73,6 @@ export function useTreeConversationTopology(conversation, replies, current) {
const depth = ancestors.value.get(id).size const depth = ancestors.value.get(id).size
const state = (() => { const state = (() => {
console.log(toValue(currentAncestors))
if (depth - currentDepth.value <= maxDepthToShowByDefault.value) { if (depth - currentDepth.value <= maxDepthToShowByDefault.value) {
return 'showing' return 'showing'
} else { } else {

View file

@ -1,31 +1,17 @@
import { createTestingPinia } from '@pinia/testing' import { createTestingPinia } from '@pinia/testing'
import { flushPromises, mount } from '@vue/test-utils'
import { setActivePinia } from 'pinia' import { setActivePinia } from 'pinia'
import { mockMastoAPIStatus, mockStatus } from 'test/fixtures/masto_api.js'
import { ref } from 'vue' import { ref } from 'vue'
import {
mockMastoAPIStatus,
mockMastoAPIUser,
mockStatus,
mockUser,
userId,
userName,
userScreenName,
userUrl,
} from 'test/fixtures/masto_api.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useOAuthStore } from 'src/stores/oauth.js'
import { useStatusesStore } from 'src/stores/statuses.js' import { useStatusesStore } from 'src/stores/statuses.js'
import { useStreamingStore } from 'src/stores/streaming.js'
import { useConversation } from 'src/composables/useConversation.js' import { useConversation } from 'src/composables/useConversation.js'
import { import {
MASTODON_STATUS_CONTEXT_URL, MASTODON_STATUS_CONTEXT_URL,
MASTODON_STATUS_URL,
MASTODON_STATUS_FAVORITEDBY_URL, MASTODON_STATUS_FAVORITEDBY_URL,
MASTODON_STATUS_REBLOGGEDBY_URL, MASTODON_STATUS_REBLOGGEDBY_URL,
MASTODON_STATUS_URL,
PLEROMA_EMOJI_REACTIONS_URL, PLEROMA_EMOJI_REACTIONS_URL,
} from 'src/api/public.js' } from 'src/api/public.js'
@ -75,7 +61,10 @@ describe('useConversation', () => {
it('should return single item that is already known when not expanded', () => { it('should return single item that is already known when not expanded', () => {
useStatusesStore().allStatuses = new Map( useStatusesStore().allStatuses = new Map(
[...new Array(20)].map((i, index) => [index.toString(), constructStatus(index)]) [...new Array(20)].map((i, index) => [
index.toString(),
constructStatus(index),
]),
) )
const result = useConversation(ref('1'), ref(false)) const result = useConversation(ref('1'), ref(false))
@ -89,52 +78,76 @@ describe('useConversation', () => {
}) })
it('should return entire conversation when fethed', async () => { it('should return entire conversation when fethed', async () => {
const convo = [...new Array(20)].map((i, index) => constructStatus(index)) const convoAPI = [...new Array(20)].map((i, index) =>
const convoAPI = [...new Array(20)].map((i, index) => constructStatusAPI(index)) constructStatusAPI(index),
)
const mockFetch = vi.fn() const mockFetch = vi.fn()
vi.when(mockFetch, { onUnmatched: 'throw' }) vi.when(mockFetch, { onUnmatched: 'throw' })
.calledWith(MASTODON_STATUS_URL('4'), expect.anything()) .calledWith(MASTODON_STATUS_URL('4'), expect.anything())
.thenResolveOnce(new Response(JSON.stringify(convoAPI[4]), { .thenResolveOnce(
headers: { 'Content-Type': 'application/json' }, new Response(JSON.stringify(convoAPI[4]), {
})) headers: { 'Content-Type': 'application/json' },
}),
)
.calledWith(MASTODON_STATUS_CONTEXT_URL('4'), expect.anything()) .calledWith(MASTODON_STATUS_CONTEXT_URL('4'), expect.anything())
.thenResolveOnce(new Response(JSON.stringify({ .thenResolveOnce(
ancestors: convoAPI.slice(0,4), new Response(
descendants: convoAPI.slice(5), JSON.stringify({
}), { ancestors: convoAPI.slice(0, 4),
headers: { 'Content-Type': 'application/json' }, descendants: convoAPI.slice(5),
})) }),
{
headers: { 'Content-Type': 'application/json' },
},
),
)
vi.stubGlobal('fetch', mockFetch) vi.stubGlobal('fetch', mockFetch)
const result = useConversation(ref('4'), ref(true)) const result = useConversation(ref('4'), ref(true))
await result.fetchConversation() await result.fetchConversation()
expect(mockFetch).to.have.been.calledWith(MASTODON_STATUS_URL('4'), expect.anything()) expect(mockFetch).to.have.been.calledWith(
MASTODON_STATUS_URL('4'),
expect.anything(),
)
expect(result.conversation.value).to.have.length(1) expect(result.conversation.value).to.have.length(1)
expect(result.conversation.value[0]).to.have.property('id', '4') expect(result.conversation.value[0]).to.have.property('id', '4')
expect(result.conversationId.value).to.have.eql('1000') expect(result.conversationId.value).to.have.eql('1000')
await vi.advanceTimersToNextTimerAsync() await vi.advanceTimersToNextTimerAsync()
expect(mockFetch).to.have.been.calledWith(MASTODON_STATUS_CONTEXT_URL('4'), expect.anything()) expect(mockFetch).to.have.been.calledWith(
MASTODON_STATUS_CONTEXT_URL('4'),
expect.anything(),
)
expect(result.conversation.value).to.have.length(20) expect(result.conversation.value).to.have.length(20)
expect(result.conversation.value[0]).to.have.property('id', '0') expect(result.conversation.value[0]).to.have.property('id', '0')
}) })
it('should fetch entire conversation when expanded', async () => { it('should fetch entire conversation when expanded', async () => {
const convo = [...new Array(20)].map((i, index) => constructStatus(index)) const convo = [...new Array(20)].map((i, index) => constructStatus(index))
const convoAPI = [...new Array(20)].map((i, index) => constructStatusAPI(index)) const convoAPI = [...new Array(20)].map((i, index) =>
useStatusesStore().addNewStatuses({ statuses: [convo[4]], timestamp: Date.now() }) constructStatusAPI(index),
)
useStatusesStore().addNewStatuses({
statuses: [convo[4]],
timestamp: Date.now(),
})
const mockFetch = vi.fn() const mockFetch = vi.fn()
vi.when(mockFetch) vi.when(mockFetch)
.calledWith(MASTODON_STATUS_CONTEXT_URL('4'), expect.anything()) .calledWith(MASTODON_STATUS_CONTEXT_URL('4'), expect.anything())
.thenResolveOnce(new Response(JSON.stringify({ .thenResolveOnce(
ancestors: convoAPI.slice(0,4), new Response(
descendants: convoAPI.slice(5), JSON.stringify({
}), { ancestors: convoAPI.slice(0, 4),
headers: { 'Content-Type': 'application/json' }, descendants: convoAPI.slice(5),
})) }),
{
headers: { 'Content-Type': 'application/json' },
},
),
)
vi.stubGlobal('fetch', mockFetch) vi.stubGlobal('fetch', mockFetch)
const expanded = ref(false) const expanded = ref(false)
@ -144,47 +157,75 @@ describe('useConversation', () => {
expect(result.focusedId.value).to.eql(null) expect(result.focusedId.value).to.eql(null)
expanded.value = true expanded.value = true
await vi.advanceTimersToNextTimerAsync() await vi.advanceTimersToNextTimerAsync()
expect(mockFetch).to.have.been.calledWith(MASTODON_STATUS_CONTEXT_URL('4'), expect.anything()) expect(mockFetch).to.have.been.calledWith(
MASTODON_STATUS_CONTEXT_URL('4'),
expect.anything(),
)
await vi.advanceTimersToNextTimerAsync() await vi.advanceTimersToNextTimerAsync()
expect(result.focusedId.value).to.eql('4') expect(result.focusedId.value).to.eql('4')
expect(mockFetch).to.have.been.calledWith(MASTODON_STATUS_FAVORITEDBY_URL('4'), expect.anything()) expect(mockFetch).to.have.been.calledWith(
expect(mockFetch).to.have.been.calledWith(MASTODON_STATUS_REBLOGGEDBY_URL('4'), expect.anything()) MASTODON_STATUS_FAVORITEDBY_URL('4'),
expect(mockFetch).to.have.been.calledWith(PLEROMA_EMOJI_REACTIONS_URL('4'), expect.anything()) expect.anything(),
)
expect(mockFetch).to.have.been.calledWith(
MASTODON_STATUS_REBLOGGEDBY_URL('4'),
expect.anything(),
)
expect(mockFetch).to.have.been.calledWith(
PLEROMA_EMOJI_REACTIONS_URL('4'),
expect.anything(),
)
await vi.advanceTimersToNextTimerAsync() await vi.advanceTimersToNextTimerAsync()
expect(result.conversation.value).to.have.length(20) expect(result.conversation.value).to.have.length(20)
expect(result.conversation.value[0]).to.have.property('id', '0') expect(result.conversation.value[0]).to.have.property('id', '0')
}) })
it('should reset and fetch another conversation when statusId changes', async () => { it('should reset and fetch another conversation when statusId changes', async () => {
const aConvo = [...new Array(20)].map((i, index) => constructStatus(index + 'a', '1000')) const aConvoAPI = [...new Array(20)].map((i, index) =>
const aConvoAPI = [...new Array(20)].map((i, index) => constructStatusAPI(index + 'a', '1000')) constructStatusAPI(index + 'a', '1000'),
const bConvo = [...new Array(20)].map((i, index) => constructStatus(index + 'b', '2000')) )
const bConvoAPI = [...new Array(20)].map((i, index) => constructStatusAPI(index + 'b', '2000')) const bConvoAPI = [...new Array(20)].map((i, index) =>
constructStatusAPI(index + 'b', '2000'),
)
const mockFetch = vi.fn() const mockFetch = vi.fn()
vi.when(mockFetch, { onUnmatched: 'throw' }) vi.when(mockFetch, { onUnmatched: 'throw' })
.calledWith(MASTODON_STATUS_URL('4a'), expect.anything()) .calledWith(MASTODON_STATUS_URL('4a'), expect.anything())
.thenResolveOnce(new Response(JSON.stringify(aConvoAPI[4]), { .thenResolveOnce(
headers: { 'Content-Type': 'application/json' }, new Response(JSON.stringify(aConvoAPI[4]), {
})) headers: { 'Content-Type': 'application/json' },
}),
)
.calledWith(MASTODON_STATUS_CONTEXT_URL('4a'), expect.anything()) .calledWith(MASTODON_STATUS_CONTEXT_URL('4a'), expect.anything())
.thenResolveOnce(new Response(JSON.stringify({ .thenResolveOnce(
ancestors: aConvoAPI.slice(0,4), new Response(
descendants: aConvoAPI.slice(5), JSON.stringify({
}), { ancestors: aConvoAPI.slice(0, 4),
headers: { 'Content-Type': 'application/json' }, descendants: aConvoAPI.slice(5),
})) }),
{
headers: { 'Content-Type': 'application/json' },
},
),
)
.calledWith(MASTODON_STATUS_URL('4b'), expect.anything()) .calledWith(MASTODON_STATUS_URL('4b'), expect.anything())
.thenResolveOnce(new Response(JSON.stringify(bConvoAPI[4]), { .thenResolveOnce(
headers: { 'Content-Type': 'application/json' }, new Response(JSON.stringify(bConvoAPI[4]), {
})) headers: { 'Content-Type': 'application/json' },
}),
)
.calledWith(MASTODON_STATUS_CONTEXT_URL('4b'), expect.anything()) .calledWith(MASTODON_STATUS_CONTEXT_URL('4b'), expect.anything())
.thenResolveOnce(new Response(JSON.stringify({ .thenResolveOnce(
ancestors: bConvoAPI.slice(0,4), new Response(
descendants: bConvoAPI.slice(5), JSON.stringify({
}), { ancestors: bConvoAPI.slice(0, 4),
headers: { 'Content-Type': 'application/json' }, descendants: bConvoAPI.slice(5),
})) }),
{
headers: { 'Content-Type': 'application/json' },
},
),
)
vi.stubGlobal('fetch', mockFetch) vi.stubGlobal('fetch', mockFetch)
const statusId = ref('4a') const statusId = ref('4a')
@ -192,13 +233,19 @@ describe('useConversation', () => {
const result = useConversation(statusId, true) const result = useConversation(statusId, true)
await result.fetchConversation() await result.fetchConversation()
expect(mockFetch).to.have.been.calledWith(MASTODON_STATUS_URL('4a'), expect.anything()) expect(mockFetch).to.have.been.calledWith(
MASTODON_STATUS_URL('4a'),
expect.anything(),
)
expect(result.conversation.value).to.have.length(1) expect(result.conversation.value).to.have.length(1)
expect(result.conversation.value[0]).to.have.property('id', '4a') expect(result.conversation.value[0]).to.have.property('id', '4a')
expect(result.conversationId.value).to.have.eql('1000') expect(result.conversationId.value).to.have.eql('1000')
await vi.advanceTimersToNextTimerAsync() await vi.advanceTimersToNextTimerAsync()
expect(mockFetch).to.have.been.calledWith(MASTODON_STATUS_CONTEXT_URL('4a'), expect.anything()) expect(mockFetch).to.have.been.calledWith(
MASTODON_STATUS_CONTEXT_URL('4a'),
expect.anything(),
)
expect(result.conversation.value).to.have.length(20) expect(result.conversation.value).to.have.length(20)
expect(result.conversation.value[0]).to.have.property('id', '0a') expect(result.conversation.value[0]).to.have.property('id', '0a')
@ -208,31 +255,47 @@ describe('useConversation', () => {
expect(result.conversation.value).to.have.length(0) expect(result.conversation.value).to.have.length(0)
await vi.advanceTimersToNextTimerAsync() await vi.advanceTimersToNextTimerAsync()
expect(mockFetch).to.have.been.calledWith(MASTODON_STATUS_URL('4b'), expect.anything()) expect(mockFetch).to.have.been.calledWith(
MASTODON_STATUS_URL('4b'),
expect.anything(),
)
expect(result.conversation.value).to.have.length(1) expect(result.conversation.value).to.have.length(1)
expect(result.conversation.value[0]).to.have.property('id', '4b') expect(result.conversation.value[0]).to.have.property('id', '4b')
expect(result.conversationId.value).to.have.eql('2000') expect(result.conversationId.value).to.have.eql('2000')
await vi.advanceTimersToNextTimerAsync() await vi.advanceTimersToNextTimerAsync()
expect(mockFetch).to.have.been.calledWith(MASTODON_STATUS_CONTEXT_URL('4b'), expect.anything()) expect(mockFetch).to.have.been.calledWith(
MASTODON_STATUS_CONTEXT_URL('4b'),
expect.anything(),
)
expect(result.conversation.value).to.have.length(20) expect(result.conversation.value).to.have.length(20)
expect(result.conversation.value[0]).to.have.property('id', '0b') expect(result.conversation.value[0]).to.have.property('id', '0b')
}) })
it('should form replies object', async () => { it('should form replies object', async () => {
const convo = [...new Array(4)].map((i, index) => constructStatus(index)) const convo = [...new Array(4)].map((i, index) => constructStatus(index))
const convoAPI = [...new Array(4)].map((i, index) => constructStatusAPI(index)) const convoAPI = [...new Array(4)].map((i, index) =>
useStatusesStore().addNewStatuses({ statuses: convo, timestamp: Date.now() }) constructStatusAPI(index),
)
useStatusesStore().addNewStatuses({
statuses: convo,
timestamp: Date.now(),
})
const mockFetch = vi.fn() const mockFetch = vi.fn()
vi.when(mockFetch) vi.when(mockFetch)
.calledWith(MASTODON_STATUS_CONTEXT_URL('2'), expect.anything()) .calledWith(MASTODON_STATUS_CONTEXT_URL('2'), expect.anything())
.thenResolveOnce(new Response(JSON.stringify({ .thenResolveOnce(
ancestors: convoAPI.slice(0,1), new Response(
descendants: convoAPI.slice(2), JSON.stringify({
}), { ancestors: convoAPI.slice(0, 1),
headers: { 'Content-Type': 'application/json' }, descendants: convoAPI.slice(2),
})) }),
{
headers: { 'Content-Type': 'application/json' },
},
),
)
vi.stubGlobal('fetch', mockFetch) vi.stubGlobal('fetch', mockFetch)
const result = useConversation('2', true) const result = useConversation('2', true)
@ -242,10 +305,12 @@ describe('useConversation', () => {
await vi.advanceTimersToNextTimerAsync() await vi.advanceTimersToNextTimerAsync()
await vi.advanceTimersToNextTimerAsync() await vi.advanceTimersToNextTimerAsync()
expect(result.conversation.value).to.have.length(4) expect(result.conversation.value).to.have.length(4)
expect(result.replies.value).to.eql(new Map([ expect(result.replies.value).to.eql(
['0', new Set([{ name: '#1', id: '1' }])], new Map([
['1', new Set([{ name: '#2', id: '2' }])], ['0', new Set([{ name: '#1', id: '1' }])],
['2', new Set([{ name: '#3', id: '3' }])], ['1', new Set([{ name: '#2', id: '2' }])],
])) ['2', new Set([{ name: '#3', id: '3' }])],
]),
)
}) })
}) })

View file

@ -6,10 +6,6 @@ import {
mockMastoAPIUser, mockMastoAPIUser,
mockStatus, mockStatus,
mockUser, mockUser,
userId,
userName,
userScreenName,
userUrl,
} from 'test/fixtures/masto_api.js' } from 'test/fixtures/masto_api.js'
import { useStatusesStore } from 'src/stores/statuses.js' import { useStatusesStore } from 'src/stores/statuses.js'