-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: 🚨 Added tests for track search
- Loading branch information
1 parent
14f9f77
commit bee2f27
Showing
7 changed files
with
152 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = { | ||
presets: [ | ||
[ | ||
'@babel/env', | ||
{ | ||
targets: { | ||
browsers: [ | ||
'last 6 chrome versions', | ||
'last 6 firefox versions', | ||
'last 3 safari versions', | ||
'last 3 edge versions', | ||
], | ||
}, | ||
}, | ||
], | ||
], | ||
env: { | ||
test: { | ||
presets: [['@babel/preset-env', { targets: { node: 'current' } }]], | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import flushPromises from 'flush-promises' | ||
import TrackSearch from './TrackSearch.vue' | ||
import createTestRenderer from '../../utils/testing/createTestRenderer' | ||
import Spotify from '../../utils/Spotify' | ||
|
||
jest.mock('../../utils/Spotify') | ||
|
||
const testTracks = [ | ||
{ | ||
name: 'foo', | ||
uri: 'foo-uri', | ||
image: 'foo-image', | ||
artist: 'foo-artist', | ||
duration_ms: 3600, | ||
}, | ||
{ | ||
name: 'bar', | ||
uri: 'bar-uri', | ||
image: 'bar-image', | ||
artist: 'bar-artist', | ||
duration_ms: 3600, | ||
}, | ||
] | ||
|
||
describe('TrackSearch', () => { | ||
beforeAll(() => { | ||
Spotify.searchTracks.mockResolvedValue(testTracks) | ||
}) | ||
|
||
const searchForTracks = async wrapper => { | ||
const input = wrapper.find('input') | ||
input.element.value = 'foobar' | ||
input.trigger('input') | ||
await flushPromises() | ||
} | ||
|
||
const shallowMountWithVuex = createTestRenderer(TrackSearch, { | ||
shallow: true, | ||
}) | ||
|
||
it('searches for entered input', () => { | ||
const { wrapper } = shallowMountWithVuex({}) | ||
const input = wrapper.find('input') | ||
input.element.value = 'foobar' | ||
input.trigger('input') | ||
expect(Spotify.searchTracks).toHaveBeenCalledWith('foobar') | ||
}) | ||
|
||
it('shows track items for each found track', async () => { | ||
const { wrapper } = shallowMountWithVuex({}) | ||
|
||
const results = wrapper.find('.results') | ||
expect(results.text()).toContain('No results :(') | ||
|
||
await searchForTracks(wrapper) | ||
|
||
const tracks = wrapper.findAll('search-playlist-item-stub') | ||
expect(tracks).toHaveLength(2) | ||
tracks.wrappers.forEach((track, i) => { | ||
expect(track.props('track').name).toBe(testTracks[i].name) | ||
}) | ||
}) | ||
|
||
it('clicking on a track will add it to the "added" list, clicking again removes it', async () => { | ||
const { wrapper } = shallowMountWithVuex({}) | ||
|
||
await searchForTracks(wrapper) | ||
|
||
const tracks = wrapper.findAll('search-playlist-item-stub') | ||
const clickIndex = 1 | ||
const fooTrack = tracks.at(clickIndex) | ||
fooTrack.trigger('click') | ||
|
||
let addedTracks = wrapper.findAll('.add-list search-playlist-item-stub') | ||
expect(addedTracks).toHaveLength(1) | ||
expect(addedTracks.at(0).props('track').name).toBe( | ||
testTracks[clickIndex].name | ||
) | ||
|
||
addedTracks.at(0).trigger('click') | ||
addedTracks = wrapper.findAll('.add-list search-playlist-item-stub') | ||
expect(addedTracks).toHaveLength(0) | ||
}) | ||
|
||
it('adding tracks emits their uris in a select event', async () => { | ||
const { wrapper } = shallowMountWithVuex({}) | ||
|
||
await searchForTracks(wrapper) | ||
|
||
const tracks = wrapper.findAll('search-playlist-item-stub') | ||
tracks.wrappers.forEach(track => track.trigger('click')) | ||
|
||
expect(wrapper.emitted().select).toBeTruthy() | ||
expect(wrapper.emitted().select).toHaveLength(2) | ||
|
||
expect(wrapper.emitted().select).toEqual([ | ||
[['foo-uri']], | ||
[['foo-uri', 'bar-uri']], | ||
]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bee2f27
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#73
bee2f27
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#10