Content-Length: 494393 | pFad | http://github.com/lana-k/sqliteviz/commit/f55a8caa92bb90c930f154cc4b5ef3e03c8a8965

EB #121 tests · lana-k/sqliteviz@f55a8ca · GitHub
Skip to content

Commit

Permalink
#121 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lana-k committed Jan 12, 2025
1 parent 87f9f9e commit f55a8ca
Show file tree
Hide file tree
Showing 7 changed files with 421 additions and 339 deletions.
1 change: 1 addition & 0 deletions src/store/actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Tab from '@/lib/tab'
import { nanoid } from 'nanoid'

export default {
async addTab ({ state }, inquiry = {}) {
Expand Down
2 changes: 1 addition & 1 deletion src/views/Main/Inquiries/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export default {
},
computed: {
inquiries () {
return this.$store.state.inquiries || []
return this.$store.state.inquiries
},
predefinedInquiries () {
return this.$store.state.predefinedInquiries.map(inquiry => {
Expand Down
51 changes: 51 additions & 0 deletions tests/App.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { expect } from 'chai'
import sinon from 'sinon'
import { shallowMount } from '@vue/test-utils'
import Vuex from 'vuex'
import App from '@/App'
import storedInquiries from '@/lib/storedInquiries'
import mutations from '@/store/mutations'

describe('App.vue', () => {
afterEach(() => {
sinon.restore()
})

it('Gets inquiries', () => {
sinon.stub(storedInquiries, 'getStoredInquiries').returns([
{id: 1}, {id: 2}, {id: 3}
])
const state = {
predefinedInquiries: [],
inquiries: []
}
const store = new Vuex.Store({ state, mutations })
shallowMount(App, { store, stubs: ['router-view'] })

expect(state.inquiries).to.eql([{id: 1}, {id: 2}, {id: 3}])
})

it('Updates inquiries when they change in store', async () => {
sinon.stub(storedInquiries, 'getStoredInquiries').returns([
{id: 1, name: 'foo'}, {id: 2, name: 'baz'}, {id: 3, name: 'bar'}
])
sinon.spy(storedInquiries, 'updateStorage')


const state = {
predefinedInquiries: [],
inquiries: []
}
const store = new Vuex.Store({ state, mutations })
const wrapper = shallowMount(App, { store, stubs: ['router-view'] })

store.state.inquiries.splice(0, 1, {id: 1, name: 'new foo name'})
await wrapper.vm.$nextTick()

expect(storedInquiries.updateStorage.calledTwice).to.equal(true)

expect(storedInquiries.updateStorage.args[1][0]).to.eql([
{id: 1, name: 'new foo name'}, {id: 2, name: 'baz'}, {id: 3, name: 'bar'}
])
})
})
83 changes: 0 additions & 83 deletions tests/lib/storedInquiries/storedInquiries.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,87 +342,4 @@ describe('storedInquiries.js', () => {
createdAt: '2020-11-03T14:17:49.524Z'
}])
})

it('save adds new inquiry in the storage', () => {
const now = new Date()
const nowPlusMinute = new Date(now.getTime() + 60 * 1000)
const tab = {
id: 1,
query: 'select * from foo',
viewType: 'chart',
viewOptions: [],
name: null,
dataView: {
getOptionsForSave () {
return ['chart']
}
}

}
const value = storedInquiries.save(tab, 'foo')
expect(value.id).to.equal(tab.id)
expect(value.name).to.equal('foo')
expect(value.query).to.equal(tab.query)
expect(value.viewOptions).to.eql(['chart'])
expect(value).to.have.property('createdAt').which.within(now, nowPlusMinute)
const inquiries = storedInquiries.getStoredInquiries()
expect(JSON.stringify(inquiries)).to.equal(JSON.stringify([value]))
})

it('save updates existing inquiry in the storage', () => {
const tab = {
id: 1,
query: 'select * from foo',
viewType: 'chart',
viewOptions: [],
name: null,
dataView: {
getOptionsForSave () {
return ['chart']
}
}

}

const first = storedInquiries.save(tab, 'foo')

tab.name = 'foo'
tab.query = 'select * from foo'
storedInquiries.save(tab)
const inquiries = storedInquiries.getStoredInquiries()
const second = inquiries[0]
expect(inquiries).has.lengthOf(1)
expect(second.id).to.equal(first.id)
expect(second.name).to.equal(first.name)
expect(second.query).to.equal(tab.query)
expect(second.viewOptions).to.eql(['chart'])
expect(new Date(second.createdAt).getTime()).to.equal(first.createdAt.getTime())
})

it("save adds a new inquiry with new id if it's based on predefined inquiry", () => {
const now = new Date()
const nowPlusMinute = new Date(now.getTime() + 60 * 1000)
const tab = {
id: 1,
query: 'select * from foo',
viewType: 'chart',
viewOptions: [],
name: 'foo predefined',
dataView: {
getOptionsForSave () {
return ['chart']
}
},
isPredefined: true
}
storedInquiries.save(tab, 'foo')

const inquiries = storedInquiries.getStoredInquiries()
expect(inquiries).has.lengthOf(1)
expect(inquiries[0]).to.have.property('id').which.not.equal(tab.id)
expect(inquiries[0].name).to.equal('foo')
expect(inquiries[0].query).to.equal(tab.query)
expect(inquiries[0].viewOptions).to.eql(['chart'])
expect(new Date(inquiries[0].createdAt)).to.be.within(now, nowPlusMinute)
})
})
109 changes: 108 additions & 1 deletion tests/store/actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const {
addTab,
addInquiry,
deleteInquiries,
renameInquiry
renameInquiry,
saveInquiry
} = actions

describe('actions', () => {
Expand Down Expand Up @@ -132,4 +133,110 @@ describe('actions', () => {
}
})).to.equal(true)
})

