Skip to content

Commit f38a78b

Browse files
committed
fix(ui): importing playlist during tutorial will skip latest steps
1 parent 5af4b60 commit f38a78b

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

renderer/stores/tutorial.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict'
22

3+
import { tick } from 'svelte'
34
import { BehaviorSubject, Subject } from 'rxjs'
45
import { location, replace } from 'svelte-spa-router'
56
import { albums } from './albums'
6-
import { playlists } from './playlists'
77
import { tracks } from './track-queue'
8-
import { tick } from 'svelte'
8+
import { lastInvokation } from '../utils'
99

1010
const steps = [
1111
{
@@ -40,7 +40,8 @@ const steps = [
4040
annotation: {
4141
left: '15%'
4242
},
43-
listen: () => awaitsEvent(playlists, playlists => playlists.length > 0)
43+
listen: () =>
44+
awaitsEvent(lastInvokation, ({ invoked }) => invoked === 'playlists.save')
4445
},
4546
{
4647
anchorId: 'to-playlists',

renderer/stores/tutorial.test.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,7 @@ describe('tutorial store', () => {
101101
})
102102

103103
it('goes to sixth step when creating a playlist', async () => {
104-
mockInvoke.mockResolvedValueOnce({
105-
results: [{}],
106-
total: 1,
107-
size: 1,
108-
from: 0
109-
})
110-
playlists.list()
104+
playlists.save({ name: 'my playlist', trackIds: [123456] })
111105
await sleep()
112106
expect(get(current)).toEqual(
113107
expect.objectContaining({

renderer/utils/invoke.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
// note: do not destructure, as it makes it harder to mock in Storybook
44
const electron = require('electron')
5+
import { BehaviorSubject } from 'rxjs'
6+
7+
const lastInvokation$ = new BehaviorSubject()
8+
9+
export const lastInvokation = lastInvokation$.asObservable()
510

611
export async function invoke(invoked, ...args) {
12+
lastInvokation$.next({ invoked, args })
713
return electron.ipcRenderer.invoke('remote', ...invoked.split('.'), ...args)
814
}

renderer/utils/invoke.test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
'use strict'
22

3+
import { get } from 'svelte/store'
34
import faker from 'faker'
4-
import { invoke } from './invoke'
5+
import { invoke, lastInvokation } from './invoke'
56
import electron from 'electron'
7+
import { sleep } from '../tests'
68

79
jest.mock('electron', () => ({
810
ipcRenderer: {
@@ -29,5 +31,10 @@ describe('invoke', () => {
2931
arg2
3032
)
3133
expect(electron.ipcRenderer.invoke).toHaveBeenCalledTimes(1)
34+
await sleep()
35+
expect(get(lastInvokation)).toEqual({
36+
invoked: 'dialog.showOpenDialog',
37+
args: [arg1, arg2]
38+
})
3239
})
3340
})

0 commit comments

Comments
 (0)