-
-
Notifications
You must be signed in to change notification settings - Fork 302
feat: Initial Scaffold for QTI editor components and add a development page #5963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d189d84
9c4f5f9
47c618a
8ea08db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| <template> | ||
|
|
||
| <div> | ||
| <div style="padding: 16px 24px 0"> | ||
| <div | ||
| style=" | ||
| padding: 16px; | ||
| color: #2196f3; | ||
| background-color: transparent; | ||
| border: 1px solid #2196f3; | ||
| border-radius: 4px; | ||
| " | ||
| > | ||
| <strong>QTI Editor — Dev Demo</strong> | ||
| Hardcoded items. Changes are local only and not persisted. | ||
| </div> | ||
| </div> | ||
|
|
||
| <QTIEditor | ||
| :assessments="assessments" | ||
| @update="onUpdate" | ||
| /> | ||
| </div> | ||
|
|
||
| </template> | ||
|
|
||
|
|
||
| <script> | ||
|
|
||
| import { ref, defineComponent } from 'vue'; | ||
| import QTIEditor from 'shared/views/QTIEditor/index'; | ||
| import { QtiInteraction } from 'shared/views/QTIEditor/constants'; | ||
|
|
||
| /** | ||
| * Hardcoded items covering three interaction types so the closed-card | ||
| * type label can be visually verified. | ||
| */ | ||
| const INITIAL_ASSESSMENTS = [ | ||
| { | ||
| id: 'demo-item-1', | ||
| type: QtiInteraction.CHOICE, | ||
| title: 'Which planet is closest to the Sun?', | ||
| }, | ||
| { | ||
| id: 'demo-item-2', | ||
| type: QtiInteraction.EXTENDED_TEXT, | ||
| title: 'Describe the water cycle in your own words.', | ||
| }, | ||
| { | ||
| id: 'demo-item-3', | ||
| type: QtiInteraction.ORDER, | ||
| title: 'Arrange these events in chronological order.', | ||
| }, | ||
| ]; | ||
|
|
||
| export default defineComponent({ | ||
| name: 'QTIDemoPage', | ||
|
|
||
| components: { QTIEditor }, | ||
|
|
||
| setup() { | ||
| const assessments = ref(INITIAL_ASSESSMENTS); | ||
|
|
||
| function onUpdate(newList) { | ||
| assessments.value = newList; | ||
| } | ||
|
|
||
| return { assessments, onUpdate }; | ||
| }, | ||
| }); | ||
|
|
||
| </script> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import { render, screen } from '@testing-library/vue'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import VueRouter from 'vue-router'; | ||
| import CollapsibleToolbar from '../index.vue'; | ||
| import { commonStrings } from 'shared/strings/commonStrings'; | ||
|
|
||
| const { optionsLabel$ } = commonStrings; | ||
|
|
||
| const makeAction = (overrides = {}) => ({ | ||
| id: 'action-1', | ||
| icon: 'edit', | ||
| label: 'Edit', | ||
| handler: jest.fn(), | ||
| collapsed: false, | ||
| disabled: false, | ||
| ...overrides, | ||
| }); | ||
|
|
||
| const renderComponent = (actions = [], optionsLabel = null) => { | ||
| return render(CollapsibleToolbar, { | ||
| props: { actions, optionsLabel }, | ||
| routes: new VueRouter(), | ||
| }); | ||
| }; | ||
|
|
||
| describe('CollapsibleToolbar', () => { | ||
| describe('visible icon actions', () => { | ||
| test('renders icon buttons for non-collapsed actions with icons', () => { | ||
| const actions = [ | ||
| makeAction({ id: 'a1', label: 'Edit', icon: 'edit', collapsed: false }), | ||
| makeAction({ id: 'a2', label: 'Move up', icon: 'chevronUp', collapsed: false }), | ||
| ]; | ||
| renderComponent(actions); | ||
| expect(screen.getByRole('button', { name: 'Edit' })).toBeInTheDocument(); | ||
| expect(screen.getByRole('button', { name: 'Move up' })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('does not render an icon button for collapsed actions', () => { | ||
| const actions = [ | ||
| makeAction({ id: 'a1', label: 'Edit', icon: 'edit', collapsed: false }), | ||
| makeAction({ id: 'a2', label: 'Delete', icon: 'delete', collapsed: true }), | ||
| ]; | ||
| renderComponent(actions); | ||
| expect(screen.getByRole('button', { name: 'Edit' })).toBeInTheDocument(); | ||
| // 'Delete' only appears inside the dropdown, not as a standalone icon button | ||
| expect(screen.queryByRole('button', { name: 'Delete' })).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('calls the action handler when an icon button is clicked', async () => { | ||
| const user = userEvent.setup(); | ||
| const handler = jest.fn(); | ||
| const actions = [ | ||
| makeAction({ id: 'a1', label: 'Edit', icon: 'edit', collapsed: false, handler }), | ||
| ]; | ||
| renderComponent(actions); | ||
| await user.click(screen.getByRole('button', { name: 'Edit' })); | ||
| expect(handler).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe('collapsed dropdown menu', () => { | ||
| test('does not render the options button when there are no collapsed actions', () => { | ||
| const actions = [makeAction({ id: 'a1', icon: 'edit', collapsed: false })]; | ||
| renderComponent(actions); | ||
| expect(screen.queryByRole('button', { name: optionsLabel$() })).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('renders the options button when there are collapsed actions', () => { | ||
| const actions = [ | ||
| makeAction({ id: 'a1', icon: 'edit', collapsed: false }), | ||
| makeAction({ id: 'a2', icon: null, label: 'Delete', collapsed: true, handler: jest.fn() }), | ||
| ]; | ||
| renderComponent(actions); | ||
| expect(screen.getByRole('button', { name: optionsLabel$() })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('renders the options button when an action has no icon (forces it to menu)', () => { | ||
| const actions = [makeAction({ id: 'a1', icon: null, label: 'Delete', collapsed: false })]; | ||
| renderComponent(actions); | ||
| expect(screen.getByRole('button', { name: optionsLabel$() })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('uses the provided optionsLabel prop for the menu button', () => { | ||
| const actions = [makeAction({ id: 'a1', icon: null, label: 'Delete', collapsed: true })]; | ||
| renderComponent(actions, 'Custom options label'); | ||
| expect(screen.getByRole('button', { name: 'Custom options label' })).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('disabled state', () => { | ||
| test('renders the icon button as disabled when action.disabled is true', () => { | ||
| const actions = [ | ||
| makeAction({ id: 'a1', label: 'Edit', icon: 'edit', collapsed: false, disabled: true }), | ||
| ]; | ||
| renderComponent(actions); | ||
| expect(screen.getByRole('button', { name: 'Edit' })).toBeDisabled(); | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| <template> | ||
|
|
||
| <div class="collapsible-toolbar"> | ||
| <div class="icon-actions-wrapper"> | ||
| <KIconButton | ||
| v-for="action in visibleIconActions" | ||
| :key="action.id" | ||
| :icon="action.icon" | ||
| :tooltip="action.label" | ||
| :ariaLabel="action.label" | ||
| :disabled="action.disabled" | ||
| :color="action.disabled ? $themeTokens.textDisabled : $themePalette.grey.v_800" | ||
| @click="action.handler" | ||
| /> | ||
| </div> | ||
|
|
||
| <KIconButton | ||
| v-if="collapsedMenuActions.length > 0" | ||
| icon="optionsVertical" | ||
| :color="$themePalette.grey.v_800" | ||
| :tooltip="optionsLabel || optionsLabel$()" | ||
| :ariaLabel="optionsLabel || optionsLabel$()" | ||
| > | ||
| <template #menu> | ||
| <KDropdownMenu | ||
| :options="dropdownOptions" | ||
| @select="handleSelect" | ||
| /> | ||
| </template> | ||
| </KIconButton> | ||
| </div> | ||
|
|
||
| </template> | ||
|
|
||
|
|
||
| <script> | ||
|
|
||
| import { computed } from 'vue'; | ||
| import { commonStrings } from 'shared/strings/commonStrings'; | ||
|
|
||
| export default { | ||
| name: 'CollapsibleToolbar', | ||
|
|
||
| setup(props) { | ||
| const { optionsLabel$ } = commonStrings; | ||
| /** Actions with an icon that are not explicitly collapsed */ | ||
| const visibleIconActions = computed(() => { | ||
| return props.actions.filter(a => !a.collapsed && Boolean(a.icon)); | ||
| }); | ||
|
|
||
| /** Actions without an icon MUST go to the menu, along with explicitly collapsed ones */ | ||
| const collapsedMenuActions = computed(() => { | ||
| return props.actions.filter(a => a.collapsed || !a.icon); | ||
| }); | ||
|
|
||
| const dropdownOptions = computed(() => { | ||
| return collapsedMenuActions.value.map(action => ({ | ||
| label: action.label, | ||
| value: action.id, | ||
| disabled: action.disabled, | ||
| })); | ||
| }); | ||
|
|
||
| function handleSelect(option) { | ||
| const action = collapsedMenuActions.value.find(a => a.id === option.value); | ||
| if (action && action.handler) { | ||
| action.handler(); | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| visibleIconActions, | ||
| collapsedMenuActions, | ||
| dropdownOptions, | ||
| handleSelect, | ||
| optionsLabel$, | ||
| }; | ||
| }, | ||
|
|
||
| props: { | ||
| /** | ||
| * Array of actions: | ||
| * { | ||
| * id: string, | ||
| * icon: string | null, | ||
| * label: string, | ||
| * handler: Function, | ||
| * collapsed?: boolean, | ||
| * disabled?: boolean | ||
| * } | ||
| */ | ||
| actions: { | ||
| type: Array, | ||
| required: true, | ||
| validator(actions) { | ||
| return actions.every( | ||
| a => | ||
| typeof a.id === 'string' && | ||
| typeof a.label === 'string' && | ||
| typeof a.handler === 'function', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: The prop validator enforces the action interface contract at the component boundary — any caller that omits |
||
| ); | ||
| }, | ||
| }, | ||
| /** Tooltip text for the generic options menu icon */ | ||
| optionsLabel: { | ||
| type: String, | ||
| default: null, | ||
| }, | ||
|
Comment on lines
+105
to
+108
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's default it to null, and let's use an |
||
| }, | ||
| }; | ||
|
|
||
| </script> | ||
|
|
||
|
|
||
| <style lang="scss" scoped> | ||
|
|
||
| .collapsible-toolbar { | ||
| display: flex; | ||
| gap: 4px; | ||
| align-items: center; | ||
| justify-content: flex-end; | ||
| } | ||
|
|
||
| .icon-actions-wrapper { | ||
| display: flex; | ||
| gap: 4px; | ||
| align-items: center; | ||
| } | ||
|
|
||
| </style> | ||
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.
We don't really need an ID for the action (at least not yet). If it is because of handleSelect, there is a better way: We can just pass the
handlerto thedropdownOptionsarray.Then, on the
handleSelectwe can just dooption.handler():). So there is no need to have anidand do other iteration in the ' handleSelect '.