Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>

<VLayout v-if="channel" align-center wrap class="pa-2">
<VLayout v-if="channel" align-center wrap class="pa-2" @click="handleClick">
<VFlex class="pa-2" xs12 sm4 md3 lg2>
<Thumbnail :src="channel.thumbnail_url" />
</VFlex>
Expand Down Expand Up @@ -47,6 +47,11 @@
return this.getChannel(this.channelId);
},
},
methods: {
handleClick() {
this.$emit('click', this.channelId);
},
},
$trs: {
versionText: 'Version {version}',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@
hover
class="list-card-hover px-3"
>
<Checkbox
v-model="selectedChannels"
color="primary"
:data-test="`checkbox-${channel.id}`"
:value="channel.id"
class="channel ma-0"
>
<ChannelItem :channelId="channel.id" />
</Checkbox>
<VLayout align-center row>
<Checkbox
v-model="selectedChannels"
color="primary"
:data-test="`checkbox-${channel.id}`"
:value="channel.id"
class="channel ma-0"
/>
<ChannelItem
:channelId="channel.id"
:data-test="`channel-item-${channel.id}`"
@click="handleSelectChannel"
/>
</VLayout>
</VCard>
</template>
</template>
Expand Down Expand Up @@ -112,6 +117,11 @@
},
methods: {
...mapActions('channel', ['loadChannelList']),
handleSelectChannel(channelId) {
this.selectedChannels = this.selectedChannels.includes(channelId)
? this.selectedChannels.filter(id => id !== channelId)
: [...this.selectedChannels, channelId];
},
},
$trs: {
searchText: 'Search for a channel',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mount } from '@vue/test-utils';
import Vuex from 'vuex';
import ChannelSelectionList from '../ChannelSelectionList';
import { ChannelListTypes } from 'shared/constants';

Expand All @@ -25,6 +26,25 @@ const publicChannel = {
published: true,
};

const getters = {
channels: jest.fn(() => [editChannel, editChannel2, publicChannel]),
getChannel: jest.fn(() => () => editChannel),
};

const actions = {
loadChannelList: jest.fn(() => Promise.resolve()),
};

const store = new Vuex.Store({
modules: {
channel: {
namespaced: true,
getters,
actions,
},
},
});

function makeWrapper() {
return mount(ChannelSelectionList, {
sync: false,
Expand All @@ -41,9 +61,7 @@ function makeWrapper() {
return Promise.resolve();
},
},
stubs: {
ChannelItem: true,
},
store,
});
}

Expand Down Expand Up @@ -77,4 +95,17 @@ describe('channelSelectionList', () => {
expect(wrapper.vm.listChannels.find(c => c.id === editChannel.id)).toBeTruthy();
expect(wrapper.vm.listChannels.find(c => c.id === editChannel2.id)).toBeFalsy();
});
it('should select channels when the channel card has been clicked', () => {
wrapper.setData({ loading: false });
wrapper.find(`[data-test="channel-item-${editChannel.id}"]`).trigger('click');
expect(wrapper.emitted('input')[0][0]).toEqual([editChannel.id]);
});
it('should deselect channels when the channel card has been clicked', () => {
wrapper.setData({ loading: false });
wrapper.find(`[data-test="channel-item-${editChannel.id}"]`).element.click(); // Check the channel
wrapper.find(`[data-test="channel-item-${editChannel.id}"]`).element.click(); // Uncheck the channel

expect(wrapper.emitted('input')[0].length).toEqual(1); // Only one event should be emitted (corresponding to the initial check)
expect(wrapper.emitted('input')[0][0]).toEqual([editChannel.id]); // The initial check event should be emitted
});
});