Skip to content

Commit

Permalink
linting in modules stores
Browse files Browse the repository at this point in the history
  • Loading branch information
MWest2020 committed Aug 5, 2024
1 parent d07eee1 commit b861465
Show file tree
Hide file tree
Showing 14 changed files with 1,022 additions and 1,022 deletions.
8 changes: 4 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Vue.mixin({ methods: { t, n } })
Vue.use(PiniaVuePlugin)

new Vue(
{
pinia,
render: h => h(App),
}
{
pinia,
render: h => h(App),
},
).$mount('#opencatalogi')
92 changes: 46 additions & 46 deletions src/store/modules/catalogi.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,50 @@ import { defineStore } from 'pinia'
import { Catalogi } from '../../entities/index.js'

export const useCatalogiStore = defineStore(
'catalogi', {
state: () => ({
catalogiItem: false,
catalogiList: [],
}),
actions: {
setCatalogiItem(catalogiItem) {
this.catalogiItem = catalogiItem && new Catalogi(catalogiItem)
console.log('Active catalog item set to ' + catalogiItem && catalogiItem?.id)
},
setCatalogiList(catalogiList) {
this.catalogiList = catalogiList.map(
(catalogiItem) => new Catalogi(catalogiItem),
)
console.log('Catalogi list set to ' + catalogiList.length + ' item')
},
async refreshCatalogiList(search = null) {
// @todo this might belong in a service?
let endpoint = '/index.php/apps/opencatalogi/api/catalogi'
if (search !== null && search !== '') {
endpoint = endpoint + '?_search=' + search
}
return fetch(
endpoint, {
method: 'GET',
}
)
.then(
(response) => {
response.json().then(
(data) => {
this.catalogiList = data.results.map(
(catalogiItem) => new Catalogi(catalogiItem),
)
}
)
}
)
.catch(
(err) => {
console.error(err)
}
)
},
},
}
'catalogi', {
state: () => ({
catalogiItem: false,
catalogiList: [],
}),
actions: {
setCatalogiItem(catalogiItem) {
this.catalogiItem = catalogiItem && new Catalogi(catalogiItem)
console.log('Active catalog item set to ' + catalogiItem && catalogiItem?.id)
},
setCatalogiList(catalogiList) {
this.catalogiList = catalogiList.map(
(catalogiItem) => new Catalogi(catalogiItem),
)
console.log('Catalogi list set to ' + catalogiList.length + ' item')
},
async refreshCatalogiList(search = null) {
// @todo this might belong in a service?
let endpoint = '/index.php/apps/opencatalogi/api/catalogi'
if (search !== null && search !== '') {
endpoint = endpoint + '?_search=' + search
}
return fetch(
endpoint, {
method: 'GET',
},
)
.then(
(response) => {
response.json().then(
(data) => {
this.catalogiList = data.results.map(
(catalogiItem) => new Catalogi(catalogiItem),
)
},
)
},
)
.catch(
(err) => {
console.error(err)
},
)
},
},
},
)
162 changes: 81 additions & 81 deletions src/store/modules/catalogi.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,87 +5,87 @@ import { useCatalogiStore } from './catalogi.js'
import { Catalogi } from '../../entities/index.js'

