Skip to content

Commit

Permalink
Update currentTab when close tabs #112
Browse files Browse the repository at this point in the history
  • Loading branch information
lana-k committed Jul 3, 2023
1 parent 41e0ae7 commit 6982204
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ export default {
state.currentTabId = state.tabs[index - 1].id
} else {
state.currentTabId = null
state.currentTab = null
state.untitledLastIndex = 0
}
state.currentTab = state.currentTabId
? state.tabs.find(tab => tab.id === state.currentTabId)
: null
}
state.tabs.splice(index, 1)
},
Expand Down
16 changes: 12 additions & 4 deletions tests/store/mutations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,15 @@ describe('mutations', () => {

const state = {
tabs: [tab1, tab2],
currentTabId: 1
currentTabId: 1,
currentTab: tab1
}

deleteTab(state, tab1)
expect(state.tabs).to.have.lengthOf(1)
expect(state.tabs[0].id).to.equal(2)
expect(state.currentTabId).to.equal(2)
expect(state.currentTab).to.eql(tab2)
})

it('deleteTab - opened, last', () => {
Expand All @@ -208,13 +210,15 @@ describe('mutations', () => {

const state = {
tabs: [tab1, tab2],
currentTabId: 2
currentTabId: 2,
currentTab: tab2
}

deleteTab(state, tab2)
expect(state.tabs).to.have.lengthOf(1)
expect(state.tabs[0].id).to.equal(1)
expect(state.currentTabId).to.equal(1)
expect(state.currentTab).to.eql(tab1)
})

it('deleteTab - opened, in the middle', () => {
Expand Down Expand Up @@ -250,14 +254,16 @@ describe('mutations', () => {

const state = {
tabs: [tab1, tab2, tab3],
currentTabId: 2
currentTabId: 2,
currentTab: tab2
}

deleteTab(state, tab2)
expect(state.tabs).to.have.lengthOf(2)
expect(state.tabs[0].id).to.equal(1)
expect(state.tabs[1].id).to.equal(3)
expect(state.currentTabId).to.equal(3)
expect(state.currentTab).to.eql(tab3)
})

it('deleteTab - opened, single', () => {
Expand All @@ -273,12 +279,14 @@ describe('mutations', () => {

const state = {
tabs: [tab1],
currentTabId: 1
currentTabId: 1,
currentTab: tab1
}

deleteTab(state, tab1)
expect(state.tabs).to.have.lengthOf(0)
expect(state.currentTabId).to.equal(null)
expect(state.currentTab).to.equal(null)
})

it('setCurrentTabId', () => {
Expand Down

0 comments on commit 6982204

Please sign in to comment.