This commit is contained in:
Henry Jameson 2026-06-18 20:53:21 +03:00
commit fe1790f217
6 changed files with 67 additions and 70 deletions

View file

@ -2,7 +2,7 @@ import { createTestingPinia } from '@pinia/testing'
import { HttpResponse, http } from 'msw'
import { setActivePinia } from 'pinia'
import { test as mockedIt } from '/test/fixtures/mock_api.js'
import { test as it } from '/test/fixtures/mock_api.js'
import { useListsStore } from 'src/stores/lists.js'
@ -17,7 +17,7 @@ describe('The lists store', () => {
})
describe('actions', () => {
mockedIt('updates array of all lists', () => {
it('updates array of all lists', () => {
const list = { id: '1', title: 'testList' }
store.setLists([list])
@ -25,74 +25,72 @@ describe('The lists store', () => {
expect(store.allLists).to.eql([list])
})
mockedIt(
'adds a new list with a title, updating the title for existing lists',
async ({ worker }) => {
const list = { id: '1', title: 'testList' }
const modList = { id: '1', title: 'anotherTestTitle' }
it('adds a new list with a title, updating the title for existing lists', async ({
worker,
}) => {
const list = { id: '1', title: 'testList' }
const modList = { id: '1', title: 'anotherTestTitle' }
worker.use(
http.put(MASTODON_LIST_URL(':id'), () =>
HttpResponse.json({ ok: true }),
),
)
console.log('1 =========', worker.listHandlers())
worker.use(
http.put(MASTODON_LIST_URL(':id'), () =>
HttpResponse.json({ ok: true }),
),
)
console.log('1 =========', worker.listHandlers())
await store.setList({ listId: list.id, title: list.title })
expect(store.allListsObject[list.id]).to.eql({
title: list.title,
accountIds: [],
})
expect(store.allLists).to.have.length(1)
expect(store.allLists[0]).to.eql(list)
await store.setList({ listId: list.id, title: list.title })
expect(store.allListsObject[list.id]).to.eql({
title: list.title,
accountIds: [],
})
expect(store.allLists).to.have.length(1)
expect(store.allLists[0]).to.eql(list)
console.log('2 =========', worker.listHandlers())
console.log('2 =========', worker.listHandlers())
await store.setList({ listId: modList.id, title: modList.title })
expect(store.allListsObject[modList.id]).to.eql({
title: modList.title,
accountIds: [],
})
expect(store.allLists).to.have.length(1)
expect(store.allLists[0]).to.eql(modList)
await store.setList({ listId: modList.id, title: modList.title })
expect(store.allListsObject[modList.id]).to.eql({
title: modList.title,
accountIds: [],
})
expect(store.allLists).to.have.length(1)
expect(store.allLists[0]).to.eql(modList)
console.log('3 =========', worker.listHandlers())
},
)
console.log('3 =========', worker.listHandlers())
})
mockedIt(
'adds a new list with an array of IDs, updating the IDs for existing lists',
async ({ worker }) => {
const list = { id: '1', accountIds: ['1', '2', '3'] }
const modList = { id: '1', accountIds: ['3', '4', '5'] }
it('adds a new list with an array of IDs, updating the IDs for existing lists', async ({
worker,
}) => {
const list = { id: '1', accountIds: ['1', '2', '3'] }
const modList = { id: '1', accountIds: ['3', '4', '5'] }
worker.use(
http.post(MASTODON_LIST_ACCOUNTS_URL(':id'), () =>
HttpResponse.json({ ok: true }),
),
http.delete(MASTODON_LIST_ACCOUNTS_URL(':id'), () =>
HttpResponse.json({ ok: true }),
),
)
worker.use(
http.post(MASTODON_LIST_ACCOUNTS_URL(':id'), () =>
HttpResponse.json({ ok: true }),
),
http.delete(MASTODON_LIST_ACCOUNTS_URL(':id'), () =>
HttpResponse.json({ ok: true }),
),
)
await store.setListAccounts({
listId: list.id,
accountIds: list.accountIds,
})
expect(store.allListsObject[list.id].accountIds).to.eql(list.accountIds)
await store.setListAccounts({
listId: list.id,
accountIds: list.accountIds,
})
expect(store.allListsObject[list.id].accountIds).to.eql(list.accountIds)
await store.setListAccounts({
listId: modList.id,
accountIds: modList.accountIds,
})
await store.setListAccounts({
listId: modList.id,
accountIds: modList.accountIds,
})
expect(store.allListsObject[modList.id].accountIds).to.eql(
modList.accountIds,
)
},
)
expect(store.allListsObject[modList.id].accountIds).to.eql(
modList.accountIds,
)
})
mockedIt('deletes a list', async ({ worker }) => {
it('deletes a list', async ({ worker }) => {
store.$patch({
allLists: [{ id: '1', title: 'testList' }],
allListsObject: {
@ -114,7 +112,7 @@ describe('The lists store', () => {
})
describe('getters', () => {
mockedIt('returns list title', () => {
it('returns list title', () => {
store.$patch({
allLists: [{ id: '1', title: 'testList' }],
allListsObject: {
@ -126,7 +124,7 @@ describe('The lists store', () => {
expect(store.findListTitle(id)).to.eql('testList')
})
mockedIt('returns list accounts', () => {
it('returns list accounts', () => {
store.$patch({
allLists: [{ id: '1', title: 'testList' }],
allListsObject: {