Skip to content
Open
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
Expand Up @@ -38,17 +38,17 @@
lg10
xl8
>
<VForm ref="channelsetform">
<VTextField
<form>
<KTextbox
v-model="name"
:rules="nameRules"
:label="$tr('titleLabel')"
maxlength="200"
counter
box
:invalid="errors.name"
:invalidText="$tr('titleRequiredText')"
showInvalidText
data-test="input-name"
/>
</VForm>
</form>

<div v-if="channelSet.secret_token">
<p>{{ $tr('tokenPrompt') }}</p>
Expand Down Expand Up @@ -213,13 +213,20 @@
import ChannelItem from './ChannelItem';
import ChannelSelectionList from './ChannelSelectionList';
import { ChannelListTypes, ErrorTypes } from 'shared/constants';
import { constantsTranslationMixin, routerMixin } from 'shared/mixins';
import { generateFormMixin, constantsTranslationMixin, routerMixin } from 'shared/mixins';
import CopyToken from 'shared/views/CopyToken';
import MessageDialog from 'shared/views/MessageDialog';
import FullscreenModal from 'shared/views/FullscreenModal';
import Tabs from 'shared/views/Tabs';
import LoadingText from 'shared/views/LoadingText';

const formMixin = generateFormMixin({
name: {
required: true,
validator: v => v && v.trim().length > 0,
},
});

export default {
name: 'ChannelSetModal',
components: {
Expand All @@ -231,7 +238,7 @@
Tabs,
LoadingText,
},
mixins: [constantsTranslationMixin, routerMixin],
mixins: [formMixin, constantsTranslationMixin, routerMixin],
props: {
channelSetId: {
type: String,
Expand All @@ -255,9 +262,6 @@
isNew() {
return this.$route.path === '/collections/new';
},
nameRules() {
return [name => (name && name.trim().length ? true : this.$tr('titleRequiredText'))];
},
name: {
get() {
return Object.prototype.hasOwnProperty.call(this.diffTracker, 'name')
Expand Down Expand Up @@ -384,44 +388,49 @@
this.saving = true;
this.showUnsavedDialog = false;

if (this.$refs.channelsetform.validate()) {
let promise;
const formData = this.clean();
if (!this.validate(formData)) {
this.saving = false;
this.$store.dispatch('showSnackbarSimple', this.errorText());
return;
}

if (this.isNew) {
const channelSetData = { ...this.diffTracker };
promise = this.commitChannelSet(channelSetData)
.then(newCollection => {
if (!newCollection || !newCollection.id) {
this.saving = false;
return;
}
let promise;

const newCollectionId = newCollection.id;
if (this.isNew) {
const channelSetData = { ...this.diffTracker, ...formData };
promise = this.commitChannelSet(channelSetData)
.then(newCollection => {
if (!newCollection || !newCollection.id) {
this.saving = false;
return;
}

this.$router.replace({
name: 'CHANNEL_SET_DETAILS',
params: { channelSetId: newCollectionId },
});
const newCollectionId = newCollection.id;

return newCollection;
})
.catch(() => {
this.saving = false;
this.$router.replace({
name: 'CHANNEL_SET_DETAILS',
params: { channelSetId: newCollectionId },
});
} else {
promise = this.saveChannels().then(() => {
return this.updateChannelSet({ id: this.channelSetId, ...this.diffTracker });
});
}

promise
.then(() => {
this.close();
return newCollection;
})
.finally(() => {
.catch(() => {
this.saving = false;
});
} else {
promise = this.saveChannels().then(() => {
return this.updateChannelSet({ id: this.channelSetId, ...this.diffTracker });
});
}

promise
.then(() => {
this.close();
})
.finally(() => {
this.saving = false;
});
},

cancelChanges() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ describe('ChannelSetModal', () => {
it('should prompt user if there are unsaved changes', async () => {
expect(getUnsavedDialog(wrapper).attributes('data-test-visible')).toBeFalsy();

await getCollectionNameInput(wrapper).setValue('My collection');
await wrapper.setData({ name: 'My collection' });
await getCloseButton(wrapper).trigger('click');

expect(getUnsavedDialog(wrapper).attributes('data-test-visible')).toBeTruthy();
Expand All @@ -228,23 +228,23 @@ describe('ChannelSetModal', () => {

describe('clicking save button', () => {
it("shouldn't update a channel set when a collection name is missing", async () => {
await getCollectionNameInput(wrapper).setValue('');
await wrapper.setData({ name: '' });
await getSaveButton(wrapper).trigger('click');
await flushPromises();

expect(updateChannelSet).not.toHaveBeenCalled();
});

it("shouldn't update a channel set when a collection name is made of empty characters", async () => {
await getCollectionNameInput(wrapper).setValue(' ');
await wrapper.setData({ name: ' ' });
await getSaveButton(wrapper).trigger('click');
await flushPromises();

expect(updateChannelSet).not.toHaveBeenCalled();
});

it('should update a channel set when a collection name is valid', async () => {
await getCollectionNameInput(wrapper).setValue('My collection');
await wrapper.setData({ name: 'My collection' });
await getSaveButton(wrapper).trigger('click');
await flushPromises();

Expand Down