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 @@ -15,9 +15,26 @@
class="box-content"
>
<div class="box-icon">
<KIcon :icon="icon" />
<KIcon
:icon="icon"
:style="{ fontSize: '18px' }"
/>
</div>
<div class="box-text">
<div
v-if="$slots.title || title"
class="box-title"
>
<slot name="title">{{ title }}</slot>
</div>
<div
v-if="$slots.description || description"
class="box-description"
>
<slot name="description">{{ description }}</slot>
</div>
<slot></slot>
</div>
<slot></slot>
<div
v-if="$slots.chip"
class="chip"
Expand Down Expand Up @@ -45,37 +62,47 @@
const boxBackgroundColor = computed(() => {
switch (props.kind) {
case 'warning':
return paletteTheme.yellow.v_100;
return paletteTheme.red.v_100;
case 'info':
return paletteTheme.grey.v_100;
default:
throw new Error(`Unsupported box kind: ${props.kind}`);
}
});
const boxTextColor = computed(() => {
const boxBorderColor = computed(() => {
switch (props.kind) {
case 'warning':
return paletteTheme.red.v_500;
return paletteTheme.red.v_300;
case 'info':
return tokensTheme.text;
return 'transparent';
default:
throw new Error(`Unsupported box kind: ${props.kind}`);
return 'transparent';
}
});
const icon = computed(() => {
switch (props.kind) {
case 'warning':
return 'warningIncomplete';
return 'error';
case 'info':
return 'infoOutline';
default:
throw new Error(`Unsupported box kind: ${props.kind}`);
}
});

const titleColor = computed(() => {
return props.kind === 'warning' ? paletteTheme.red.v_600 : tokensTheme.text;
});

const descriptionColor = computed(() => {
return props.kind === 'warning' ? paletteTheme.grey.v_800 : tokensTheme.text;
});

return {
boxBackgroundColor,
boxTextColor,
boxBorderColor,
titleColor,
descriptionColor,
icon,
};
},
Expand All @@ -91,6 +118,16 @@
required: false,
default: false,
},
title: {
type: String,
required: false,
default: '',
},
description: {
type: String,
required: false,
default: '',
},
},
};

Expand All @@ -100,20 +137,46 @@
<style lang="scss" scoped>

.box {
padding: 8px;
color: v-bind('boxTextColor');
padding: 10px;
background-color: v-bind('boxBackgroundColor');
border: 1px solid v-bind('boxBorderColor');
border-radius: 4px;
}

.box-content {
display: flex;
gap: 8px;
align-items: start;
}

.box-icon {
width: 20px;
height: 20px;
display: flex;
flex-shrink: 0;
align-items: center;
justify-content: center;
width: 18px;
height: 18px;
font-size: 18px;
line-height: 1;
}

.box-text {
display: flex;
flex: 1;
flex-direction: column;
gap: 4px;
font-size: 14px;
line-height: 140%;
}

.box-title {
font-weight: 600;
color: v-bind('titleColor');
}

.box-description {
font-weight: 400;
color: v-bind('descriptionColor');
}