it('saveInquiry adds new inquiry in the storage', async () => {
const now = new Date()
const nowPlusMinute = new Date(now.getTime() + 60 * 1000)

const tab = {
id: 1,
query: 'select * from foo',
viewType: 'chart',
viewOptions: [],
name: null,
dataView: {
getOptionsForSave () {
return ['chart']
}
}
}
const state = {
inquiries: [],
tabs: [tab],
}

const value = await saveInquiry({ state }, {
inquiryTab: tab,
newName: 'foo'
})
expect(value.id).to.equal(tab.id)
expect(value.name).to.equal('foo')
expect(value.query).to.equal(tab.query)
expect(value.viewOptions).to.eql(['chart'])
expect(value).to.have.property('createdAt').which.within(now, nowPlusMinute)
expect(state.inquiries).to.eql([value])
})

it('save updates existing inquiry in the storage', async () => {
const tab = {
id: 1,
query: 'select * from foo',
viewType: 'chart',
viewOptions: [],
name: null,
dataView: {
getOptionsForSave () {
return ['chart']
}
}
}

const state = {
inquiries: [],
tabs: [tab],
}

const first = await saveInquiry({ state }, {
inquiryTab: tab,
newName: 'foo'
})

tab.name = 'foo'
tab.query = 'select * from foo'
await saveInquiry({ state }, { inquiryTab: tab })
const inquiries = state.inquiries
const second = inquiries[0]
expect(inquiries).has.lengthOf(1)
expect(second.id).to.equal(first.id)
expect(second.name).to.equal(first.name)
expect(second.query).to.equal(tab.query)
expect(second.viewOptions).to.eql(['chart'])
expect(new Date(second.createdAt).getTime()).to.equal(first.createdAt.getTime())
})

it("save adds a new inquiry with new id if it's based on predefined inquiry", async () => {
const now = new Date()
const nowPlusMinute = new Date(now.getTime() + 60 * 1000)
const tab = {
id: 1,
query: 'select * from foo',
viewType: 'chart',
viewOptions: [],
name: 'foo predefined',
dataView: {
getOptionsForSave () {
return ['chart']
}
},
isPredefined: true
}

const state = {
inquiries: [],
tabs: [tab],
}

await saveInquiry({ state }, {
inquiryTab: tab,
newName: 'foo'
})

const inquiries = state.inquiries
expect(inquiries).has.lengthOf(1)
expect(inquiries[0]).to.have.property('id').which.not.equal(tab.id)
expect(inquiries[0].name).to.equal('foo')
expect(inquiries[0].query).to.equal(tab.query)
expect(inquiries[0].viewOptions).to.eql(['chart'])
expect(new Date(inquiries[0].createdAt)).to.be.within(now, nowPlusMinute)
})
})
Loading

0 comments on commit f55a8ca

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/lana-k/sqliteviz/commit/f55a8caa92bb90c930f154cc4b5ef3e03c8a8965

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy