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
2 changes: 2 additions & 0 deletions contentcuration/contentcuration/frontend/shared/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ import ActionLink from 'shared/views/ActionLink';
import Icon from 'shared/views/Icon';
import BaseMenu from 'shared/views/BaseMenu.vue';
import Divider from 'shared/views/Divider';
import Teleport from 'shared/views/QTIEditor/components/Teleport.vue';
import { initializeDB, resetDB } from 'shared/data';
import { Session, injectVuexStore } from 'shared/data/resources';

Expand Down Expand Up @@ -259,6 +260,7 @@ Vue.component('ActionLink', ActionLink);
Vue.component('BaseMenu', BaseMenu);
Vue.component('Divider', Divider);
Vue.component('Icon', Icon);
Vue.component('Teleport', Teleport);

function initiateServiceWorker() {
// Second conditional must be removed if you are doing dev work on the service
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import { render, screen, fireEvent } from '@testing-library/vue';
import VueRouter from 'vue-router';
import AnswerSettings from '../index.vue';
import { qtiEditorStrings as tr } from '../../../qtiEditorStrings';

jest.mock('kolibri-design-system/lib/composables/useKResponsiveWindow', () => {
const { ref } = require('vue');
return {
__esModule: true,
default: () => ({ windowIsSmall: ref(false) }),
};
});

const defaultProps = {
settings: ['shuffle', 'showAnswerCount'],
shuffle: false,
showAnswerCount: true,
};

describe('AnswerSettings', () => {
it('renders answer settings label', () => {
render(AnswerSettings, { props: defaultProps, routes: new VueRouter() });
expect(screen.getByText(tr.$tr('answerSettingsLabel'))).toBeInTheDocument();
});

it('renders shuffle checkbox when included in settings', () => {
render(AnswerSettings, { props: defaultProps, routes: new VueRouter() });
expect(
screen.getByRole('checkbox', { name: tr.$tr('shuffleAnswersLabel') }),
).toBeInTheDocument();
});

it('renders show answer count checkbox when included in settings', () => {
render(AnswerSettings, { props: defaultProps, routes: new VueRouter() });
expect(
screen.getByRole('checkbox', { name: tr.$tr('showAnswerCountLabel') }),
).toBeInTheDocument();
});

it('does not render shuffle checkbox when not in settings', () => {
render(AnswerSettings, {
props: { ...defaultProps, settings: ['showAnswerCount'] },
routes: new VueRouter(),
});
expect(
screen.queryByRole('checkbox', { name: tr.$tr('shuffleAnswersLabel') }),
).not.toBeInTheDocument();
});

it('does not render show answer count checkbox when not in settings', () => {
render(AnswerSettings, {
props: { ...defaultProps, settings: ['shuffle'] },
routes: new VueRouter(),
});
expect(
screen.queryByRole('checkbox', { name: tr.$tr('showAnswerCountLabel') }),
).not.toBeInTheDocument();
});

it('emits update:shuffle when shuffle checkbox toggled', async () => {
const { emitted } = render(AnswerSettings, { props: defaultProps, routes: new VueRouter() });

const checkbox = screen.getByRole('checkbox', { name: tr.$tr('shuffleAnswersLabel') });
await fireEvent.click(checkbox);

expect(emitted()['update:shuffle']).toBeTruthy();
expect(emitted()['update:shuffle'][0]).toEqual([true]);
});

it('emits update:showAnswerCount when show answer count checkbox toggled', async () => {
const { emitted } = render(AnswerSettings, { props: defaultProps, routes: new VueRouter() });

const checkbox = screen.getByRole('checkbox', { name: tr.$tr('showAnswerCountLabel') });
await fireEvent.click(checkbox);

expect(emitted()['update:showAnswerCount']).toBeTruthy();
expect(emitted()['update:showAnswerCount'][0]).toEqual([false]);
});

it('opens shuffle info modal when info button clicked', async () => {
render(AnswerSettings, { props: defaultProps, routes: new VueRouter() });

const infoButtons = screen.getAllByRole('button', { name: tr.$tr('shuffleAnswersInfoTitle') });
await fireEvent.click(infoButtons[0]);

expect(screen.getByRole('dialog')).toBeInTheDocument();
expect(screen.getByText(tr.$tr('shuffleAnswersInfoBody'))).toBeInTheDocument();
});

it('opens show answer count info modal when info button clicked', async () => {
render(AnswerSettings, { props: defaultProps, routes: new VueRouter() });

const infoButtons = screen.getAllByRole('button', {
name: tr.$tr('showAnswerCountInfoTitle'),
});
await fireEvent.click(infoButtons[0]);

expect(screen.getByRole('dialog')).toBeInTheDocument();
expect(screen.getByText(tr.$tr('showAnswerCountInfoBody'))).toBeInTheDocument();
});

it('closes modal when Close button clicked', async () => {
render(AnswerSettings, { props: defaultProps, routes: new VueRouter() });

const infoButtons = screen.getAllByRole('button', { name: tr.$tr('shuffleAnswersInfoTitle') });
await fireEvent.click(infoButtons[0]);
expect(screen.getByRole('dialog')).toBeInTheDocument();

await fireEvent.click(screen.getByRole('button', { name: tr.$tr('closeBtnLabel') }));
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
});

it('reflects shuffle prop value in checkbox', () => {
render(AnswerSettings, {
props: { ...defaultProps, shuffle: true },
routes: new VueRouter(),
});

const checkbox = screen.getByRole('checkbox', { name: tr.$tr('shuffleAnswersLabel') });
expect(checkbox).toBeChecked();
});

it('reflects showAnswerCount prop value in checkbox', () => {
render(AnswerSettings, {
props: { ...defaultProps, showAnswerCount: false },
routes: new VueRouter(),
});

const checkbox = screen.getByRole('checkbox', { name: tr.$tr('showAnswerCountLabel') });
expect(checkbox).not.toBeChecked();
});
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, given that this will only be used in the editor, could we move this component to the choice folder instead?

Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
<template>

<div class="answer-settings">
<div
class="answer-settings-label"
:style="{ color: $themePalette.grey.v_700 }"
>
{{ answerSettingsLabel$() }}
</div>

<div
v-if="settings.includes('shuffle')"
class="setting-row"
>
<KCheckbox
:checked="shuffle"
:label="shuffleAnswersLabel$()"
:color="$themeTokens.primary"
@change="$emit('update:shuffle', $event)"
/>
<KIconButton
icon="infoOutline"
:tooltip="shuffleAnswersInfoTitle$()"
:ariaLabel="shuffleAnswersInfoTitle$()"
size="mini"
:color="$themePalette.grey.v_700"
@click="showShuffleModal = true"
/>
</div>

<div
v-if="settings.includes('showAnswerCount')"
class="setting-row"
>
<KCheckbox
:checked="showAnswerCount"
:label="showAnswerCountLabel$()"
:color="$themeTokens.primary"
@change="$emit('update:showAnswerCount', $event)"
/>
<KIconButton
icon="infoOutline"
:tooltip="showAnswerCountInfoTitle$()"
:ariaLabel="showAnswerCountInfoTitle$()"
size="mini"
:color="$themePalette.grey.v_700"
@click="showAnswerCountModal = true"
/>
</div>

<KModal
v-if="showShuffleModal"
:title="shuffleAnswersInfoTitle$()"
@cancel="showShuffleModal = false"
>
<p :style="{ color: $themeTokens.annotation }">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem

{{ shuffleAnswersInfoBody$() }}
</p>
<template #actions>
<KButton
:text="closeBtnLabel$()"
@click="showShuffleModal = false"
/>
</template>
</KModal>

<KModal
v-if="showAnswerCountModal"
:title="showAnswerCountInfoTitle$()"
@cancel="showAnswerCountModal = false"
>
<p :style="{ color: $themeTokens.annotation }">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can leave the normal text color here, instead of this annotation.

{{ showAnswerCountInfoBody$() }}
</p>
<template #actions>
<KButton
:text="closeBtnLabel$()"
@click="showAnswerCountModal = false"
/>
</template>
Comment on lines +75 to +80

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also just use the cancelText prop instead of this actions slot. Usually the actions slot is used for more complex button layouts.

</KModal>
</div>

</template>


<script>

import { ref } from 'vue';
import { qtiEditorStrings } from '../../qtiEditorStrings';

export default {
name: 'AnswerSettings',

setup() {
const {
answerSettingsLabel$,
shuffleAnswersLabel$,
shuffleAnswersInfoTitle$,
shuffleAnswersInfoBody$,
showAnswerCountLabel$,
showAnswerCountInfoTitle$,
showAnswerCountInfoBody$,
closeBtnLabel$,
} = qtiEditorStrings;

const showShuffleModal = ref(false);
const showAnswerCountModal = ref(false);

return {
answerSettingsLabel$,
shuffleAnswersLabel$,
shuffleAnswersInfoTitle$,
shuffleAnswersInfoBody$,
showAnswerCountLabel$,
showAnswerCountInfoTitle$,
showAnswerCountInfoBody$,
closeBtnLabel$,
showShuffleModal,
showAnswerCountModal,
};
},

props: {
settings: {
type: Array,
required: true,
validator: arr => arr.every(setting => ['shuffle', 'showAnswerCount'].includes(setting)),
},
Comment on lines +125 to +129

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this will only be rendered for choice interactions, I think it's fine to let it infer when to display each based on the questionType instead of this settings prop.

shuffle: {
type: Boolean,
default: false,
},
showAnswerCount: {
type: Boolean,
default: true,
},
},

emits: ['update:shuffle', 'update:showAnswerCount'],
};

</script>


<style lang="scss" scoped>

.answer-settings {
display: flex;
flex-direction: column;
}

.answer-settings-label {
font-size: 12px;
font-weight: 600;
line-height: 1.4;
white-space: nowrap;
}

.setting-row {
display: flex;
gap: 8px;
align-items: center;
}

</style>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { render, screen } from '@testing-library/vue';
import { nextTick } from 'vue';
import VueRouter from 'vue-router';
import InteractionSection from '../index.vue';
import { qtiEditorStrings as tr } from '../../../qtiEditorStrings';

import {
CHOICE_SINGLE_SELECT_XML,
Expand All @@ -10,6 +11,13 @@ import {
} from '../../../utils/testingFixtures';

jest.mock('shared/views/TipTapEditor/TipTapEditor/TipTapEditor');
jest.mock('kolibri-design-system/lib/composables/useKResponsiveWindow', () => {
const { ref } = require('vue');
return {
__esModule: true,
default: () => ({ windowIsSmall: ref(false) }),
};
});

const renderSection = (props = {}) =>
render(InteractionSection, {
Expand Down Expand Up @@ -41,7 +49,7 @@ describe('InteractionSection', () => {
describe('parse error handling', () => {
it('shows a parse error when XML is malformed', () => {
renderSection({ interaction: interactionBlock('not-xml<{{') });
expect(screen.getByText('This question could not be loaded')).toBeInTheDocument();
expect(screen.getByText(tr.$tr('errorParsingQuestion'))).toBeInTheDocument();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
:interaction="interaction"
:mode="mode"
:showAnswers="showAnswers"
:teleportTarget="teleportTarget"
@update:interaction="interaction => $emit('update:interaction', interaction)"
/>
</div>
Expand Down Expand Up @@ -66,6 +67,10 @@
type: Boolean,
default: false,
},
teleportTarget: {
type: String,
default: '',
},
},

emits: ['update:questionType', 'update:interaction'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import { qtiEditorStrings } from '../../../qtiEditorStrings';
import { AssessmentItemTypes } from '../../../constants';

jest.mock('shared/views/TipTapEditor/TipTapEditor/TipTapEditor');
jest.mock('kolibri-design-system/lib/composables/useKResponsiveWindow', () => {
const { ref } = require('vue');
return {
__esModule: true,
default: () => ({ windowIsSmall: ref(false) }),
};
});

const { closeBtnLabel$, questionContentPlaceholder$ } = qtiEditorStrings;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@
</div>
</div>

<div :id="`qti-question-settings-${index}`"></div>

<div class="question-card-body">
<InteractionSection
v-if="interactions.length > 0"
:interaction="interactions[0]"
:mode="mode"
:showAnswers="showAnswers"
:teleportTarget="`#qti-question-settings-${index}`"
@update:questionType="type => (currentQuestionType = type)"
@update:interaction="onUpdateInteraction"
/>
Expand Down
Loading
Loading