.chip {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,16 @@ jest.mock('shared/data/resources', () => ({

const store = factory();

const {
nonePrimaryInfo$,
flaggedPrimaryInfo$,
approvedPrimaryInfo$,
submittedPrimaryInfo$,
reviewersWillSeeLatestFirst$,
} = communityChannelsStrings;
const { nonePrimaryInfo$, flaggedPrimaryInfo$, approvedPrimaryInfo$, submittedPrimaryInfo$ } =
communityChannelsStrings;

async function makeWrapper({ channel, publishedData, latestSubmission }) {
const isLoading = ref(true);
const isFinished = ref(false);

store.state.currentChannel.currentChannelId = channel.id;
store.commit('channel/ADD_CHANNEL', channel);

usePublishedData.mockReturnValue({
isLoading,
isFinished,
Expand Down Expand Up @@ -79,9 +77,9 @@ const publishedNonPublicChannel = {
};

const publicChannel = {
id: 'published-non-public-channel',
id: 'public-channel',
version: 2,
name: 'Published Non-Public Channel',
name: 'Public Channel',
published: true,
public: true,
};
Expand Down Expand Up @@ -110,6 +108,10 @@ const publishedData = {
const submittedLatestSubmission = { channel_version: 2, status: CommunityLibraryStatus.PENDING };

describe('SubmitToCommunityLibrarySidePanel', () => {
beforeEach(() => {
store.state.currentChannel.currentChannelId = null;
store.state.channel.channelsMap = {};
});
describe('correct warnings are shown', () => {
it('when channel is published, not public and not submitted', async () => {
const wrapper = await makeWrapper({
Expand Down Expand Up @@ -178,10 +180,9 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
latestSubmission: null,
});

const infoBoxes = wrapper.findAllComponents(Box).filter(box => box.props('kind') === 'info');
expect(infoBoxes.length).toBe(1);
const infoBox = infoBoxes.wrappers[0];
expect(infoBox.text()).toContain(nonePrimaryInfo$());
const infoSection = wrapper.find('.info-section');
expect(infoSection.exists()).toBe(true);
expect(infoSection.text()).toContain(nonePrimaryInfo$());
});

it('when the previous submission was rejected', async () => {
Expand All @@ -191,10 +192,9 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
latestSubmission: { channel_version: 1, status: CommunityLibraryStatus.REJECTED },
});

const infoBoxes = wrapper.findAllComponents(Box).filter(box => box.props('kind') === 'info');
expect(infoBoxes.length).toBe(1);
const infoBox = infoBoxes.wrappers[0];
expect(infoBox.text()).toContain(flaggedPrimaryInfo$());
const infoSection = wrapper.find('.info-section');
expect(infoSection.exists()).toBe(true);
expect(infoSection.text()).toContain(flaggedPrimaryInfo$());
});

it('when the previous submission was approved', async () => {
Expand All @@ -204,11 +204,9 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
latestSubmission: { channel_version: 1, status: CommunityLibraryStatus.APPROVED },
});

const infoBoxes = wrapper.findAllComponents(Box).filter(box => box.props('kind') === 'info');
expect(infoBoxes.length).toBe(1);
const infoBox = infoBoxes.wrappers[0];
expect(infoBox.text()).toContain(approvedPrimaryInfo$());
expect(infoBox.text()).toContain(reviewersWillSeeLatestFirst$());
const infoSection = wrapper.find('.info-section');
expect(infoSection.exists()).toBe(true);
expect(infoSection.text()).toContain(approvedPrimaryInfo$());
});

it('when the previous submission is pending', async () => {
Expand All @@ -218,11 +216,9 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
latestSubmission: { channel_version: 1, status: CommunityLibraryStatus.PENDING },
});

const infoBoxes = wrapper.findAllComponents(Box).filter(box => box.props('kind') === 'info');
expect(infoBoxes.length).toBe(1);
const infoBox = infoBoxes.wrappers[0];
expect(infoBox.text()).toContain(submittedPrimaryInfo$());
expect(infoBox.text()).toContain(reviewersWillSeeLatestFirst$());
const infoSection = wrapper.find('.info-section');
expect(infoSection.exists()).toBe(true);
expect(infoSection.text()).toContain(submittedPrimaryInfo$());
});
});

Expand Down Expand Up @@ -256,17 +252,16 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
latestSubmission: null,
});

let moreDetails = wrapper.find('[data-test="more-details"]');
expect(moreDetails.exists()).toBe(false);
const infoText = wrapper.find('.info-text');
expect(infoText.text()).not.toContain('The Kolibri Community Library features channels');

let moreDetailsButton = wrapper.find('[data-test="more-details-button"]');
const moreDetailsButton = wrapper.find('[data-test="more-details-button"]');
await moreDetailsButton.trigger('click');

moreDetails = wrapper.find('.more-details-text');
expect(moreDetails.exists()).toBe(true);
expect(infoText.text()).toContain('The Kolibri Community Library features channels');

moreDetailsButton = wrapper.find('[data-test="more-details-button"]');
expect(moreDetailsButton.exists()).toBe(false);
const lessDetailsButton = wrapper.find('[data-test="less-details-button"]');
expect(lessDetailsButton.exists()).toBe(true);
});
});

Expand Down Expand Up @@ -478,6 +473,7 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
});

it('the panel closes', async () => {
jest.useFakeTimers();
const wrapper = await makeWrapper({
channel: publishedNonPublicChannel,
publishedData,
Expand All @@ -491,9 +487,11 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
await submitButton.trigger('click');

expect(wrapper.emitted('close')).toBeTruthy();
jest.useRealTimers();
});

it('a submission snackbar is shown', async () => {
jest.useFakeTimers();
const wrapper = await makeWrapper({
channel: publishedNonPublicChannel,
publishedData,
Expand All @@ -505,14 +503,15 @@ describe('SubmitToCommunityLibrarySidePanel', () => {

const submitButton = wrapper.find('[data-test="submit-button"]');
await submitButton.trigger('click');

jest.useFakeTimers();
await wrapper.vm.$nextTick();

expect(store.getters['snackbarIsVisible']).toBe(true);
expect(CommunityLibrarySubmission.create).not.toHaveBeenCalled();
jest.useRealTimers();
});

it('the submission is created after a timeout', async () => {
jest.useFakeTimers();
const wrapper = await makeWrapper({
channel: publishedNonPublicChannel,
publishedData,
Expand All @@ -524,20 +523,22 @@ describe('SubmitToCommunityLibrarySidePanel', () => {

const countryField = wrapper.findComponent(CountryField);
await countryField.vm.$emit('input', ['Czech Republic']);

jest.useFakeTimers();
await wrapper.vm.$nextTick();

const submitButton = wrapper.find('[data-test="submit-button"]');
await submitButton.trigger('click');
await wrapper.vm.$nextTick();

jest.runAllTimers();
await wrapper.vm.$nextTick();

expect(CommunityLibrarySubmission.create).toHaveBeenCalledWith({
description: 'Some description',
channel: publishedNonPublicChannel.id,
countries: ['CZ'],
categories: [Categories.SCHOOL],
});
jest.useRealTimers();
});
});

Expand Down
Loading