describe(
'Catalogi Store', () => {
beforeEach(
() => {
setActivePinia(createPinia())
}
)

it(
'sets catalogi item correctly', () => {
const store = useCatalogiStore()

store.setCatalogiItem(testData[0])

expect(store.catalogiItem).toBeInstanceOf(Catalogi)
expect(store.catalogiItem).toEqual(testData[0])

expect(store.catalogiItem.validate()).toBe(true)
}
)

it(
'sets catalogi list correctly', () => {
const store = useCatalogiStore()

store.setCatalogiList(testData)

expect(store.catalogiList).toHaveLength(testData.length)

// list item 1
expect(store.catalogiList[0]).toBeInstanceOf(Catalogi)
expect(store.catalogiList[0]).toEqual(testData[0])

expect(store.catalogiList[0].validate()).toBe(true)

// list item 2
expect(store.catalogiList[1]).toBeInstanceOf(Catalogi)
expect(store.catalogiList[1].id).toBe(testData[1].id)
expect(store.catalogiList[1].title).toBe(testData[1].title)
expect(store.catalogiList[1].summary).toBe(testData[1].summary)
expect(store.catalogiList[1].description).toBe(testData[1].description)
expect(store.catalogiList[1].image).toBe('')
expect(store.catalogiList[1].search).toBe('')

expect(store.catalogiList[1].validate()).toBe(true)

// list item 3
expect(store.catalogiList[2]).toBeInstanceOf(Catalogi)
expect(store.catalogiList[2].id).toBe(testData[2].id)
expect(store.catalogiList[2].title).toBe('')
expect(store.catalogiList[2].summary).toBe(testData[2].summary)
expect(store.catalogiList[2].description).toBe(testData[2].description)
expect(store.catalogiList[2].image).toBe(testData[2].image)
expect(store.catalogiList[2].search).toBe(testData[2].search)

expect(store.catalogiList[2].validate()).toBe(false) // id, title and summary are required, causing a falsy result
}
)
}
'Catalogi Store', () => {
beforeEach(
() => {
setActivePinia(createPinia())
},
)

it(
'sets catalogi item correctly', () => {
const store = useCatalogiStore()

store.setCatalogiItem(testData[0])

expect(store.catalogiItem).toBeInstanceOf(Catalogi)
expect(store.catalogiItem).toEqual(testData[0])

expect(store.catalogiItem.validate()).toBe(true)
},
)

it(
'sets catalogi list correctly', () => {
const store = useCatalogiStore()

store.setCatalogiList(testData)

expect(store.catalogiList).toHaveLength(testData.length)

// list item 1
expect(store.catalogiList[0]).toBeInstanceOf(Catalogi)
expect(store.catalogiList[0]).toEqual(testData[0])

expect(store.catalogiList[0].validate()).toBe(true)

// list item 2
expect(store.catalogiList[1]).toBeInstanceOf(Catalogi)
expect(store.catalogiList[1].id).toBe(testData[1].id)
expect(store.catalogiList[1].title).toBe(testData[1].title)
expect(store.catalogiList[1].summary).toBe(testData[1].summary)
expect(store.catalogiList[1].description).toBe(testData[1].description)
expect(store.catalogiList[1].image).toBe('')
expect(store.catalogiList[1].search).toBe('')

expect(store.catalogiList[1].validate()).toBe(true)

// list item 3
expect(store.catalogiList[2]).toBeInstanceOf(Catalogi)
expect(store.catalogiList[2].id).toBe(testData[2].id)
expect(store.catalogiList[2].title).toBe('')
expect(store.catalogiList[2].summary).toBe(testData[2].summary)
expect(store.catalogiList[2].description).toBe(testData[2].description)
expect(store.catalogiList[2].image).toBe(testData[2].image)
expect(store.catalogiList[2].search).toBe(testData[2].search)

expect(store.catalogiList[2].validate()).toBe(false) // id, title and summary are required, causing a falsy result
},
)
},
)

const testData = [
{
id: '1',
title: 'Decat',
summary: 'a short form summary',
description: 'a really really long description about this catalogus',
image: 'string',
search: 'string',
},
{
id: '2',
title: 'Woo',
summary: 'a short form summary',
description: 'a really really long description about this catalogus',
},
{
id: '3',
title: '',
summary: 'a short form summary',
description: 'a really really long description about this catalogus',
image: 'string',
search: 'string',
},
]
{
id: '1',
title: 'Decat',
summary: 'a short form summary',
description: 'a really really long description about this catalogus',
image: 'string',
search: 'string',
},
{
id: '2',
title: 'Woo',
summary: 'a short form summary',
description: 'a really really long description about this catalogus',
},
{
id: '3',
title: '',
summary: 'a short form summary',
description: 'a really really long description about this catalogus',
image: 'string',
search: 'string',
},
]
92 changes: 46 additions & 46 deletions src/store/modules/directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,50 @@ import { defineStore } from 'pinia'
import { Listing } from '../../entities/index.js'

export const useDirectoryStore = defineStore(
'directory', {
state: () => ({
listingItem: false,
listingList: [],
}),
actions: {
setListingItem(listingItem) {
this.listingItem = listingItem && new Listing(listingItem)
console.log('Active directory item set to ' + listingItem && listingItem.id)
},
setListingList(listingList) {
this.listingList = listingList.map(
(listingItem) => new Listing(listingItem),
)
console.log('Active directory item set to ' + listingList.length)
},
async refreshListingList(search = null) {
// @todo this might belong in a service?
let endpoint = '/index.php/apps/opencatalogi/api/directory'
if (search !== null && search !== '') {
endpoint = endpoint + '?_search=' + search
}
return fetch(
endpoint, {
method: 'GET',
}
)
.then(
(response) => {
response.json().then(
(data) => {
this.listingList = data.results.map(
(listingItem) => new Listing(listingItem),
)
}
)
}
)
.catch(
(err) => {
console.error(err)
}
)
},
},
}
'directory', {
state: () => ({
listingItem: false,
listingList: [],
}),
actions: {
setListingItem(listingItem) {
this.listingItem = listingItem && new Listing(listingItem)
console.log('Active directory item set to ' + listingItem && listingItem.id)
},
setListingList(listingList) {
this.listingList = listingList.map(
(listingItem) => new Listing(listingItem),
)
console.log('Active directory item set to ' + listingList.length)
},
async refreshListingList(search = null) {
// @todo this might belong in a service?
let endpoint = '/index.php/apps/opencatalogi/api/directory'
if (search !== null && search !== '') {
endpoint = endpoint + '?_search=' + search
}
return fetch(
endpoint, {
method: 'GET',
},
)
.then(
(response) => {
response.json().then(
(data) => {
this.listingList = data.results.map(
(listingItem) => new Listing(listingItem),
)
},
)
},
)
.catch(
(err) => {
console.error(err)
},
)
},
},
},
)
Loading

0 comments on commit b861465

Please sign in to comment.