Compare commits
8 Commits
test_hyper
...
open-relea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b66238c7c0 | ||
|
|
e4c5238f70 | ||
|
|
1bc759a1e7 | ||
|
|
5cc04f8a80 | ||
|
|
de4189b4a5 | ||
|
|
785b91d3c7 | ||
|
|
a63409eaa6 | ||
|
|
3c8e5b2501 |
8
.env
8
.env
@@ -1,4 +1,3 @@
|
|||||||
APP_ID='authoring'
|
|
||||||
NODE_ENV='production'
|
NODE_ENV='production'
|
||||||
ACCESS_TOKEN_COOKIE_NAME=''
|
ACCESS_TOKEN_COOKIE_NAME=''
|
||||||
BASE_URL=''
|
BASE_URL=''
|
||||||
@@ -35,15 +34,12 @@ ENABLE_UNIT_PAGE=false
|
|||||||
ENABLE_ASSETS_PAGE=false
|
ENABLE_ASSETS_PAGE=false
|
||||||
ENABLE_VIDEO_UPLOAD_PAGE_LINK_IN_CONTENT_DROPDOWN=false
|
ENABLE_VIDEO_UPLOAD_PAGE_LINK_IN_CONTENT_DROPDOWN=false
|
||||||
ENABLE_TAGGING_TAXONOMY_PAGES=true
|
ENABLE_TAGGING_TAXONOMY_PAGES=true
|
||||||
ENABLE_CERTIFICATE_PAGE=true
|
|
||||||
BBB_LEARN_MORE_URL=''
|
BBB_LEARN_MORE_URL=''
|
||||||
HOTJAR_APP_ID=''
|
HOTJAR_APP_ID=''
|
||||||
HOTJAR_VERSION=6
|
HOTJAR_VERSION=6
|
||||||
HOTJAR_DEBUG=false
|
HOTJAR_DEBUG=false
|
||||||
INVITE_STUDENTS_EMAIL_TO=''
|
INVITE_STUDENTS_EMAIL_TO=''
|
||||||
ENABLE_HOME_PAGE_COURSE_API_V2=true
|
AI_TRANSLATIONS_BASE_URL=''
|
||||||
|
ENABLE_HOME_PAGE_COURSE_API_V2=false
|
||||||
ENABLE_CHECKLIST_QUALITY=''
|
ENABLE_CHECKLIST_QUALITY=''
|
||||||
ENABLE_GRADING_METHOD_IN_PROBLEMS=false
|
ENABLE_GRADING_METHOD_IN_PROBLEMS=false
|
||||||
# "Multi-level" blocks are unsupported in libraries
|
|
||||||
# TODO: Missing support for ORA2
|
|
||||||
LIBRARY_UNSUPPORTED_BLOCKS="conditional,step-builder,problem-builder,openassessment"
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
APP_ID='authoring'
|
|
||||||
NODE_ENV='development'
|
NODE_ENV='development'
|
||||||
ACCESS_TOKEN_COOKIE_NAME='edx-jwt-cookie-header-payload'
|
ACCESS_TOKEN_COOKIE_NAME='edx-jwt-cookie-header-payload'
|
||||||
BASE_URL='http://localhost:2001'
|
BASE_URL='http://localhost:2001'
|
||||||
@@ -36,7 +35,6 @@ ENABLE_TEAM_TYPE_SETTING=false
|
|||||||
ENABLE_UNIT_PAGE=false
|
ENABLE_UNIT_PAGE=false
|
||||||
ENABLE_ASSETS_PAGE=false
|
ENABLE_ASSETS_PAGE=false
|
||||||
ENABLE_VIDEO_UPLOAD_PAGE_LINK_IN_CONTENT_DROPDOWN=true
|
ENABLE_VIDEO_UPLOAD_PAGE_LINK_IN_CONTENT_DROPDOWN=true
|
||||||
ENABLE_CERTIFICATE_PAGE=true
|
|
||||||
ENABLE_NEW_VIDEO_UPLOAD_PAGE=true
|
ENABLE_NEW_VIDEO_UPLOAD_PAGE=true
|
||||||
ENABLE_TAGGING_TAXONOMY_PAGES=true
|
ENABLE_TAGGING_TAXONOMY_PAGES=true
|
||||||
BBB_LEARN_MORE_URL=''
|
BBB_LEARN_MORE_URL=''
|
||||||
@@ -44,8 +42,7 @@ HOTJAR_APP_ID=''
|
|||||||
HOTJAR_VERSION=6
|
HOTJAR_VERSION=6
|
||||||
HOTJAR_DEBUG=true
|
HOTJAR_DEBUG=true
|
||||||
INVITE_STUDENTS_EMAIL_TO="someone@domain.com"
|
INVITE_STUDENTS_EMAIL_TO="someone@domain.com"
|
||||||
ENABLE_HOME_PAGE_COURSE_API_V2=true
|
AI_TRANSLATIONS_BASE_URL='http://localhost:18760'
|
||||||
|
ENABLE_HOME_PAGE_COURSE_API_V2=false
|
||||||
ENABLE_CHECKLIST_QUALITY=true
|
ENABLE_CHECKLIST_QUALITY=true
|
||||||
ENABLE_GRADING_METHOD_IN_PROBLEMS=false
|
ENABLE_GRADING_METHOD_IN_PROBLEMS=false
|
||||||
# "Multi-level" blocks are unsupported in libraries
|
|
||||||
LIBRARY_UNSUPPORTED_BLOCKS="conditional,step-builder,problem-builder"
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
APP_ID='authoring'
|
|
||||||
ACCESS_TOKEN_COOKIE_NAME='edx-jwt-cookie-header-payload'
|
ACCESS_TOKEN_COOKIE_NAME='edx-jwt-cookie-header-payload'
|
||||||
BASE_URL='http://localhost:2001'
|
BASE_URL='http://localhost:2001'
|
||||||
CREDENTIALS_BASE_URL='http://localhost:18150'
|
CREDENTIALS_BASE_URL='http://localhost:18150'
|
||||||
@@ -32,13 +31,9 @@ ENABLE_TEAM_TYPE_SETTING=false
|
|||||||
ENABLE_UNIT_PAGE=true
|
ENABLE_UNIT_PAGE=true
|
||||||
ENABLE_ASSETS_PAGE=false
|
ENABLE_ASSETS_PAGE=false
|
||||||
ENABLE_VIDEO_UPLOAD_PAGE_LINK_IN_CONTENT_DROPDOWN=true
|
ENABLE_VIDEO_UPLOAD_PAGE_LINK_IN_CONTENT_DROPDOWN=true
|
||||||
ENABLE_CERTIFICATE_PAGE=true
|
|
||||||
ENABLE_TAGGING_TAXONOMY_PAGES=true
|
ENABLE_TAGGING_TAXONOMY_PAGES=true
|
||||||
BBB_LEARN_MORE_URL=''
|
BBB_LEARN_MORE_URL=''
|
||||||
INVITE_STUDENTS_EMAIL_TO="someone@domain.com"
|
INVITE_STUDENTS_EMAIL_TO="someone@domain.com"
|
||||||
ENABLE_HOME_PAGE_COURSE_API_V2=true
|
ENABLE_HOME_PAGE_COURSE_API_V2=true
|
||||||
ENABLE_CHECKLIST_QUALITY=true
|
ENABLE_CHECKLIST_QUALITY=true
|
||||||
ENABLE_GRADING_METHOD_IN_PROBLEMS=false
|
ENABLE_GRADING_METHOD_IN_PROBLEMS=false
|
||||||
# "Multi-level" blocks are unsupported in libraries
|
|
||||||
# TODO: Missing support for ORA2
|
|
||||||
LIBRARY_UNSUPPORTED_BLOCKS="conditional,step-builder,problem-builder,openassessment"
|
|
||||||
|
|||||||
@@ -11,9 +11,8 @@ module.exports = createConfig(
|
|||||||
}],
|
}],
|
||||||
'template-curly-spacing': 'off',
|
'template-curly-spacing': 'off',
|
||||||
'react-hooks/exhaustive-deps': 'off',
|
'react-hooks/exhaustive-deps': 'off',
|
||||||
|
indent: ['error', 2],
|
||||||
'no-restricted-exports': 'off',
|
'no-restricted-exports': 'off',
|
||||||
// There is no reason to disallow this syntax anymore; we don't use regenerator-runtime in new browsers
|
|
||||||
'no-restricted-syntax': 'off',
|
|
||||||
},
|
},
|
||||||
settings: {
|
settings: {
|
||||||
// Import URLs should be resolved using aliases
|
// Import URLs should be resolved using aliases
|
||||||
|
|||||||
7
.github/dependabot.yml
vendored
7
.github/dependabot.yml
vendored
@@ -1,7 +0,0 @@
|
|||||||
version: 2
|
|
||||||
updates:
|
|
||||||
# Adding new check for github-actions
|
|
||||||
- package-ecosystem: "github-actions"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "weekly"
|
|
||||||
23
.github/workflows/validate.yml
vendored
23
.github/workflows/validate.yml
vendored
@@ -9,27 +9,14 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
tests:
|
tests:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-node@v4
|
- name: Setup Nodejs Env
|
||||||
|
run: echo "NODE_VER=`cat .nvmrc`" >> $GITHUB_ENV
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version-file: '.nvmrc'
|
node-version: ${{ env.NODE_VER }}
|
||||||
- run: make validate.ci
|
- run: make validate.ci
|
||||||
- name: Archive code coverage results
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: code-coverage-report
|
|
||||||
path: coverage/*.*
|
|
||||||
coverage:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: tests
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Download code coverage results
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: code-coverage-report
|
|
||||||
- name: Upload coverage
|
- name: Upload coverage
|
||||||
uses: codecov/codecov-action@v4
|
uses: codecov/codecov-action@v4
|
||||||
with:
|
with:
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,7 +1,6 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
.eslintcache
|
.eslintcache
|
||||||
.idea
|
.idea
|
||||||
.run
|
|
||||||
node_modules
|
node_modules
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
coverage
|
coverage
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
"scss/at-rule-no-unknown": true,
|
"scss/at-rule-no-unknown": true,
|
||||||
"scss/at-import-partial-extension": null,
|
"scss/at-import-partial-extension": null,
|
||||||
"scss/comment-no-empty": null,
|
"scss/comment-no-empty": null,
|
||||||
"import-notation": "string",
|
|
||||||
"property-no-unknown": [true, {
|
"property-no-unknown": [true, {
|
||||||
"ignoreProperties": ["xs", "sm", "md", "lg", "xl", "xxl"]
|
"ignoreProperties": ["xs", "sm", "md", "lg", "xl", "xxl"]
|
||||||
}],
|
}],
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
# The following users are the maintainers of all frontend-app-authoring files
|
# The following users are the maintainers of all frontend-app-course-authoring files
|
||||||
* @openedx/2u-tnl
|
* @openedx/2u-tnl
|
||||||
|
|||||||
5
Makefile
5
Makefile
@@ -35,12 +35,13 @@ pull_translations:
|
|||||||
cd src/i18n/messages \
|
cd src/i18n/messages \
|
||||||
&& atlas pull $(ATLAS_OPTIONS) \
|
&& atlas pull $(ATLAS_OPTIONS) \
|
||||||
translations/frontend-component-ai-translations/src/i18n/messages:frontend-component-ai-translations \
|
translations/frontend-component-ai-translations/src/i18n/messages:frontend-component-ai-translations \
|
||||||
|
translations/frontend-lib-content-components/src/i18n/messages:frontend-lib-content-components \
|
||||||
translations/frontend-platform/src/i18n/messages:frontend-platform \
|
translations/frontend-platform/src/i18n/messages:frontend-platform \
|
||||||
translations/paragon/src/i18n/messages:paragon \
|
translations/paragon/src/i18n/messages:paragon \
|
||||||
translations/frontend-component-footer/src/i18n/messages:frontend-component-footer \
|
translations/frontend-component-footer/src/i18n/messages:frontend-component-footer \
|
||||||
translations/frontend-app-course-authoring/src/i18n/messages:frontend-app-course-authoring
|
translations/frontend-app-course-authoring/src/i18n/messages:frontend-app-course-authoring
|
||||||
|
|
||||||
$(intl_imports) frontend-component-ai-translations frontend-platform paragon frontend-component-footer frontend-app-course-authoring
|
$(intl_imports) frontend-component-ai-translations frontend-lib-content-components frontend-platform paragon frontend-component-footer frontend-app-course-authoring
|
||||||
|
|
||||||
# This target is used by Travis.
|
# This target is used by Travis.
|
||||||
validate-no-uncommitted-package-lock-changes:
|
validate-no-uncommitted-package-lock-changes:
|
||||||
@@ -53,7 +54,7 @@ validate:
|
|||||||
npm run i18n_extract
|
npm run i18n_extract
|
||||||
npm run lint -- --max-warnings 0
|
npm run lint -- --max-warnings 0
|
||||||
npm run types
|
npm run types
|
||||||
npm run test:ci
|
npm run test
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
.PHONY: validate.ci
|
.PHONY: validate.ci
|
||||||
|
|||||||
122
README.rst
122
README.rst
@@ -1,5 +1,5 @@
|
|||||||
frontend-app-authoring
|
frontend-app-course-authoring
|
||||||
######################
|
#############################
|
||||||
|
|
||||||
|license-badge| |status-badge| |codecov-badge|
|
|license-badge| |status-badge| |codecov-badge|
|
||||||
|
|
||||||
@@ -7,9 +7,9 @@ frontend-app-authoring
|
|||||||
Purpose
|
Purpose
|
||||||
*******
|
*******
|
||||||
|
|
||||||
This implements most of the frontend for **Open edX Studio**, allowing authors to create and edit courses, libraries, and their learning components.
|
This is the Course Authoring micro-frontend, currently under development by `2U <https://2u.com>`_.
|
||||||
|
|
||||||
A few parts of Studio still default to the `"legacy" pages defined in edx-platform <https://github.com/openedx/edx-platform/tree/master/cms>`_, but those are rapidly being deprecated and replaced with the React- and Paragon-based pages defined here.
|
Its purpose is to provide both a framework and UI for new or replacement React-based authoring features outside ``edx-platform``. You can find the current set described below.
|
||||||
|
|
||||||
|
|
||||||
Getting Started
|
Getting Started
|
||||||
@@ -18,87 +18,51 @@ Getting Started
|
|||||||
Prerequisites
|
Prerequisites
|
||||||
=============
|
=============
|
||||||
|
|
||||||
`Tutor`_ is currently recommended as a development environment for the Authoring
|
The `devstack`_ is currently recommended as a development environment for your
|
||||||
MFE. Most likely, it already has this MFE configured; however, you'll need to
|
new MFE. If you start it with ``make dev.up.lms`` that should give you
|
||||||
make some changes in order to run it in development mode. You can refer
|
everything you need as a companion to this frontend.
|
||||||
to the `relevant tutor-mfe documentation`_ for details, or follow the quick
|
|
||||||
guide below.
|
Note that it is also possible to use `Tutor`_ to develop an MFE. You can refer
|
||||||
|
to the `relevant tutor-mfe documentation`_ to get started using it.
|
||||||
|
|
||||||
|
.. _Devstack: https://github.com/openedx/devstack
|
||||||
|
|
||||||
.. _Tutor: https://github.com/overhangio/tutor
|
.. _Tutor: https://github.com/overhangio/tutor
|
||||||
|
|
||||||
.. _relevant tutor-mfe documentation: https://github.com/overhangio/tutor-mfe#mfe-development
|
.. _relevant tutor-mfe documentation: https://github.com/overhangio/tutor-mfe#mfe-development
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
=============
|
||||||
|
|
||||||
Cloning and Setup
|
All features that integrate into the edx-platform CMS require that the ``COURSE_AUTHORING_MICROFRONTEND_URL`` Django setting is set in the CMS environment and points to this MFE's deployment URL. This should be done automatically if you are using devstack or tutor-mfe.
|
||||||
=================
|
|
||||||
|
|
||||||
1. Clone your new repo:
|
Cloning and Startup
|
||||||
|
===================
|
||||||
|
|
||||||
.. code-block:: bash
|
|
||||||
|
|
||||||
git clone https://github.com/openedx/frontend-app-authoring.git
|
1. Clone the repo:
|
||||||
|
|
||||||
2. Use the version of Node specified in the ``.nvmrc`` file.
|
``git clone https://github.com/openedx/frontend-app-course-authoring.git``
|
||||||
|
|
||||||
The current version of the micro-frontend build scripts supports node 20.
|
2. Use node v18.x.
|
||||||
Using other major versions of node *may* work, but this is unsupported. For
|
|
||||||
convenience, this repository includes an ``.nvmrc`` file to help in setting the
|
|
||||||
correct node version via `nvm <https://github.com/nvm-sh/nvm>`_.
|
|
||||||
|
|
||||||
3. Stop the Tutor devstack, if it's running: ``tutor dev stop``
|
The current version of the micro-frontend build scripts support node 18.
|
||||||
|
Using other major versions of node *may* work, but this is unsupported. For
|
||||||
|
convenience, this repository includes an .nvmrc file to help in setting the
|
||||||
|
correct node version via `nvm use`_.
|
||||||
|
|
||||||
4. Next, we need to tell Tutor that we're going to be running this repo in
|
3. Install npm dependencies:
|
||||||
development mode, and it should be excluded from the ``mfe`` container that
|
|
||||||
otherwise runs every MFE. Run this:
|
|
||||||
|
|
||||||
.. code-block:: bash
|
``cd frontend-app-course-authoring && npm install``
|
||||||
|
|
||||||
tutor mounts add /path/to/frontend-app-authoring
|
|
||||||
|
|
||||||
5. Start Tutor in development mode. This command will start the LMS and Studio,
|
4. Start the dev server:
|
||||||
and other required MFEs like ``authn`` and ``account``, but will not start
|
|
||||||
the Authoring MFE, which we're going to run on the host instead of in a
|
|
||||||
container managed by Tutor. Run:
|
|
||||||
|
|
||||||
.. code-block:: bash
|
``npm start``
|
||||||
|
|
||||||
tutor dev start lms cms mfe
|
|
||||||
|
|
||||||
Startup
|
The dev server is running at `http://localhost:2001 <http://localhost:2001>`_.
|
||||||
=======
|
or whatever port you setup.
|
||||||
|
|
||||||
1. Install npm dependencies:
|
|
||||||
|
|
||||||
.. code-block:: bash
|
|
||||||
|
|
||||||
cd frontend-app-authoring && npm ci
|
|
||||||
|
|
||||||
2. Start the dev server:
|
|
||||||
|
|
||||||
.. code-block:: bash
|
|
||||||
|
|
||||||
npm run dev
|
|
||||||
|
|
||||||
Then you can access the app at http://apps.local.openedx.io:2001/course-authoring/home
|
|
||||||
|
|
||||||
Troubleshooting
|
|
||||||
---------------
|
|
||||||
|
|
||||||
* If you see an "Invalid Host header" error, then you're probably using a different domain name for your devstack such as
|
|
||||||
``local.edly.io`` or ``local.overhang.io`` (not the new recommended default, ``local.openedx.io``). In that case, run
|
|
||||||
these commands to update your devstack's domain names:
|
|
||||||
|
|
||||||
.. code-block:: bash
|
|
||||||
|
|
||||||
tutor dev stop
|
|
||||||
tutor config save --set LMS_HOST=local.openedx.io --set CMS_HOST=studio.local.openedx.io
|
|
||||||
tutor dev launch -I --skip-build
|
|
||||||
tutor dev stop authoring # We will run this MFE on the host
|
|
||||||
|
|
||||||
* If tutor-mfe is not starting the authoring MFE in development mode (eg. `tutor dev start authoring` fails), it may be due to
|
|
||||||
using a tutor version that expects the MFE name to be frontend-app-course-authoring (the previous name of this repo). To fix
|
|
||||||
this, you can rename the cloned repo directory to frontend-app-course-authoring. More information can be found in
|
|
||||||
`this forum post <https://discuss.openedx.org/t/repo-rename-frontend-app-course-authoring-frontend-app-authoring/13930/2>`__.
|
|
||||||
|
|
||||||
|
|
||||||
Features
|
Features
|
||||||
@@ -181,6 +145,10 @@ Feature Description
|
|||||||
|
|
||||||
When a corresponding waffle flag is set, upon editing a block in Studio, the view is rendered by this MFE instead of by the XBlock's authoring view. The user remains in Studio.
|
When a corresponding waffle flag is set, upon editing a block in Studio, the view is rendered by this MFE instead of by the XBlock's authoring view. The user remains in Studio.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
The new editors themselves are currently implemented in a repository outside ``openedx``: `frontend-lib-content-components <https://github.com/edx/frontend-lib-content-components/>`_, a dependency of this MFE. This repository is slated to be moved to the ``openedx`` org, however.
|
||||||
|
|
||||||
Feature: New Proctoring Exams View
|
Feature: New Proctoring Exams View
|
||||||
==================================
|
==================================
|
||||||
|
|
||||||
@@ -296,26 +264,10 @@ In additional to the standard settings, the following local configuration items
|
|||||||
Tagging/Taxonomy functionality.
|
Tagging/Taxonomy functionality.
|
||||||
|
|
||||||
|
|
||||||
Feature: Libraries V2/Legacy Tabs
|
|
||||||
=================================
|
|
||||||
|
|
||||||
Configuration
|
|
||||||
-------------
|
|
||||||
|
|
||||||
In additional to the standard settings, the following local configurations can be set to switch between different library modes:
|
|
||||||
|
|
||||||
* ``MEILISEARCH_ENABLED``: Studio setting which is enabled when the `meilisearch plugin`_ is installed.
|
|
||||||
* ``edx-platform`` Waffle flags:
|
|
||||||
|
|
||||||
* ``contentstore.new_studio_mfe.disable_legacy_libraries``: this feature flag must be OFF to show legacy Libraries V1
|
|
||||||
* ``contentstore.new_studio_mfe.disable_new_libraries``: this feature flag must be OFF to show Content Libraries V2
|
|
||||||
|
|
||||||
.. _meilisearch plugin: https://github.com/open-craft/tutor-contrib-meilisearch
|
|
||||||
|
|
||||||
Developing
|
Developing
|
||||||
**********
|
**********
|
||||||
|
|
||||||
`Tutor <https://docs.tutor.edly.io/>`_ is the community-supported Open edX development environment. See the `tutor-mfe plugin README <https://github.com/overhangio/tutor-mfe?tab=readme-ov-file#mfe-development>`_ for more information.
|
`Devstack <https://edx.readthedocs.io/projects/edx-installing-configuring-and-running/en/latest/installation/index.html>`_. If you start Devstack with ``make dev.up.studio`` that should give you everything you need as a companion to this frontend.
|
||||||
|
|
||||||
|
|
||||||
If your devstack includes the default Demo course, you can visit the following URLs to see content:
|
If your devstack includes the default Demo course, you can visit the following URLs to see content:
|
||||||
@@ -344,8 +296,8 @@ The production build is created with ``npm run build``.
|
|||||||
:target: https://travis-ci.com/edx/frontend-app-course-authoring
|
:target: https://travis-ci.com/edx/frontend-app-course-authoring
|
||||||
.. |Codecov| image:: https://codecov.io/gh/edx/frontend-app-course-authoring/branch/master/graph/badge.svg
|
.. |Codecov| image:: https://codecov.io/gh/edx/frontend-app-course-authoring/branch/master/graph/badge.svg
|
||||||
:target: https://codecov.io/gh/edx/frontend-app-course-authoring
|
:target: https://codecov.io/gh/edx/frontend-app-course-authoring
|
||||||
.. |license| image:: https://img.shields.io/npm/l/@edx/frontend-app-authoring.svg
|
.. |license| image:: https://img.shields.io/npm/l/@edx/frontend-app-course-authoring.svg
|
||||||
:target: @edx/frontend-app-authoring
|
:target: @edx/frontend-app-course-authoring
|
||||||
|
|
||||||
Internationalization
|
Internationalization
|
||||||
====================
|
====================
|
||||||
|
|||||||
@@ -4,15 +4,14 @@
|
|||||||
apiVersion: backstage.io/v1alpha1
|
apiVersion: backstage.io/v1alpha1
|
||||||
kind: Component
|
kind: Component
|
||||||
metadata:
|
metadata:
|
||||||
name: 'frontend-app-authoring'
|
name: 'frontend-app-course-authoring'
|
||||||
description: "The frontend (MFE) for Open edX Authoring (aka Studio)"
|
description: "The frontend (MFE) for Open edX Course Authoring (aka Studio)"
|
||||||
links:
|
links:
|
||||||
- url: "https://github.com/openedx/frontend-app-authoring"
|
- url: "https://github.com/openedx/frontend-app-course-authoring"
|
||||||
title: "Frontend app authoring"
|
title: "Frontend app course authoring"
|
||||||
icon: "Web"
|
icon: "Web"
|
||||||
annotations:
|
annotations:
|
||||||
openedx.org/arch-interest-groups: ""
|
openedx.org/arch-interest-groups: ""
|
||||||
openedx.org/release: "master"
|
|
||||||
spec:
|
spec:
|
||||||
owner: group:2u-tnl
|
owner: group:2u-tnl
|
||||||
type: 'website'
|
type: 'website'
|
||||||
|
|||||||
11
openedx.yaml
Normal file
11
openedx.yaml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# This file describes this Open edX repo, as described in OEP-2:
|
||||||
|
# http://open-edx-proposals.readthedocs.io/en/latest/oeps/oep-0002.html#specification
|
||||||
|
|
||||||
|
nick: cath
|
||||||
|
oeps: {}
|
||||||
|
owner: edx/platform-core-tnl
|
||||||
|
openedx-release:
|
||||||
|
# The openedx-release key is described in OEP-10:
|
||||||
|
# https://open-edx-proposals.readthedocs.io/en/latest/oep-0010-proc-openedx-releases.html
|
||||||
|
# The FAQ might also be helpful: https://openedx.atlassian.net/wiki/spaces/COMM/pages/1331268879/Open+edX+Release+FAQ
|
||||||
|
ref: master
|
||||||
26380
package-lock.json
generated
26380
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
107
package.json
107
package.json
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "@edx/frontend-app-authoring",
|
"name": "@edx/frontend-app-course-authoring",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Frontend application template",
|
"description": "Frontend application template",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/openedx/frontend-app-authoring.git"
|
"url": "git+https://github.com/openedx/frontend-app-course-authoring.git"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"extends @edx/browserslist-config"
|
"extends @edx/browserslist-config"
|
||||||
@@ -13,42 +13,47 @@
|
|||||||
"build": "fedx-scripts webpack",
|
"build": "fedx-scripts webpack",
|
||||||
"i18n_extract": "fedx-scripts formatjs extract",
|
"i18n_extract": "fedx-scripts formatjs extract",
|
||||||
"stylelint": "stylelint \"plugins/**/*.scss\" \"src/**/*.scss\" \"scss/**/*.scss\" --config .stylelintrc.json",
|
"stylelint": "stylelint \"plugins/**/*.scss\" \"src/**/*.scss\" \"scss/**/*.scss\" --config .stylelintrc.json",
|
||||||
"lint": "npm run stylelint && fedx-scripts eslint --ext .js --ext .jsx --ext .ts --ext .tsx .",
|
"lint": "npm run stylelint && fedx-scripts eslint --ext .js --ext .jsx .",
|
||||||
"lint:fix": "npm run stylelint -- --fix && fedx-scripts eslint --fix --ext .js --ext .jsx --ext .ts --ext .tsx .",
|
"lint:fix": "npm run stylelint && fedx-scripts eslint --ext .js --ext .jsx . --fix",
|
||||||
"snapshot": "TZ=UTC fedx-scripts jest --updateSnapshot",
|
"snapshot": "TZ=UTC fedx-scripts jest --updateSnapshot",
|
||||||
"start": "fedx-scripts webpack-dev-server --progress",
|
"start": "fedx-scripts webpack-dev-server --progress",
|
||||||
"start:with-theme": "paragon install-theme && npm start && npm install",
|
"start:with-theme": "paragon install-theme && npm start && npm install",
|
||||||
"dev": "PUBLIC_PATH=/authoring/ MFE_CONFIG_API_URL='http://localhost:8000/api/mfe_config/v1' fedx-scripts webpack-dev-server --progress --host apps.local.openedx.io",
|
|
||||||
"test": "TZ=UTC fedx-scripts jest --coverage --passWithNoTests",
|
"test": "TZ=UTC fedx-scripts jest --coverage --passWithNoTests",
|
||||||
"test:ci": "TZ=UTC fedx-scripts jest --silent --coverage --passWithNoTests",
|
|
||||||
"types": "tsc --noEmit"
|
"types": "tsc --noEmit"
|
||||||
},
|
},
|
||||||
|
"husky": {
|
||||||
|
"hooks": {
|
||||||
|
"pre-commit": "npm run lint"
|
||||||
|
}
|
||||||
|
},
|
||||||
"author": "edX",
|
"author": "edX",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"homepage": "https://github.com/openedx/frontend-app-authoring#readme",
|
"homepage": "https://github.com/openedx/frontend-app-course-authoring#readme",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/openedx/frontend-app-authoring/issues"
|
"url": "https://github.com/openedx/frontend-app-course-authoring/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@codemirror/lang-html": "^6.0.0",
|
|
||||||
"@codemirror/lang-xml": "^6.0.0",
|
|
||||||
"@codemirror/lint": "^6.2.1",
|
|
||||||
"@codemirror/state": "^6.0.0",
|
|
||||||
"@codemirror/view": "^6.0.0",
|
|
||||||
"@dnd-kit/core": "^6.1.0",
|
"@dnd-kit/core": "^6.1.0",
|
||||||
"@dnd-kit/modifiers": "^7.0.0",
|
"@dnd-kit/modifiers": "^7.0.0",
|
||||||
"@dnd-kit/sortable": "^8.0.0",
|
"@dnd-kit/sortable": "^8.0.0",
|
||||||
"@dnd-kit/utilities": "^3.2.2",
|
"@dnd-kit/utilities": "^3.2.2",
|
||||||
"@edx/brand": "npm:@openedx/brand-openedx@^1.2.3",
|
"@edx/brand": "npm:@openedx/brand-openedx@^1.2.2",
|
||||||
"@edx/browserslist-config": "1.2.0",
|
"@edx/frontend-component-ai-translations": "^2.0.0",
|
||||||
"@edx/frontend-component-footer": "^14.3.0",
|
"@edx/frontend-component-footer": "^13.0.2",
|
||||||
"@edx/frontend-component-header": "^6.2.0",
|
"@edx/frontend-component-header": "^5.1.0",
|
||||||
"@edx/frontend-enterprise-hotjar": "^7.2.0",
|
"@edx/frontend-enterprise-hotjar": "^2.0.0",
|
||||||
"@edx/frontend-platform": "^8.3.1",
|
"@edx/frontend-lib-content-components": "^2.1.11",
|
||||||
|
"@edx/frontend-platform": "7.0.1",
|
||||||
"@edx/openedx-atlas": "^0.6.0",
|
"@edx/openedx-atlas": "^0.6.0",
|
||||||
|
"@fortawesome/fontawesome-svg-core": "1.2.36",
|
||||||
|
"@fortawesome/free-brands-svg-icons": "5.15.4",
|
||||||
|
"@fortawesome/free-regular-svg-icons": "5.15.4",
|
||||||
|
"@fortawesome/free-solid-svg-icons": "5.15.4",
|
||||||
|
"@fortawesome/react-fontawesome": "0.2.0",
|
||||||
|
"@meilisearch/instant-meilisearch": "^0.17.0",
|
||||||
"@openedx-plugins/course-app-calculator": "file:plugins/course-apps/calculator",
|
"@openedx-plugins/course-app-calculator": "file:plugins/course-apps/calculator",
|
||||||
"@openedx-plugins/course-app-edxnotes": "file:plugins/course-apps/edxnotes",
|
"@openedx-plugins/course-app-edxnotes": "file:plugins/course-apps/edxnotes",
|
||||||
"@openedx-plugins/course-app-learning_assistant": "file:plugins/course-apps/learning_assistant",
|
"@openedx-plugins/course-app-learning_assistant": "file:plugins/course-apps/learning_assistant",
|
||||||
@@ -59,66 +64,62 @@
|
|||||||
"@openedx-plugins/course-app-teams": "file:plugins/course-apps/teams",
|
"@openedx-plugins/course-app-teams": "file:plugins/course-apps/teams",
|
||||||
"@openedx-plugins/course-app-wiki": "file:plugins/course-apps/wiki",
|
"@openedx-plugins/course-app-wiki": "file:plugins/course-apps/wiki",
|
||||||
"@openedx-plugins/course-app-xpert_unit_summary": "file:plugins/course-apps/xpert_unit_summary",
|
"@openedx-plugins/course-app-xpert_unit_summary": "file:plugins/course-apps/xpert_unit_summary",
|
||||||
"@openedx/frontend-build": "^14.3.3",
|
"@openedx/frontend-plugin-framework": "^1.1.0",
|
||||||
"@openedx/frontend-plugin-framework": "^1.6.0",
|
"@openedx/paragon": "^22.2.1",
|
||||||
"@openedx/frontend-slot-footer": "^1.2.0",
|
|
||||||
"@openedx/paragon": "^22.16.0",
|
|
||||||
"@redux-devtools/extension": "^3.3.0",
|
|
||||||
"@reduxjs/toolkit": "1.9.7",
|
"@reduxjs/toolkit": "1.9.7",
|
||||||
"@tanstack/react-query": "4.36.1",
|
"@tanstack/react-query": "4.36.1",
|
||||||
"@tinymce/tinymce-react": "^3.14.0",
|
"classnames": "2.2.6",
|
||||||
"classnames": "2.5.1",
|
"core-js": "3.8.1",
|
||||||
"codemirror": "^6.0.0",
|
|
||||||
"email-validator": "2.0.4",
|
"email-validator": "2.0.4",
|
||||||
"fast-xml-parser": "^4.0.10",
|
|
||||||
"file-saver": "^2.0.5",
|
"file-saver": "^2.0.5",
|
||||||
"formik": "2.4.6",
|
"formik": "2.2.6",
|
||||||
"frontend-components-tinymce-advanced-plugins": "^1.0.3",
|
|
||||||
"jszip": "^3.10.1",
|
"jszip": "^3.10.1",
|
||||||
"lodash": "4.17.21",
|
"lodash": "4.17.21",
|
||||||
"meilisearch": "^0.41.0",
|
"meilisearch": "^0.38.0",
|
||||||
"moment": "2.30.1",
|
"moment": "2.29.4",
|
||||||
"moment-shortformat": "^2.1.0",
|
|
||||||
"npm": "^10.8.1",
|
|
||||||
"prop-types": "^15.8.1",
|
"prop-types": "^15.8.1",
|
||||||
"react": "^18.3.1",
|
"react": "17.0.2",
|
||||||
"react-datepicker": "^4.13.0",
|
"react-datepicker": "^4.13.0",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "17.0.2",
|
||||||
"react-error-boundary": "^4.0.13",
|
"react-error-boundary": "^4.0.13",
|
||||||
"react-helmet": "^6.1.0",
|
"react-helmet": "^6.1.0",
|
||||||
"react-onclickoutside": "^6.13.0",
|
|
||||||
"react-redux": "7.2.9",
|
"react-redux": "7.2.9",
|
||||||
"react-responsive": "9.0.2",
|
"react-responsive": "9.0.2",
|
||||||
"react-router": "6.27.0",
|
"react-router": "6.16.0",
|
||||||
"react-router-dom": "6.27.0",
|
"react-router-dom": "6.16.0",
|
||||||
"react-select": "5.8.0",
|
"react-select": "5.8.0",
|
||||||
"react-textarea-autosize": "^8.5.3",
|
"react-textarea-autosize": "^8.4.1",
|
||||||
"react-transition-group": "4.4.5",
|
"react-transition-group": "4.4.5",
|
||||||
"redux": "4.0.5",
|
"redux": "4.0.5",
|
||||||
"redux-logger": "^3.0.6",
|
"regenerator-runtime": "0.13.7",
|
||||||
"redux-thunk": "^2.4.1",
|
|
||||||
"reselect": "^4.1.5",
|
|
||||||
"start": "^5.1.0",
|
|
||||||
"tinymce": "^5.10.4",
|
|
||||||
"universal-cookie": "^4.0.4",
|
"universal-cookie": "^4.0.4",
|
||||||
"uuid": "^3.4.0",
|
"uuid": "^3.4.0",
|
||||||
"xmlchecker": "^0.1.0",
|
|
||||||
"yup": "0.31.1"
|
"yup": "0.31.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@edx/react-unit-test-utils": "^4.0.0",
|
"@edx/browserslist-config": "1.2.0",
|
||||||
"@edx/stylelint-config-edx": "2.3.3",
|
"@edx/react-unit-test-utils": "^2.0.0",
|
||||||
|
"@edx/reactifex": "^1.0.3",
|
||||||
|
"@edx/stylelint-config-edx": "2.3.0",
|
||||||
"@edx/typescript-config": "^1.0.1",
|
"@edx/typescript-config": "^1.0.1",
|
||||||
"@testing-library/jest-dom": "^6.6.3",
|
"@openedx/frontend-build": "13.1.0",
|
||||||
"@testing-library/react": "^16.2.0",
|
"@testing-library/jest-dom": "5.17.0",
|
||||||
|
"@testing-library/react": "12.1.5",
|
||||||
|
"@testing-library/react-hooks": "^8.0.1",
|
||||||
"@testing-library/user-event": "^13.2.1",
|
"@testing-library/user-event": "^13.2.1",
|
||||||
"@types/lodash": "^4.17.7",
|
"axios": "^0.28.0",
|
||||||
"axios-mock-adapter": "1.22.0",
|
"axios-mock-adapter": "1.22.0",
|
||||||
"eslint-import-resolver-webpack": "^0.13.8",
|
"eslint-import-resolver-webpack": "^0.13.8",
|
||||||
"fetch-mock-jest": "^1.5.1",
|
"fetch-mock-jest": "^1.5.1",
|
||||||
|
"glob": "7.2.3",
|
||||||
|
"husky": "7.0.4",
|
||||||
"jest-canvas-mock": "^2.5.2",
|
"jest-canvas-mock": "^2.5.2",
|
||||||
"jest-expect-message": "^1.1.3",
|
"jest-expect-message": "^1.1.3",
|
||||||
"react-test-renderer": "^18.3.1",
|
"react-test-renderer": "17.0.2",
|
||||||
"redux-mock-store": "^1.5.4"
|
"reactifex": "1.1.1",
|
||||||
|
"ts-loader": "^9.5.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"decode-uri-component": ">=0.2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,14 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Calculator configuration for courses using it",
|
"description": "Calculator configuration for courses using it",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@edx/frontend-app-authoring": "*",
|
"@edx/frontend-app-course-authoring": "*",
|
||||||
"@edx/frontend-platform": "*",
|
"@edx/frontend-platform": "*",
|
||||||
"@openedx/paragon": "*",
|
"@openedx/paragon": "*",
|
||||||
"prop-types": "*",
|
"prop-types": "*",
|
||||||
"react": "*"
|
"react": "*"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"@edx/frontend-app-authoring": {
|
"@edx/frontend-app-course-authoring": {
|
||||||
"optional": true
|
"optional": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,14 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "edxnotes configuration for courses using it",
|
"description": "edxnotes configuration for courses using it",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@edx/frontend-app-authoring": "*",
|
"@edx/frontend-app-course-authoring": "*",
|
||||||
"@edx/frontend-platform": "*",
|
"@edx/frontend-platform": "*",
|
||||||
"@openedx/paragon": "*",
|
"@openedx/paragon": "*",
|
||||||
"prop-types": "*",
|
"prop-types": "*",
|
||||||
"react": "*"
|
"react": "*"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"@edx/frontend-app-authoring": {
|
"@edx/frontend-app-course-authoring": {
|
||||||
"optional": true
|
"optional": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Learning Assistant configuration for courses using it",
|
"description": "Learning Assistant configuration for courses using it",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@edx/frontend-app-authoring": "*",
|
"@edx/frontend-app-course-authoring": "*",
|
||||||
"@edx/frontend-platform": "*",
|
"@edx/frontend-platform": "*",
|
||||||
"@openedx/paragon": "*",
|
"@openedx/paragon": "*",
|
||||||
"prop-types": "*",
|
"prop-types": "*",
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
"yup": "*"
|
"yup": "*"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"@edx/frontend-app-authoring": {
|
"@edx/frontend-app-course-authoring": {
|
||||||
"optional": true
|
"optional": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import { useDispatch, useSelector } from 'react-redux';
|
|||||||
import { camelCase } from 'lodash';
|
import { camelCase } from 'lodash';
|
||||||
import { Icon } from '@openedx/paragon';
|
import { Icon } from '@openedx/paragon';
|
||||||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||||
|
import { SelectableBox } from '@edx/frontend-lib-content-components';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import SelectableBox from 'CourseAuthoring/editors/sharedComponents/SelectableBox';
|
|
||||||
import AppSettingsModal from 'CourseAuthoring/pages-and-resources/app-settings-modal/AppSettingsModal';
|
import AppSettingsModal from 'CourseAuthoring/pages-and-resources/app-settings-modal/AppSettingsModal';
|
||||||
import { useModel } from 'CourseAuthoring/generic/model-store';
|
import { useModel } from 'CourseAuthoring/generic/model-store';
|
||||||
import Loading from 'CourseAuthoring/generic/Loading';
|
import Loading from 'CourseAuthoring/generic/Loading';
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable import/prefer-default-export */
|
||||||
import { ensureConfig, getConfig } from '@edx/frontend-platform';
|
import { ensureConfig, getConfig } from '@edx/frontend-platform';
|
||||||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
||||||
import { bbbPlanTypes } from '../constants';
|
import { bbbPlanTypes } from '../constants';
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Live course configuration for courses using it",
|
"description": "Live course configuration for courses using it",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@edx/frontend-app-authoring": "*",
|
"@edx/frontend-app-course-authoring": "*",
|
||||||
|
"@edx/frontend-lib-content-components": "*",
|
||||||
"@edx/frontend-platform": "*",
|
"@edx/frontend-platform": "*",
|
||||||
"@openedx/paragon": "*",
|
"@openedx/paragon": "*",
|
||||||
"@reduxjs/toolkit": "*",
|
"@reduxjs/toolkit": "*",
|
||||||
@@ -15,7 +16,7 @@
|
|||||||
"yup": "*"
|
"yup": "*"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"@edx/frontend-app-authoring": {
|
"@edx/frontend-app-course-authoring": {
|
||||||
"optional": true
|
"optional": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,176 +1,69 @@
|
|||||||
import { useEffect, useState, useRef } from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import * as Yup from 'yup';
|
||||||
|
|
||||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||||
import { useDispatch, useSelector } from 'react-redux';
|
|
||||||
|
|
||||||
import {
|
import { Hyperlink } from '@openedx/paragon';
|
||||||
ActionRow, Alert, Badge, Form, Hyperlink, ModalDialog, StatefulButton,
|
import { useModel } from 'CourseAuthoring/generic/model-store';
|
||||||
} from '@openedx/paragon';
|
|
||||||
import { Info } from '@openedx/paragon/icons';
|
|
||||||
import { updateModel, useModel } from 'CourseAuthoring/generic/model-store';
|
|
||||||
|
|
||||||
import { RequestStatus } from 'CourseAuthoring/data/constants';
|
|
||||||
import FormSwitchGroup from 'CourseAuthoring/generic/FormSwitchGroup';
|
import FormSwitchGroup from 'CourseAuthoring/generic/FormSwitchGroup';
|
||||||
import Loading from 'CourseAuthoring/generic/Loading';
|
import { useAppSetting } from 'CourseAuthoring/utils';
|
||||||
import PermissionDeniedAlert from 'CourseAuthoring/generic/PermissionDeniedAlert';
|
import AppSettingsModal from 'CourseAuthoring/pages-and-resources/app-settings-modal/AppSettingsModal';
|
||||||
import ConnectionErrorAlert from 'CourseAuthoring/generic/ConnectionErrorAlert';
|
|
||||||
import { useAppSetting, useIsMobile } from 'CourseAuthoring/utils';
|
|
||||||
import { getLoadingStatus, getSavingStatus } from 'CourseAuthoring/pages-and-resources/data/selectors';
|
|
||||||
import { updateSavingStatus } from 'CourseAuthoring/pages-and-resources/data/slice';
|
|
||||||
|
|
||||||
import messages from './messages';
|
import messages from './messages';
|
||||||
|
|
||||||
const ORASettings = ({ onClose }) => {
|
const ORASettings = ({ intl, onClose }) => {
|
||||||
const dispatch = useDispatch();
|
|
||||||
const { formatMessage } = useIntl();
|
|
||||||
const alertRef = useRef(null);
|
|
||||||
const updateSettingsRequestStatus = useSelector(getSavingStatus);
|
|
||||||
const loadingStatus = useSelector(getLoadingStatus);
|
|
||||||
const isMobile = useIsMobile();
|
|
||||||
const modalVariant = isMobile ? 'dark' : 'default';
|
|
||||||
const appId = 'ora_settings';
|
const appId = 'ora_settings';
|
||||||
const appInfo = useModel('courseApps', appId);
|
const appInfo = useModel('courseApps', appId);
|
||||||
|
|
||||||
const [enableFlexiblePeerGrade, saveSetting] = useAppSetting(
|
const [enableFlexiblePeerGrade, saveSetting] = useAppSetting(
|
||||||
'forceOnFlexiblePeerOpenassessments',
|
'forceOnFlexiblePeerOpenassessments',
|
||||||
);
|
);
|
||||||
const initialFormValues = { enableFlexiblePeerGrade };
|
|
||||||
|
|
||||||
const [formValues, setFormValues] = useState(initialFormValues);
|
|
||||||
const [saveError, setSaveError] = useState(false);
|
|
||||||
|
|
||||||
const submitButtonState = updateSettingsRequestStatus === RequestStatus.IN_PROGRESS ? 'pending' : 'default';
|
|
||||||
const handleSettingsSave = (values) => saveSetting(values.enableFlexiblePeerGrade);
|
const handleSettingsSave = (values) => saveSetting(values.enableFlexiblePeerGrade);
|
||||||
|
|
||||||
const handleSubmit = async (event) => {
|
const title = (
|
||||||
let success = true;
|
<div>
|
||||||
event.preventDefault();
|
<p>{intl.formatMessage(messages.heading)}</p>
|
||||||
|
<div className="pt-3">
|
||||||
success = success && await handleSettingsSave(formValues);
|
<Hyperlink
|
||||||
await setSaveError(!success);
|
className="text-primary-500 small"
|
||||||
if ((initialFormValues.enableFlexiblePeerGrade !== formValues.enableFlexiblePeerGrade) && success) {
|
destination={appInfo.documentationLinks?.learnMoreConfiguration}
|
||||||
success = await dispatch(updateModel({
|
target="_blank"
|
||||||
modelType: 'courseApps',
|
rel="noreferrer noopener"
|
||||||
model: {
|
>
|
||||||
id: appId, enabled: formValues.enableFlexiblePeerGrade,
|
{intl.formatMessage(messages.ORASettingsHelpLink)}
|
||||||
},
|
</Hyperlink>
|
||||||
}));
|
</div>
|
||||||
}
|
</div>
|
||||||
!success && alertRef?.current.scrollIntoView(); // eslint-disable-line @typescript-eslint/no-unused-expressions
|
);
|
||||||
};
|
|
||||||
|
|
||||||
const handleChange = (e) => {
|
|
||||||
setFormValues({ enableFlexiblePeerGrade: e.target.checked });
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (updateSettingsRequestStatus === RequestStatus.SUCCESSFUL) {
|
|
||||||
dispatch(updateSavingStatus({ status: '' }));
|
|
||||||
onClose();
|
|
||||||
}
|
|
||||||
}, [updateSettingsRequestStatus]);
|
|
||||||
|
|
||||||
const renderBody = () => {
|
|
||||||
switch (loadingStatus) {
|
|
||||||
case RequestStatus.SUCCESSFUL:
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{saveError && (
|
|
||||||
<Alert variant="danger" icon={Info} ref={alertRef}>
|
|
||||||
<Alert.Heading>
|
|
||||||
{formatMessage(messages.errorSavingTitle)}
|
|
||||||
</Alert.Heading>
|
|
||||||
{formatMessage(messages.errorSavingMessage)}
|
|
||||||
</Alert>
|
|
||||||
)}
|
|
||||||
<FormSwitchGroup
|
|
||||||
id="enable-flexible-peer-grade"
|
|
||||||
name="enableFlexiblePeerGrade"
|
|
||||||
label={(
|
|
||||||
<div className="d-flex align-items-center">
|
|
||||||
{formatMessage(messages.enableFlexPeerGradeLabel)}
|
|
||||||
{formValues.enableFlexiblePeerGrade && (
|
|
||||||
<Badge className="ml-2" variant="success" data-testid="enable-badge">
|
|
||||||
{formatMessage(messages.enabledBadgeLabel)}
|
|
||||||
</Badge>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
helpText={(
|
|
||||||
<div>
|
|
||||||
<p>{formatMessage(messages.enableFlexPeerGradeHelp)}</p>
|
|
||||||
<span className="py-3">
|
|
||||||
<Hyperlink
|
|
||||||
className="text-primary-500 small"
|
|
||||||
destination={appInfo.documentationLinks?.learnMoreConfiguration}
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer noopener"
|
|
||||||
>
|
|
||||||
{formatMessage(messages.ORASettingsHelpLink)}
|
|
||||||
</Hyperlink>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
onChange={handleChange}
|
|
||||||
checked={formValues.enableFlexiblePeerGrade}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
case RequestStatus.DENIED:
|
|
||||||
return <PermissionDeniedAlert />;
|
|
||||||
case RequestStatus.FAILED:
|
|
||||||
return <ConnectionErrorAlert />;
|
|
||||||
default:
|
|
||||||
return <Loading />;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ModalDialog
|
<AppSettingsModal
|
||||||
title={formatMessage(messages.heading)}
|
appId={appId}
|
||||||
isOpen
|
title={title}
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
size="lg"
|
initialValues={{ enableFlexiblePeerGrade }}
|
||||||
variant={modalVariant}
|
validationSchema={{ enableFlexiblePeerGrade: Yup.boolean() }}
|
||||||
hasCloseButton={isMobile}
|
onSettingsSave={handleSettingsSave}
|
||||||
isFullscreenScroll
|
hideAppToggle
|
||||||
isFullscreenOnMobile
|
|
||||||
>
|
>
|
||||||
<Form onSubmit={handleSubmit} data-testid="proctoringForm">
|
{({ values, handleChange, handleBlur }) => (
|
||||||
<ModalDialog.Header>
|
<FormSwitchGroup
|
||||||
<ModalDialog.Title>
|
id="enable-flexible-peer-grade"
|
||||||
{formatMessage(messages.heading)}
|
name="enableFlexiblePeerGrade"
|
||||||
</ModalDialog.Title>
|
label={intl.formatMessage(messages.enableFlexPeerGradeLabel)}
|
||||||
</ModalDialog.Header>
|
helpText={intl.formatMessage(messages.enableFlexPeerGradeHelp)}
|
||||||
<ModalDialog.Body>
|
onChange={handleChange}
|
||||||
{renderBody()}
|
onBlur={handleBlur}
|
||||||
</ModalDialog.Body>
|
checked={values.enableFlexiblePeerGrade}
|
||||||
<ModalDialog.Footer className="p-4">
|
/>
|
||||||
<ActionRow>
|
)}
|
||||||
<ModalDialog.CloseButton variant="tertiary">
|
</AppSettingsModal>
|
||||||
{formatMessage(messages.cancelLabel)}
|
|
||||||
</ModalDialog.CloseButton>
|
|
||||||
<StatefulButton
|
|
||||||
labels={{
|
|
||||||
default: formatMessage(messages.saveLabel),
|
|
||||||
pending: formatMessage(messages.pendingSaveLabel),
|
|
||||||
}}
|
|
||||||
description="Form save button"
|
|
||||||
data-testid="submissionButton"
|
|
||||||
disabled={submitButtonState === RequestStatus.IN_PROGRESS}
|
|
||||||
state={submitButtonState}
|
|
||||||
type="submit"
|
|
||||||
/>
|
|
||||||
</ActionRow>
|
|
||||||
</ModalDialog.Footer>
|
|
||||||
</Form>
|
|
||||||
</ModalDialog>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
ORASettings.propTypes = {
|
ORASettings.propTypes = {
|
||||||
|
intl: intlShape.isRequired,
|
||||||
onClose: PropTypes.func.isRequired,
|
onClose: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ORASettings;
|
export default injectIntl(ORASettings);
|
||||||
|
|||||||
@@ -1,152 +1,33 @@
|
|||||||
import {
|
import { shallow } from '@edx/react-unit-test-utils';
|
||||||
render,
|
|
||||||
screen,
|
|
||||||
waitFor,
|
|
||||||
within,
|
|
||||||
} from '@testing-library/react';
|
|
||||||
import ReactDOM from 'react-dom';
|
|
||||||
import { Routes, Route, MemoryRouter } from 'react-router-dom';
|
|
||||||
import { initializeMockApp } from '@edx/frontend-platform';
|
|
||||||
import MockAdapter from 'axios-mock-adapter';
|
|
||||||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
|
||||||
import { AppProvider, PageWrap } from '@edx/frontend-platform/react';
|
|
||||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
|
||||||
|
|
||||||
import initializeStore from 'CourseAuthoring/store';
|
|
||||||
import { executeThunk } from 'CourseAuthoring/utils';
|
|
||||||
import PagesAndResourcesProvider from 'CourseAuthoring/pages-and-resources/PagesAndResourcesProvider';
|
|
||||||
import { getCourseAppsApiUrl, getCourseAdvancedSettingsApiUrl } from 'CourseAuthoring/pages-and-resources/data/api';
|
|
||||||
import { fetchCourseApps, fetchCourseAppSettings } from 'CourseAuthoring/pages-and-resources/data/thunks';
|
|
||||||
import ORASettings from './Settings';
|
import ORASettings from './Settings';
|
||||||
import messages from './messages';
|
|
||||||
import {
|
|
||||||
courseId,
|
|
||||||
inititalState,
|
|
||||||
} from './factories/mockData';
|
|
||||||
|
|
||||||
let axiosMock;
|
jest.mock('@edx/frontend-platform/i18n', () => ({
|
||||||
let store;
|
...jest.requireActual('@edx/frontend-platform/i18n'), // use actual for all non-hook parts
|
||||||
const oraSettingsUrl = `/course/${courseId}/pages-and-resources/live/settings`;
|
injectIntl: (component) => component,
|
||||||
|
intlShape: {},
|
||||||
|
}));
|
||||||
|
jest.mock('yup', () => ({
|
||||||
|
boolean: jest.fn().mockReturnValue('Yub.boolean'),
|
||||||
|
}));
|
||||||
|
jest.mock('CourseAuthoring/generic/model-store', () => ({
|
||||||
|
useModel: jest.fn().mockReturnValue({ documentationLinks: { learnMoreConfiguration: 'https://learnmore.test' } }),
|
||||||
|
}));
|
||||||
|
jest.mock('CourseAuthoring/generic/FormSwitchGroup', () => 'FormSwitchGroup');
|
||||||
|
jest.mock('CourseAuthoring/utils', () => ({
|
||||||
|
useAppSetting: jest.fn().mockReturnValue(['abitrary value', jest.fn().mockName('saveSetting')]),
|
||||||
|
}));
|
||||||
|
jest.mock('CourseAuthoring/pages-and-resources/app-settings-modal/AppSettingsModal', () => 'AppSettingsModal');
|
||||||
|
|
||||||
// Modal creates a portal. Overriding ReactDOM.createPortal allows portals to be tested in jest.
|
const props = {
|
||||||
ReactDOM.createPortal = jest.fn(node => node);
|
onClose: jest.fn().mockName('onClose'),
|
||||||
|
intl: {
|
||||||
const renderComponent = () => (
|
formatMessage: (message) => message.defaultMessage,
|
||||||
render(
|
},
|
||||||
<IntlProvider locale="en">
|
|
||||||
<AppProvider store={store} wrapWithRouter={false}>
|
|
||||||
<PagesAndResourcesProvider courseId={courseId}>
|
|
||||||
<MemoryRouter initialEntries={[oraSettingsUrl]}>
|
|
||||||
<Routes>
|
|
||||||
<Route path={oraSettingsUrl} element={<PageWrap><ORASettings onClose={jest.fn()} /></PageWrap>} />
|
|
||||||
</Routes>
|
|
||||||
</MemoryRouter>
|
|
||||||
</PagesAndResourcesProvider>
|
|
||||||
</AppProvider>
|
|
||||||
</IntlProvider>,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
const mockStore = async ({
|
|
||||||
apiStatus,
|
|
||||||
enabled,
|
|
||||||
}) => {
|
|
||||||
const settings = ['forceOnFlexiblePeerOpenassessments'];
|
|
||||||
const fetchCourseAppsUrl = `${getCourseAppsApiUrl()}/${courseId}`;
|
|
||||||
const fetchAdvancedSettingsUrl = `${getCourseAdvancedSettingsApiUrl()}/${courseId}`;
|
|
||||||
|
|
||||||
axiosMock.onGet(fetchCourseAppsUrl).reply(
|
|
||||||
200,
|
|
||||||
[{
|
|
||||||
allowed_operations: { enable: false, configure: true },
|
|
||||||
description: 'setting',
|
|
||||||
documentation_links: { learnMoreConfiguration: '' },
|
|
||||||
enabled,
|
|
||||||
id: 'ora_settings',
|
|
||||||
name: 'Flexible Peer Grading for ORAs',
|
|
||||||
}],
|
|
||||||
);
|
|
||||||
axiosMock.onGet(fetchAdvancedSettingsUrl).reply(
|
|
||||||
apiStatus,
|
|
||||||
{ force_on_flexible_peer_openassessments: { value: enabled } },
|
|
||||||
);
|
|
||||||
|
|
||||||
await executeThunk(fetchCourseApps(courseId), store.dispatch);
|
|
||||||
await executeThunk(fetchCourseAppSettings(courseId, settings), store.dispatch);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('ORASettings', () => {
|
describe('ORASettings', () => {
|
||||||
beforeEach(async () => {
|
it('should render', () => {
|
||||||
initializeMockApp({
|
const wrapper = shallow(<ORASettings {...props} />);
|
||||||
authenticatedUser: {
|
expect(wrapper.snapshot).toMatchSnapshot();
|
||||||
userId: 3,
|
|
||||||
username: 'abc123',
|
|
||||||
administrator: false,
|
|
||||||
roles: [],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
store = initializeStore(inititalState);
|
|
||||||
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Flexible peer grading configuration modal is visible', async () => {
|
|
||||||
renderComponent();
|
|
||||||
expect(screen.getByRole('dialog')).toBeVisible();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Displays "Configure Flexible Peer Grading" heading', async () => {
|
|
||||||
renderComponent();
|
|
||||||
const headingElement = screen.getByText(messages.heading.defaultMessage);
|
|
||||||
|
|
||||||
expect(headingElement).toBeVisible();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Displays loading component', () => {
|
|
||||||
renderComponent();
|
|
||||||
const loadingElement = screen.getByRole('status');
|
|
||||||
|
|
||||||
expect(within(loadingElement).getByText('Loading...')).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Displays Connection Error Alert', async () => {
|
|
||||||
await mockStore({ apiStatus: 404, enabled: true });
|
|
||||||
renderComponent();
|
|
||||||
const errorAlert = screen.getByRole('alert');
|
|
||||||
|
|
||||||
expect(within(errorAlert).getByText('We encountered a technical error when loading this page.', { exact: false })).toBeVisible();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Displays Permissions Error Alert', async () => {
|
|
||||||
await mockStore({ apiStatus: 403, enabled: true });
|
|
||||||
renderComponent();
|
|
||||||
const errorAlert = screen.getByRole('alert');
|
|
||||||
|
|
||||||
expect(within(errorAlert).getByText('You are not authorized to view this page', { exact: false })).toBeVisible();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Displays title, helper text and badge when flexible peer grading button is enabled', async () => {
|
|
||||||
renderComponent();
|
|
||||||
await mockStore({ apiStatus: 200, enabled: true });
|
|
||||||
|
|
||||||
waitFor(() => {
|
|
||||||
const label = screen.getByText(messages.enableFlexPeerGradeLabel.defaultMessage);
|
|
||||||
const enableBadge = screen.getByTestId('enable-badge');
|
|
||||||
|
|
||||||
expect(label).toBeVisible();
|
|
||||||
|
|
||||||
expect(enableBadge).toHaveTextContent('Enabled');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Displays title, helper text and hides badge when flexible peer grading button is disabled', async () => {
|
|
||||||
renderComponent();
|
|
||||||
await mockStore({ apiStatus: 200, enabled: false });
|
|
||||||
|
|
||||||
const label = await screen.findByText(messages.enableFlexPeerGradeLabel.defaultMessage);
|
|
||||||
const enableBadge = screen.queryByTestId('enable-badge');
|
|
||||||
|
|
||||||
expect(label).toBeVisible();
|
|
||||||
|
|
||||||
expect(enableBadge).toBeNull();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`ORASettings should render 1`] = `
|
||||||
|
<AppSettingsModal
|
||||||
|
appId="ora_settings"
|
||||||
|
hideAppToggle={true}
|
||||||
|
initialValues={
|
||||||
|
Object {
|
||||||
|
"enableFlexiblePeerGrade": "abitrary value",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onClose={[MockFunction onClose]}
|
||||||
|
onSettingsSave={[Function]}
|
||||||
|
title={
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
Configure open response assessment
|
||||||
|
</p>
|
||||||
|
<div
|
||||||
|
className="pt-3"
|
||||||
|
>
|
||||||
|
<withDeprecatedProps(Hyperlink)
|
||||||
|
className="text-primary-500 small"
|
||||||
|
destination="https://learnmore.test"
|
||||||
|
rel="noreferrer noopener"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
Learn more about open response assessment settings
|
||||||
|
</withDeprecatedProps(Hyperlink)>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
validationSchema={
|
||||||
|
Object {
|
||||||
|
"enableFlexiblePeerGrade": "Yub.boolean",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
[Function]
|
||||||
|
</AppSettingsModal>
|
||||||
|
`;
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
export const courseId = 'course-v1:org+num+run';
|
|
||||||
|
|
||||||
export const inititalState = {
|
|
||||||
courseDetail: {
|
|
||||||
courseId,
|
|
||||||
status: 'successful',
|
|
||||||
},
|
|
||||||
pagesAndResources: {
|
|
||||||
courseAppIds: ['ora_settings'],
|
|
||||||
loadingStatus: 'in-progress',
|
|
||||||
savingStatus: '',
|
|
||||||
courseAppsApiStatus: {},
|
|
||||||
courseAppSettings: {},
|
|
||||||
},
|
|
||||||
models: {
|
|
||||||
courseApps: {
|
|
||||||
ora_settings: {
|
|
||||||
id: 'ora_settings',
|
|
||||||
name: 'Flexible Peer Grading',
|
|
||||||
enabled: true,
|
|
||||||
description: 'Enable flexible peer grading',
|
|
||||||
allowedOperations: {
|
|
||||||
enable: false,
|
|
||||||
configure: true,
|
|
||||||
},
|
|
||||||
documentationLinks: {
|
|
||||||
learnMoreConfiguration: '',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -3,51 +3,19 @@ import { defineMessages } from '@edx/frontend-platform/i18n';
|
|||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
heading: {
|
heading: {
|
||||||
id: 'course-authoring.pages-resources.ora.heading',
|
id: 'course-authoring.pages-resources.ora.heading',
|
||||||
defaultMessage: 'Configure Flexible Peer Grading',
|
defaultMessage: 'Configure open response assessment',
|
||||||
description: 'Title for the modal dialog header',
|
|
||||||
},
|
},
|
||||||
ORASettingsHelpLink: {
|
ORASettingsHelpLink: {
|
||||||
id: 'course-authoring.pages-resources.ora.flex-peer-grading.link',
|
id: 'course-authoring.pages-resources.ora.flex-peer-grading.link',
|
||||||
defaultMessage: 'Learn more about open response assessment settings',
|
defaultMessage: 'Learn more about open response assessment settings',
|
||||||
description: 'Descriptive text for the hyperlink to the docs site',
|
|
||||||
},
|
},
|
||||||
enableFlexPeerGradeLabel: {
|
enableFlexPeerGradeLabel: {
|
||||||
id: 'course-authoring.pages-resources.ora.flex-peer-grading.label',
|
id: 'course-authoring.pages-resources.ora.flex-peer-grading.label',
|
||||||
defaultMessage: 'Flex Peer Grading',
|
defaultMessage: 'Flex Peer Grading',
|
||||||
description: 'Label for form switch',
|
|
||||||
},
|
},
|
||||||
enableFlexPeerGradeHelp: {
|
enableFlexPeerGradeHelp: {
|
||||||
id: 'course-authoring.pages-resources.ora.flex-peer-grading.help',
|
id: 'course-authoring.pages-resources.ora.flex-peer-grading.help',
|
||||||
defaultMessage: 'Turn on Flexible Peer Grading for all open response assessments in the course with peer grading.',
|
defaultMessage: 'Turn on Flexible Peer Grading for all open response assessments in the course with peer grading.',
|
||||||
description: 'Help text describing what happens when the switch is enabled',
|
|
||||||
},
|
|
||||||
enabledBadgeLabel: {
|
|
||||||
id: 'course-authoring.pages-resources.ora.flex-peer-grading.enabled-badge.label',
|
|
||||||
defaultMessage: 'Enabled',
|
|
||||||
description: 'Label for badge that show users that a setting is enabled',
|
|
||||||
},
|
|
||||||
cancelLabel: {
|
|
||||||
id: 'course-authoring.pages-resources.ora.flex-peer-grading.cancel-button.label',
|
|
||||||
defaultMessage: 'Cancel',
|
|
||||||
description: 'Label for button that cancels user changes',
|
|
||||||
},
|
|
||||||
saveLabel: {
|
|
||||||
id: 'course-authoring.pages-resources.ora.flex-peer-grading.save-button.label',
|
|
||||||
defaultMessage: 'Save',
|
|
||||||
description: 'Label for button that saves user changes',
|
|
||||||
},
|
|
||||||
pendingSaveLabel: {
|
|
||||||
id: 'course-authoring.pages-resources.ora.flex-peer-grading.pending-save-button.label',
|
|
||||||
defaultMessage: 'Saving',
|
|
||||||
description: 'Label for button that has pending api save calls',
|
|
||||||
},
|
|
||||||
errorSavingTitle: {
|
|
||||||
id: 'course-authoring.pages-resources.ora.flex-peer-grading.save-error.title',
|
|
||||||
defaultMessage: 'We couldn\'t apply your changes.',
|
|
||||||
},
|
|
||||||
errorSavingMessage: {
|
|
||||||
id: 'course-authoring.pages-resources.ora.flex-peer-grading.save-error.message',
|
|
||||||
defaultMessage: 'Please check your entries and try again.',
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,16 +3,15 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Open Response Assessment configuration for courses using it",
|
"description": "Open Response Assessment configuration for courses using it",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@edx/frontend-app-authoring": "*",
|
"@edx/frontend-app-course-authoring": "*",
|
||||||
"@edx/frontend-platform": "*",
|
"@edx/frontend-platform": "*",
|
||||||
"@openedx/paragon": "*",
|
"@openedx/paragon": "*",
|
||||||
"prop-types": "*",
|
"prop-types": "*",
|
||||||
"react": "*",
|
"react": "*",
|
||||||
"react-redux": "*",
|
|
||||||
"yup": "*"
|
"yup": "*"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"@edx/frontend-app-authoring": {
|
"@edx/frontend-app-course-authoring": {
|
||||||
"optional": true
|
"optional": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,8 +64,6 @@ const ProctoringSettings = ({ intl, onClose }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { courseId } = useContext(PagesAndResourcesContext);
|
const { courseId } = useContext(PagesAndResourcesContext);
|
||||||
const courseDetails = useModel('courseDetails', courseId);
|
|
||||||
const org = courseDetails?.org;
|
|
||||||
const appInfo = useModel('courseApps', 'proctoring');
|
const appInfo = useModel('courseApps', 'proctoring');
|
||||||
const alertRef = React.createRef();
|
const alertRef = React.createRef();
|
||||||
const saveStatusAlertRef = React.createRef();
|
const saveStatusAlertRef = React.createRef();
|
||||||
@@ -148,9 +146,9 @@ const ProctoringSettings = ({ intl, onClose }) => {
|
|||||||
setSaveSuccess(true);
|
setSaveSuccess(true);
|
||||||
setSaveError(false);
|
setSaveError(false);
|
||||||
setSubmissionInProgress(false);
|
setSubmissionInProgress(false);
|
||||||
}).catch((error) => {
|
}).catch(() => {
|
||||||
setSaveSuccess(false);
|
setSaveSuccess(false);
|
||||||
setSaveError(error);
|
setSaveError(true);
|
||||||
setSubmissionInProgress(false);
|
setSubmissionInProgress(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -460,44 +458,6 @@ const ProctoringSettings = ({ intl, onClose }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderSaveError() {
|
function renderSaveError() {
|
||||||
let errorMessage = (
|
|
||||||
<FormattedMessage
|
|
||||||
id="authoring.proctoring.alert.error"
|
|
||||||
defaultMessage={`
|
|
||||||
We encountered a technical error while trying to save proctored exam settings.
|
|
||||||
This might be a temporary issue, so please try again in a few minutes.
|
|
||||||
If the problem persists, please go to the {support_link} for help.
|
|
||||||
`}
|
|
||||||
values={{
|
|
||||||
support_link: (
|
|
||||||
<Alert.Link href={getConfig().SUPPORT_URL}>
|
|
||||||
{intl.formatMessage(messages['authoring.proctoring.support.text'])}
|
|
||||||
</Alert.Link>
|
|
||||||
),
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
if (saveError?.response.status === 403) {
|
|
||||||
errorMessage = (
|
|
||||||
<FormattedMessage
|
|
||||||
id="authoring.proctoring.alert.error.forbidden"
|
|
||||||
defaultMessage={`
|
|
||||||
You do not have permission to edit proctored exam settings for this course.
|
|
||||||
If you are a course team member and this problem persists,
|
|
||||||
please go to the {support_link} for help.
|
|
||||||
`}
|
|
||||||
values={{
|
|
||||||
support_link: (
|
|
||||||
<Alert.Link href={getConfig().SUPPORT_URL}>
|
|
||||||
{intl.formatMessage(messages['authoring.proctoring.support.text'])}
|
|
||||||
</Alert.Link>
|
|
||||||
),
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Alert
|
<Alert
|
||||||
variant="danger"
|
variant="danger"
|
||||||
@@ -507,7 +467,21 @@ const ProctoringSettings = ({ intl, onClose }) => {
|
|||||||
onClose={() => setSaveError(false)}
|
onClose={() => setSaveError(false)}
|
||||||
dismissible
|
dismissible
|
||||||
>
|
>
|
||||||
{errorMessage}
|
<FormattedMessage
|
||||||
|
id="authoring.examsettings.alert.error"
|
||||||
|
defaultMessage={`
|
||||||
|
We encountered a technical error while trying to save proctored exam settings.
|
||||||
|
This might be a temporary issue, so please try again in a few minutes.
|
||||||
|
If the problem persists, please go to the {support_link} for help.
|
||||||
|
`}
|
||||||
|
values={{
|
||||||
|
support_link: (
|
||||||
|
<Alert.Link href={getConfig().SUPPORT_URL}>
|
||||||
|
{intl.formatMessage(messages['authoring.proctoring.support.text'])}
|
||||||
|
</Alert.Link>
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</Alert>
|
</Alert>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -516,7 +490,7 @@ const ProctoringSettings = ({ intl, onClose }) => {
|
|||||||
Promise.all([
|
Promise.all([
|
||||||
StudioApiService.getProctoredExamSettingsData(courseId),
|
StudioApiService.getProctoredExamSettingsData(courseId),
|
||||||
ExamsApiService.isAvailable() ? ExamsApiService.getCourseExamConfiguration(courseId) : Promise.resolve(),
|
ExamsApiService.isAvailable() ? ExamsApiService.getCourseExamConfiguration(courseId) : Promise.resolve(),
|
||||||
ExamsApiService.isAvailable() ? ExamsApiService.getAvailableProviders(org) : Promise.resolve(),
|
ExamsApiService.isAvailable() ? ExamsApiService.getAvailableProviders() : Promise.resolve(),
|
||||||
])
|
])
|
||||||
.then(
|
.then(
|
||||||
([settingsResponse, examConfigResponse, ltiProvidersResponse]) => {
|
([settingsResponse, examConfigResponse, ltiProvidersResponse]) => {
|
||||||
|
|||||||
@@ -15,9 +15,8 @@ import initializeStore from 'CourseAuthoring/store';
|
|||||||
import PagesAndResourcesProvider from 'CourseAuthoring/pages-and-resources/PagesAndResourcesProvider';
|
import PagesAndResourcesProvider from 'CourseAuthoring/pages-and-resources/PagesAndResourcesProvider';
|
||||||
import ProctoredExamSettings from './Settings';
|
import ProctoredExamSettings from './Settings';
|
||||||
|
|
||||||
const courseId = 'course-v1%3AedX%2BDemoX%2BDemo_Course';
|
|
||||||
const defaultProps = {
|
const defaultProps = {
|
||||||
courseId,
|
courseId: 'course-v1%3AedX%2BDemoX%2BDemo_Course',
|
||||||
onClose: () => {},
|
onClose: () => {},
|
||||||
};
|
};
|
||||||
const IntlProctoredExamSettings = injectIntl(ProctoredExamSettings);
|
const IntlProctoredExamSettings = injectIntl(ProctoredExamSettings);
|
||||||
@@ -35,7 +34,7 @@ const intlWrapper = children => (
|
|||||||
let axiosMock;
|
let axiosMock;
|
||||||
|
|
||||||
describe('ProctoredExamSettings', () => {
|
describe('ProctoredExamSettings', () => {
|
||||||
function setupApp(isAdmin = true, org = undefined) {
|
function setupApp(isAdmin = true) {
|
||||||
mergeConfig({
|
mergeConfig({
|
||||||
EXAMS_BASE_URL: 'http://exams.testing.co',
|
EXAMS_BASE_URL: 'http://exams.testing.co',
|
||||||
}, 'CourseAuthoringConfig');
|
}, 'CourseAuthoringConfig');
|
||||||
@@ -53,18 +52,12 @@ describe('ProctoredExamSettings', () => {
|
|||||||
courseApps: {
|
courseApps: {
|
||||||
proctoring: {},
|
proctoring: {},
|
||||||
},
|
},
|
||||||
courseDetails: {
|
|
||||||
[courseId]: {
|
|
||||||
start: Date(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
...(org ? { courseDetails: { [courseId]: { org } } } : {}),
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
|
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
|
||||||
axiosMock.onGet(
|
axiosMock.onGet(
|
||||||
`${ExamsApiService.getExamsBaseUrl()}/api/v1/providers${org ? `?org=${org}` : ''}`,
|
`${ExamsApiService.getExamsBaseUrl()}/api/v1/providers`,
|
||||||
).reply(200, [
|
).reply(200, [
|
||||||
{
|
{
|
||||||
name: 'test_lti',
|
name: 'test_lti',
|
||||||
@@ -110,7 +103,9 @@ describe('ProctoredExamSettings', () => {
|
|||||||
screen.getByDisplayValue('mockproc');
|
screen.getByDisplayValue('mockproc');
|
||||||
});
|
});
|
||||||
const selectElement = screen.getByDisplayValue('mockproc');
|
const selectElement = screen.getByDisplayValue('mockproc');
|
||||||
fireEvent.change(selectElement, { target: { value: 'proctortrack' } });
|
await act(async () => {
|
||||||
|
fireEvent.change(selectElement, { target: { value: 'proctortrack' } });
|
||||||
|
});
|
||||||
const zendeskTicketInput = screen.getByTestId('createZendeskTicketsNo');
|
const zendeskTicketInput = screen.getByTestId('createZendeskTicketsNo');
|
||||||
expect(zendeskTicketInput.checked).toEqual(true);
|
expect(zendeskTicketInput.checked).toEqual(true);
|
||||||
});
|
});
|
||||||
@@ -120,7 +115,9 @@ describe('ProctoredExamSettings', () => {
|
|||||||
screen.getByDisplayValue('mockproc');
|
screen.getByDisplayValue('mockproc');
|
||||||
});
|
});
|
||||||
const selectElement = screen.getByDisplayValue('mockproc');
|
const selectElement = screen.getByDisplayValue('mockproc');
|
||||||
fireEvent.change(selectElement, { target: { value: 'software_secure' } });
|
await act(async () => {
|
||||||
|
fireEvent.change(selectElement, { target: { value: 'software_secure' } });
|
||||||
|
});
|
||||||
const zendeskTicketInput = screen.getByTestId('createZendeskTicketsYes');
|
const zendeskTicketInput = screen.getByTestId('createZendeskTicketsYes');
|
||||||
expect(zendeskTicketInput.checked).toEqual(true);
|
expect(zendeskTicketInput.checked).toEqual(true);
|
||||||
});
|
});
|
||||||
@@ -130,7 +127,9 @@ describe('ProctoredExamSettings', () => {
|
|||||||
screen.getByDisplayValue('mockproc');
|
screen.getByDisplayValue('mockproc');
|
||||||
});
|
});
|
||||||
const selectElement = screen.getByDisplayValue('mockproc');
|
const selectElement = screen.getByDisplayValue('mockproc');
|
||||||
fireEvent.change(selectElement, { target: { value: 'mockproc' } });
|
await act(async () => {
|
||||||
|
fireEvent.change(selectElement, { target: { value: 'mockproc' } });
|
||||||
|
});
|
||||||
const zendeskTicketInput = screen.getByTestId('createZendeskTicketsYes');
|
const zendeskTicketInput = screen.getByTestId('createZendeskTicketsYes');
|
||||||
expect(zendeskTicketInput.checked).toEqual(true);
|
expect(zendeskTicketInput.checked).toEqual(true);
|
||||||
});
|
});
|
||||||
@@ -177,7 +176,9 @@ describe('ProctoredExamSettings', () => {
|
|||||||
|
|
||||||
let enabledProctoredExamCheck = screen.getAllByLabelText('Proctored exams', { exact: false })[0];
|
let enabledProctoredExamCheck = screen.getAllByLabelText('Proctored exams', { exact: false })[0];
|
||||||
expect(enabledProctoredExamCheck.checked).toEqual(true);
|
expect(enabledProctoredExamCheck.checked).toEqual(true);
|
||||||
fireEvent.click(enabledProctoredExamCheck, { target: { value: false } });
|
await act(async () => {
|
||||||
|
fireEvent.click(enabledProctoredExamCheck, { target: { value: false } });
|
||||||
|
});
|
||||||
enabledProctoredExamCheck = screen.getByLabelText('Proctored exams');
|
enabledProctoredExamCheck = screen.getByLabelText('Proctored exams');
|
||||||
expect(enabledProctoredExamCheck.checked).toEqual(false);
|
expect(enabledProctoredExamCheck.checked).toEqual(false);
|
||||||
expect(screen.queryByText('Allow opting out of proctored exams')).toBeNull();
|
expect(screen.queryByText('Allow opting out of proctored exams')).toBeNull();
|
||||||
@@ -192,7 +193,9 @@ describe('ProctoredExamSettings', () => {
|
|||||||
screen.getByDisplayValue('mockproc');
|
screen.getByDisplayValue('mockproc');
|
||||||
});
|
});
|
||||||
const selectElement = screen.getByDisplayValue('mockproc');
|
const selectElement = screen.getByDisplayValue('mockproc');
|
||||||
fireEvent.change(selectElement, { target: { value: 'test_lti' } });
|
await act(async () => {
|
||||||
|
fireEvent.change(selectElement, { target: { value: 'test_lti' } });
|
||||||
|
});
|
||||||
expect(screen.queryByTestId('allowOptingOutRadio')).toBeNull();
|
expect(screen.queryByTestId('allowOptingOutRadio')).toBeNull();
|
||||||
expect(screen.queryByTestId('createZendeskTicketsYes')).toBeNull();
|
expect(screen.queryByTestId('createZendeskTicketsYes')).toBeNull();
|
||||||
expect(screen.queryByTestId('createZendeskTicketsNo')).toBeNull();
|
expect(screen.queryByTestId('createZendeskTicketsNo')).toBeNull();
|
||||||
@@ -234,9 +237,13 @@ describe('ProctoredExamSettings', () => {
|
|||||||
screen.getByDisplayValue('proctortrack');
|
screen.getByDisplayValue('proctortrack');
|
||||||
});
|
});
|
||||||
const selectEscalationEmailElement = screen.getByDisplayValue('test@example.com');
|
const selectEscalationEmailElement = screen.getByDisplayValue('test@example.com');
|
||||||
fireEvent.change(selectEscalationEmailElement, { target: { value: '' } });
|
await act(async () => {
|
||||||
|
fireEvent.change(selectEscalationEmailElement, { target: { value: '' } });
|
||||||
|
});
|
||||||
const selectButton = screen.getByTestId('submissionButton');
|
const selectButton = screen.getByTestId('submissionButton');
|
||||||
fireEvent.click(selectButton);
|
await act(async () => {
|
||||||
|
fireEvent.click(selectButton);
|
||||||
|
});
|
||||||
|
|
||||||
// verify alert content and focus management
|
// verify alert content and focus management
|
||||||
const escalationEmailError = screen.getByTestId('escalationEmailError');
|
const escalationEmailError = screen.getByTestId('escalationEmailError');
|
||||||
@@ -245,7 +252,9 @@ describe('ProctoredExamSettings', () => {
|
|||||||
|
|
||||||
// verify alert link links to offending input
|
// verify alert link links to offending input
|
||||||
const errorLink = screen.getByTestId('escalationEmailErrorLink');
|
const errorLink = screen.getByTestId('escalationEmailErrorLink');
|
||||||
fireEvent.click(errorLink);
|
await act(async () => {
|
||||||
|
fireEvent.click(errorLink);
|
||||||
|
});
|
||||||
const escalationEmailInput = screen.getByTestId('escalationEmail');
|
const escalationEmailInput = screen.getByTestId('escalationEmail');
|
||||||
expect(document.activeElement).toEqual(escalationEmailInput);
|
expect(document.activeElement).toEqual(escalationEmailInput);
|
||||||
});
|
});
|
||||||
@@ -256,12 +265,18 @@ describe('ProctoredExamSettings', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const selectElement = screen.getByDisplayValue('proctortrack');
|
const selectElement = screen.getByDisplayValue('proctortrack');
|
||||||
fireEvent.change(selectElement, { target: { value: provider } });
|
await act(async () => {
|
||||||
|
fireEvent.change(selectElement, { target: { value: provider } });
|
||||||
|
});
|
||||||
|
|
||||||
const selectEscalationEmailElement = screen.getByDisplayValue('test@example.com');
|
const selectEscalationEmailElement = screen.getByDisplayValue('test@example.com');
|
||||||
fireEvent.change(selectEscalationEmailElement, { target: { value: 'foo.bar' } });
|
await act(async () => {
|
||||||
const proctoringForm = screen.getByTestId('proctoringForm');
|
fireEvent.change(selectEscalationEmailElement, { target: { value: 'foo.bar' } });
|
||||||
fireEvent.submit(proctoringForm);
|
});
|
||||||
|
const selectButton = screen.getByTestId('submissionButton');
|
||||||
|
await act(async () => {
|
||||||
|
fireEvent.click(selectButton);
|
||||||
|
});
|
||||||
|
|
||||||
// verify alert content and focus management
|
// verify alert content and focus management
|
||||||
const escalationEmailError = screen.getByTestId('escalationEmailError');
|
const escalationEmailError = screen.getByTestId('escalationEmailError');
|
||||||
@@ -271,7 +286,9 @@ describe('ProctoredExamSettings', () => {
|
|||||||
|
|
||||||
// verify alert link links to offending input
|
// verify alert link links to offending input
|
||||||
const errorLink = screen.getByTestId('escalationEmailErrorLink');
|
const errorLink = screen.getByTestId('escalationEmailErrorLink');
|
||||||
fireEvent.click(errorLink);
|
await act(async () => {
|
||||||
|
fireEvent.click(errorLink);
|
||||||
|
});
|
||||||
const escalationEmailInput = screen.getByTestId('escalationEmail');
|
const escalationEmailInput = screen.getByTestId('escalationEmail');
|
||||||
expect(document.activeElement).toEqual(escalationEmailInput);
|
expect(document.activeElement).toEqual(escalationEmailInput);
|
||||||
});
|
});
|
||||||
@@ -281,11 +298,15 @@ describe('ProctoredExamSettings', () => {
|
|||||||
screen.getByDisplayValue('proctortrack');
|
screen.getByDisplayValue('proctortrack');
|
||||||
});
|
});
|
||||||
const selectEscalationEmailElement = screen.getByDisplayValue('test@example.com');
|
const selectEscalationEmailElement = screen.getByDisplayValue('test@example.com');
|
||||||
fireEvent.change(selectEscalationEmailElement, { target: { value: 'foo.bar' } });
|
await act(async () => {
|
||||||
|
fireEvent.change(selectEscalationEmailElement, { target: { value: 'foo.bar' } });
|
||||||
|
});
|
||||||
const enableProctoringElement = screen.getByText('Proctored exams');
|
const enableProctoringElement = screen.getByText('Proctored exams');
|
||||||
fireEvent.click(enableProctoringElement);
|
await act(async () => fireEvent.click(enableProctoringElement));
|
||||||
const selectButton = screen.getByTestId('submissionButton');
|
const selectButton = screen.getByTestId('submissionButton');
|
||||||
fireEvent.click(selectButton);
|
await act(async () => {
|
||||||
|
fireEvent.click(selectButton);
|
||||||
|
});
|
||||||
|
|
||||||
// verify alert content and focus management
|
// verify alert content and focus management
|
||||||
const escalationEmailError = screen.getByTestId('escalationEmailError');
|
const escalationEmailError = screen.getByTestId('escalationEmailError');
|
||||||
@@ -299,22 +320,24 @@ describe('ProctoredExamSettings', () => {
|
|||||||
screen.getByDisplayValue('proctortrack');
|
screen.getByDisplayValue('proctortrack');
|
||||||
});
|
});
|
||||||
const selectEscalationEmailElement = screen.getByDisplayValue('test@example.com');
|
const selectEscalationEmailElement = screen.getByDisplayValue('test@example.com');
|
||||||
fireEvent.change(selectEscalationEmailElement, { target: { value: '' } });
|
await act(async () => {
|
||||||
|
fireEvent.change(selectEscalationEmailElement, { target: { value: '' } });
|
||||||
|
});
|
||||||
const enableProctoringElement = screen.getByText('Proctored exams');
|
const enableProctoringElement = screen.getByText('Proctored exams');
|
||||||
fireEvent.click(enableProctoringElement);
|
await act(async () => fireEvent.click(enableProctoringElement));
|
||||||
const selectButton = screen.getByTestId('submissionButton');
|
const selectButton = screen.getByTestId('submissionButton');
|
||||||
fireEvent.click(selectButton);
|
await act(async () => {
|
||||||
|
fireEvent.click(selectButton);
|
||||||
|
});
|
||||||
|
|
||||||
// verify there is no escalation email alert, and focus has been set on save success alert
|
// verify there is no escalation email alert, and focus has been set on save success alert
|
||||||
expect(screen.queryByTestId('escalationEmailError')).toBeNull();
|
expect(screen.queryByTestId('escalationEmailError')).toBeNull();
|
||||||
|
|
||||||
await waitFor(() => {
|
const errorAlert = screen.getByTestId('saveSuccess');
|
||||||
const errorAlert = screen.getByTestId('saveSuccess');
|
expect(errorAlert.textContent).toEqual(
|
||||||
expect(errorAlert.textContent).toEqual(
|
expect.stringContaining('Proctored exam settings saved successfully.'),
|
||||||
expect.stringContaining('Proctored exam settings saved successfully.'),
|
);
|
||||||
);
|
expect(document.activeElement).toEqual(errorAlert);
|
||||||
expect(document.activeElement).toEqual(errorAlert);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`Has no error when valid proctoring escalation email is provided with ${provider} selected`, async () => {
|
it(`Has no error when valid proctoring escalation email is provided with ${provider} selected`, async () => {
|
||||||
@@ -322,20 +345,22 @@ describe('ProctoredExamSettings', () => {
|
|||||||
screen.getByDisplayValue('proctortrack');
|
screen.getByDisplayValue('proctortrack');
|
||||||
});
|
});
|
||||||
const selectEscalationEmailElement = screen.getByDisplayValue('test@example.com');
|
const selectEscalationEmailElement = screen.getByDisplayValue('test@example.com');
|
||||||
fireEvent.change(selectEscalationEmailElement, { target: { value: 'foo@bar.com' } });
|
await act(async () => {
|
||||||
|
fireEvent.change(selectEscalationEmailElement, { target: { value: 'foo@bar.com' } });
|
||||||
|
});
|
||||||
const selectButton = screen.getByTestId('submissionButton');
|
const selectButton = screen.getByTestId('submissionButton');
|
||||||
fireEvent.click(selectButton);
|
await act(async () => {
|
||||||
|
fireEvent.click(selectButton);
|
||||||
|
});
|
||||||
|
|
||||||
// verify there is no escalation email alert, and focus has been set on save success alert
|
// verify there is no escalation email alert, and focus has been set on save success alert
|
||||||
expect(screen.queryByTestId('escalationEmailError')).toBeNull();
|
expect(screen.queryByTestId('escalationEmailError')).toBeNull();
|
||||||
|
|
||||||
await waitFor(() => {
|
const errorAlert = screen.getByTestId('saveSuccess');
|
||||||
const errorAlert = screen.getByTestId('saveSuccess');
|
expect(errorAlert.textContent).toEqual(
|
||||||
expect(errorAlert.textContent).toEqual(
|
expect.stringContaining('Proctored exam settings saved successfully.'),
|
||||||
expect.stringContaining('Proctored exam settings saved successfully.'),
|
);
|
||||||
);
|
expect(document.activeElement).toEqual(errorAlert);
|
||||||
expect(document.activeElement).toEqual(errorAlert);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`Escalation email field hidden when proctoring backend is not ${provider}`, async () => {
|
it(`Escalation email field hidden when proctoring backend is not ${provider}`, async () => {
|
||||||
@@ -345,7 +370,9 @@ describe('ProctoredExamSettings', () => {
|
|||||||
const proctoringBackendSelect = screen.getByDisplayValue('proctortrack');
|
const proctoringBackendSelect = screen.getByDisplayValue('proctortrack');
|
||||||
const selectEscalationEmailElement = screen.getByTestId('escalationEmail');
|
const selectEscalationEmailElement = screen.getByTestId('escalationEmail');
|
||||||
expect(selectEscalationEmailElement.value).toEqual('test@example.com');
|
expect(selectEscalationEmailElement.value).toEqual('test@example.com');
|
||||||
fireEvent.change(proctoringBackendSelect, { target: { value: 'software_secure' } });
|
await act(async () => {
|
||||||
|
fireEvent.change(proctoringBackendSelect, { target: { value: 'software_secure' } });
|
||||||
|
});
|
||||||
expect(screen.queryByTestId('escalationEmail')).toBeNull();
|
expect(screen.queryByTestId('escalationEmail')).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -355,9 +382,13 @@ describe('ProctoredExamSettings', () => {
|
|||||||
});
|
});
|
||||||
const proctoringBackendSelect = screen.getByDisplayValue('proctortrack');
|
const proctoringBackendSelect = screen.getByDisplayValue('proctortrack');
|
||||||
let selectEscalationEmailElement = screen.getByTestId('escalationEmail');
|
let selectEscalationEmailElement = screen.getByTestId('escalationEmail');
|
||||||
fireEvent.change(proctoringBackendSelect, { target: { value: 'software_secure' } });
|
await act(async () => {
|
||||||
|
fireEvent.change(proctoringBackendSelect, { target: { value: 'software_secure' } });
|
||||||
|
});
|
||||||
expect(screen.queryByTestId('escalationEmail')).toBeNull();
|
expect(screen.queryByTestId('escalationEmail')).toBeNull();
|
||||||
fireEvent.change(proctoringBackendSelect, { target: { value: 'proctortrack' } });
|
await act(async () => {
|
||||||
|
fireEvent.change(proctoringBackendSelect, { target: { value: 'proctortrack' } });
|
||||||
|
});
|
||||||
expect(screen.queryByTestId('escalationEmail')).toBeDefined();
|
expect(screen.queryByTestId('escalationEmail')).toBeDefined();
|
||||||
selectEscalationEmailElement = screen.getByTestId('escalationEmail');
|
selectEscalationEmailElement = screen.getByTestId('escalationEmail');
|
||||||
expect(selectEscalationEmailElement.value).toEqual('test@example.com');
|
expect(selectEscalationEmailElement.value).toEqual('test@example.com');
|
||||||
@@ -368,8 +399,12 @@ describe('ProctoredExamSettings', () => {
|
|||||||
screen.getByDisplayValue('proctortrack');
|
screen.getByDisplayValue('proctortrack');
|
||||||
});
|
});
|
||||||
const selectEscalationEmailElement = screen.getByDisplayValue('test@example.com');
|
const selectEscalationEmailElement = screen.getByDisplayValue('test@example.com');
|
||||||
fireEvent.change(selectEscalationEmailElement, { target: { value: '' } });
|
await act(async () => {
|
||||||
fireEvent.submit(selectEscalationEmailElement);
|
fireEvent.change(selectEscalationEmailElement, { target: { value: '' } });
|
||||||
|
});
|
||||||
|
await act(async () => {
|
||||||
|
fireEvent.submit(selectEscalationEmailElement);
|
||||||
|
});
|
||||||
// if the error appears, the form has been submitted
|
// if the error appears, the form has been submitted
|
||||||
expect(screen.getByTestId('escalationEmailError')).toBeDefined();
|
expect(screen.getByTestId('escalationEmailError')).toBeDefined();
|
||||||
});
|
});
|
||||||
@@ -423,16 +458,6 @@ describe('ProctoredExamSettings', () => {
|
|||||||
expect(providerOption.hasAttribute('disabled')).toEqual(false);
|
expect(providerOption.hasAttribute('disabled')).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Sends the org to the proctoring provider endpoint', async () => {
|
|
||||||
const isAdmin = false;
|
|
||||||
const org = 'test-org';
|
|
||||||
setupApp(isAdmin, org);
|
|
||||||
mockCourseData(mockGetFutureCourseData);
|
|
||||||
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
|
||||||
const providerOption = screen.getByTestId('proctortrack');
|
|
||||||
expect(providerOption.hasAttribute('disabled')).toEqual(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Enables all proctoring provider options if user administrator and it is after start date', async () => {
|
it('Enables all proctoring provider options if user administrator and it is after start date', async () => {
|
||||||
const isAdmin = true;
|
const isAdmin = true;
|
||||||
setupApp(isAdmin);
|
setupApp(isAdmin);
|
||||||
@@ -544,9 +569,12 @@ describe('ProctoredExamSettings', () => {
|
|||||||
|
|
||||||
describe('Connection states', () => {
|
describe('Connection states', () => {
|
||||||
it('Shows the spinner before the connection is complete', async () => {
|
it('Shows the spinner before the connection is complete', async () => {
|
||||||
render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />));
|
await act(async () => {
|
||||||
const spinner = await screen.findByRole('status');
|
render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />));
|
||||||
expect(spinner.textContent).toEqual('Loading...');
|
// This expectation is _inside_ the `act` intentionally, so that it executes immediately.
|
||||||
|
const spinner = screen.getByRole('status');
|
||||||
|
expect(spinner.textContent).toEqual('Loading...');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Show connection error message when we suffer studio server side error', async () => {
|
it('Show connection error message when we suffer studio server side error', async () => {
|
||||||
@@ -600,7 +628,9 @@ describe('ProctoredExamSettings', () => {
|
|||||||
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
||||||
let submitButton = screen.getByTestId('submissionButton');
|
let submitButton = screen.getByTestId('submissionButton');
|
||||||
expect(screen.queryByTestId('saveInProgress')).toBeFalsy();
|
expect(screen.queryByTestId('saveInProgress')).toBeFalsy();
|
||||||
fireEvent.click(submitButton);
|
act(() => {
|
||||||
|
fireEvent.click(submitButton);
|
||||||
|
});
|
||||||
|
|
||||||
submitButton = screen.getByTestId('submissionButton');
|
submitButton = screen.getByTestId('submissionButton');
|
||||||
expect(submitButton).toHaveAttribute('disabled');
|
expect(submitButton).toHaveAttribute('disabled');
|
||||||
@@ -610,13 +640,19 @@ describe('ProctoredExamSettings', () => {
|
|||||||
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
||||||
// Make a change to the provider to proctortrack and set the email
|
// Make a change to the provider to proctortrack and set the email
|
||||||
const selectElement = screen.getByDisplayValue('mockproc');
|
const selectElement = screen.getByDisplayValue('mockproc');
|
||||||
fireEvent.change(selectElement, { target: { value: 'proctortrack' } });
|
await act(async () => {
|
||||||
|
fireEvent.change(selectElement, { target: { value: 'proctortrack' } });
|
||||||
|
});
|
||||||
const escalationEmail = screen.getByTestId('escalationEmail');
|
const escalationEmail = screen.getByTestId('escalationEmail');
|
||||||
expect(escalationEmail.value).toEqual('test@example.com');
|
expect(escalationEmail.value).toEqual('test@example.com');
|
||||||
fireEvent.change(escalationEmail, { target: { value: 'proctortrack@example.com' } });
|
await act(async () => {
|
||||||
|
fireEvent.change(escalationEmail, { target: { value: 'proctortrack@example.com' } });
|
||||||
|
});
|
||||||
expect(escalationEmail.value).toEqual('proctortrack@example.com');
|
expect(escalationEmail.value).toEqual('proctortrack@example.com');
|
||||||
const submitButton = screen.getByTestId('submissionButton');
|
const submitButton = screen.getByTestId('submissionButton');
|
||||||
fireEvent.click(submitButton);
|
await act(async () => {
|
||||||
|
fireEvent.click(submitButton);
|
||||||
|
});
|
||||||
expect(axiosMock.history.post.length).toBe(1);
|
expect(axiosMock.history.post.length).toBe(1);
|
||||||
expect(JSON.parse(axiosMock.history.post[0].data)).toEqual({
|
expect(JSON.parse(axiosMock.history.post[0].data)).toEqual({
|
||||||
proctored_exam_settings: {
|
proctored_exam_settings: {
|
||||||
@@ -628,13 +664,11 @@ describe('ProctoredExamSettings', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await waitFor(() => {
|
const errorAlert = screen.getByTestId('saveSuccess');
|
||||||
const errorAlert = screen.getByTestId('saveSuccess');
|
expect(errorAlert.textContent).toEqual(
|
||||||
expect(errorAlert.textContent).toEqual(
|
expect.stringContaining('Proctored exam settings saved successfully.'),
|
||||||
expect.stringContaining('Proctored exam settings saved successfully.'),
|
);
|
||||||
);
|
expect(document.activeElement).toEqual(errorAlert);
|
||||||
expect(document.activeElement).toEqual(errorAlert);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Makes API call successfully without proctoring_escalation_email if not proctortrack', async () => {
|
it('Makes API call successfully without proctoring_escalation_email if not proctortrack', async () => {
|
||||||
@@ -644,7 +678,9 @@ describe('ProctoredExamSettings', () => {
|
|||||||
expect(screen.getByDisplayValue('mockproc')).toBeDefined();
|
expect(screen.getByDisplayValue('mockproc')).toBeDefined();
|
||||||
|
|
||||||
const submitButton = screen.getByTestId('submissionButton');
|
const submitButton = screen.getByTestId('submissionButton');
|
||||||
fireEvent.click(submitButton);
|
await act(async () => {
|
||||||
|
fireEvent.click(submitButton);
|
||||||
|
});
|
||||||
expect(axiosMock.history.post.length).toBe(1);
|
expect(axiosMock.history.post.length).toBe(1);
|
||||||
expect(JSON.parse(axiosMock.history.post[0].data)).toEqual({
|
expect(JSON.parse(axiosMock.history.post[0].data)).toEqual({
|
||||||
proctored_exam_settings: {
|
proctored_exam_settings: {
|
||||||
@@ -655,28 +691,32 @@ describe('ProctoredExamSettings', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await waitFor(() => {
|
const errorAlert = screen.getByTestId('saveSuccess');
|
||||||
const errorAlert = screen.getByTestId('saveSuccess');
|
expect(errorAlert.textContent).toEqual(
|
||||||
expect(errorAlert.textContent).toEqual(
|
expect.stringContaining('Proctored exam settings saved successfully.'),
|
||||||
expect.stringContaining('Proctored exam settings saved successfully.'),
|
);
|
||||||
);
|
expect(document.activeElement).toEqual(errorAlert);
|
||||||
expect(document.activeElement).toEqual(errorAlert);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Successfully updates exam configuration and studio provider is set to "lti_external" for lti providers', async () => {
|
it('Successfully updates exam configuration and studio provider is set to "lti_external" for lti providers', async () => {
|
||||||
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
||||||
// Make a change to the provider to test_lti and set the email
|
// Make a change to the provider to test_lti and set the email
|
||||||
const selectElement = screen.getByDisplayValue('mockproc');
|
const selectElement = screen.getByDisplayValue('mockproc');
|
||||||
fireEvent.change(selectElement, { target: { value: 'test_lti' } });
|
await act(async () => {
|
||||||
|
fireEvent.change(selectElement, { target: { value: 'test_lti' } });
|
||||||
|
});
|
||||||
|
|
||||||
const escalationEmail = screen.getByTestId('escalationEmail');
|
const escalationEmail = screen.getByTestId('escalationEmail');
|
||||||
expect(escalationEmail.value).toEqual('test@example.com');
|
expect(escalationEmail.value).toEqual('test@example.com');
|
||||||
fireEvent.change(escalationEmail, { target: { value: 'test_lti@example.com' } });
|
await act(async () => {
|
||||||
|
fireEvent.change(escalationEmail, { target: { value: 'test_lti@example.com' } });
|
||||||
|
});
|
||||||
expect(escalationEmail.value).toEqual('test_lti@example.com');
|
expect(escalationEmail.value).toEqual('test_lti@example.com');
|
||||||
|
|
||||||
const submitButton = screen.getByTestId('submissionButton');
|
const submitButton = screen.getByTestId('submissionButton');
|
||||||
fireEvent.click(submitButton);
|
await act(async () => {
|
||||||
|
fireEvent.click(submitButton);
|
||||||
|
});
|
||||||
|
|
||||||
// update exam service config
|
// update exam service config
|
||||||
expect(axiosMock.history.patch.length).toBe(1);
|
expect(axiosMock.history.patch.length).toBe(1);
|
||||||
@@ -696,19 +736,19 @@ describe('ProctoredExamSettings', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await waitFor(() => {
|
const errorAlert = screen.getByTestId('saveSuccess');
|
||||||
const errorAlert = screen.getByTestId('saveSuccess');
|
expect(errorAlert.textContent).toEqual(
|
||||||
expect(errorAlert.textContent).toEqual(
|
expect.stringContaining('Proctored exam settings saved successfully.'),
|
||||||
expect.stringContaining('Proctored exam settings saved successfully.'),
|
);
|
||||||
);
|
expect(document.activeElement).toEqual(errorAlert);
|
||||||
expect(document.activeElement).toEqual(errorAlert);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Sets exam service provider to null if a non-lti provider is selected', async () => {
|
it('Sets exam service provider to null if a non-lti provider is selected', async () => {
|
||||||
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
||||||
const submitButton = screen.getByTestId('submissionButton');
|
const submitButton = screen.getByTestId('submissionButton');
|
||||||
fireEvent.click(submitButton);
|
await act(async () => {
|
||||||
|
fireEvent.click(submitButton);
|
||||||
|
});
|
||||||
// update exam service config
|
// update exam service config
|
||||||
expect(axiosMock.history.patch.length).toBe(1);
|
expect(axiosMock.history.patch.length).toBe(1);
|
||||||
expect(JSON.parse(axiosMock.history.patch[0].data)).toEqual({
|
expect(JSON.parse(axiosMock.history.patch[0].data)).toEqual({
|
||||||
@@ -726,13 +766,11 @@ describe('ProctoredExamSettings', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await waitFor(() => {
|
const errorAlert = screen.getByTestId('saveSuccess');
|
||||||
const errorAlert = screen.getByTestId('saveSuccess');
|
expect(errorAlert.textContent).toEqual(
|
||||||
expect(errorAlert.textContent).toEqual(
|
expect.stringContaining('Proctored exam settings saved successfully.'),
|
||||||
expect.stringContaining('Proctored exam settings saved successfully.'),
|
);
|
||||||
);
|
expect(document.activeElement).toEqual(errorAlert);
|
||||||
expect(document.activeElement).toEqual(errorAlert);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Does not update exam service if lti is not enabled in studio', async () => {
|
it('Does not update exam service if lti is not enabled in studio', async () => {
|
||||||
@@ -752,7 +790,9 @@ describe('ProctoredExamSettings', () => {
|
|||||||
|
|
||||||
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
||||||
const submitButton = screen.getByTestId('submissionButton');
|
const submitButton = screen.getByTestId('submissionButton');
|
||||||
fireEvent.click(submitButton);
|
await act(async () => {
|
||||||
|
fireEvent.click(submitButton);
|
||||||
|
});
|
||||||
// does not update exam service config
|
// does not update exam service config
|
||||||
expect(axiosMock.history.patch.length).toBe(0);
|
expect(axiosMock.history.patch.length).toBe(0);
|
||||||
// does update studio
|
// does update studio
|
||||||
@@ -766,13 +806,11 @@ describe('ProctoredExamSettings', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await waitFor(() => {
|
const errorAlert = screen.getByTestId('saveSuccess');
|
||||||
const errorAlert = screen.getByTestId('saveSuccess');
|
expect(errorAlert.textContent).toEqual(
|
||||||
expect(errorAlert.textContent).toEqual(
|
expect.stringContaining('Proctored exam settings saved successfully.'),
|
||||||
expect.stringContaining('Proctored exam settings saved successfully.'),
|
);
|
||||||
);
|
expect(document.activeElement).toEqual(errorAlert);
|
||||||
expect(document.activeElement).toEqual(errorAlert);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Makes studio API call generated error', async () => {
|
it('Makes studio API call generated error', async () => {
|
||||||
@@ -782,15 +820,15 @@ describe('ProctoredExamSettings', () => {
|
|||||||
|
|
||||||
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
||||||
const submitButton = screen.getByTestId('submissionButton');
|
const submitButton = screen.getByTestId('submissionButton');
|
||||||
fireEvent.click(submitButton);
|
await act(async () => {
|
||||||
expect(axiosMock.history.post.length).toBe(1);
|
fireEvent.click(submitButton);
|
||||||
await waitFor(() => {
|
|
||||||
const errorAlert = screen.getByTestId('saveError');
|
|
||||||
expect(errorAlert.textContent).toEqual(
|
|
||||||
expect.stringContaining('We encountered a technical error while trying to save proctored exam settings'),
|
|
||||||
);
|
|
||||||
expect(document.activeElement).toEqual(errorAlert);
|
|
||||||
});
|
});
|
||||||
|
expect(axiosMock.history.post.length).toBe(1);
|
||||||
|
const errorAlert = screen.getByTestId('saveError');
|
||||||
|
expect(errorAlert.textContent).toEqual(
|
||||||
|
expect.stringContaining('We encountered a technical error while trying to save proctored exam settings'),
|
||||||
|
);
|
||||||
|
expect(document.activeElement).toEqual(errorAlert);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Makes exams API call generated error', async () => {
|
it('Makes exams API call generated error', async () => {
|
||||||
@@ -800,33 +838,15 @@ describe('ProctoredExamSettings', () => {
|
|||||||
|
|
||||||
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
||||||
const submitButton = screen.getByTestId('submissionButton');
|
const submitButton = screen.getByTestId('submissionButton');
|
||||||
fireEvent.click(submitButton);
|
await act(async () => {
|
||||||
expect(axiosMock.history.post.length).toBe(1);
|
fireEvent.click(submitButton);
|
||||||
await waitFor(() => {
|
|
||||||
const errorAlert = screen.getByTestId('saveError');
|
|
||||||
expect(errorAlert.textContent).toEqual(
|
|
||||||
expect.stringContaining('We encountered a technical error while trying to save proctored exam settings'),
|
|
||||||
);
|
|
||||||
expect(document.activeElement).toEqual(errorAlert);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
test('Exams API permission error', async () => {
|
|
||||||
axiosMock.onPatch(
|
|
||||||
`${ExamsApiService.getExamsBaseUrl()}/api/v1/configs/course_id/${defaultProps.courseId}`,
|
|
||||||
).reply(403, 'error');
|
|
||||||
|
|
||||||
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
|
||||||
const submitButton = screen.getByTestId('submissionButton');
|
|
||||||
fireEvent.click(submitButton);
|
|
||||||
expect(axiosMock.history.post.length).toBe(1);
|
expect(axiosMock.history.post.length).toBe(1);
|
||||||
await waitFor(() => {
|
const errorAlert = screen.getByTestId('saveError');
|
||||||
const errorAlert = screen.getByTestId('saveError');
|
expect(errorAlert.textContent).toEqual(
|
||||||
expect(errorAlert.textContent).toEqual(
|
expect.stringContaining('We encountered a technical error while trying to save proctored exam settings'),
|
||||||
expect.stringContaining('You do not have permission to edit proctored exam settings for this course'),
|
);
|
||||||
);
|
expect(document.activeElement).toEqual(errorAlert);
|
||||||
expect(document.activeElement).toEqual(errorAlert);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Manages focus correctly after different save statuses', async () => {
|
it('Manages focus correctly after different save statuses', async () => {
|
||||||
@@ -837,30 +857,30 @@ describe('ProctoredExamSettings', () => {
|
|||||||
|
|
||||||
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
||||||
const submitButton = screen.getByTestId('submissionButton');
|
const submitButton = screen.getByTestId('submissionButton');
|
||||||
fireEvent.click(submitButton);
|
await act(async () => {
|
||||||
expect(axiosMock.history.post.length).toBe(1);
|
fireEvent.click(submitButton);
|
||||||
await waitFor(() => {
|
|
||||||
const errorAlert = screen.getByTestId('saveError');
|
|
||||||
expect(errorAlert.textContent).toEqual(
|
|
||||||
expect.stringContaining('We encountered a technical error while trying to save proctored exam settings'),
|
|
||||||
);
|
|
||||||
expect(document.activeElement).toEqual(errorAlert);
|
|
||||||
});
|
});
|
||||||
|
expect(axiosMock.history.post.length).toBe(1);
|
||||||
|
const errorAlert = screen.getByTestId('saveError');
|
||||||
|
expect(errorAlert.textContent).toEqual(
|
||||||
|
expect.stringContaining('We encountered a technical error while trying to save proctored exam settings'),
|
||||||
|
);
|
||||||
|
expect(document.activeElement).toEqual(errorAlert);
|
||||||
|
|
||||||
// now make a call that will allow for a successful save
|
// now make a call that will allow for a successful save
|
||||||
axiosMock.onPost(
|
axiosMock.onPost(
|
||||||
StudioApiService.getProctoredExamSettingsUrl(defaultProps.courseId),
|
StudioApiService.getProctoredExamSettingsUrl(defaultProps.courseId),
|
||||||
).reply(200, 'success');
|
).reply(200, 'success');
|
||||||
fireEvent.click(submitButton);
|
await act(async () => {
|
||||||
|
fireEvent.click(submitButton);
|
||||||
|
});
|
||||||
|
|
||||||
expect(axiosMock.history.post.length).toBe(2);
|
expect(axiosMock.history.post.length).toBe(2);
|
||||||
await waitFor(() => {
|
const successAlert = screen.getByTestId('saveSuccess');
|
||||||
const successAlert = screen.getByTestId('saveSuccess');
|
expect(successAlert.textContent).toEqual(
|
||||||
expect(successAlert.textContent).toEqual(
|
expect.stringContaining('Proctored exam settings saved successfully.'),
|
||||||
expect.stringContaining('Proctored exam settings saved successfully.'),
|
);
|
||||||
);
|
expect(document.activeElement).toEqual(successAlert);
|
||||||
expect(document.activeElement).toEqual(successAlert);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Include Zendesk ticket in post request if user is not an admin', async () => {
|
it('Include Zendesk ticket in post request if user is not an admin', async () => {
|
||||||
@@ -871,9 +891,13 @@ describe('ProctoredExamSettings', () => {
|
|||||||
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
await act(async () => render(intlWrapper(<IntlProctoredExamSettings {...defaultProps} />)));
|
||||||
// Make a change to the proctoring provider
|
// Make a change to the proctoring provider
|
||||||
const selectElement = screen.getByDisplayValue('mockproc');
|
const selectElement = screen.getByDisplayValue('mockproc');
|
||||||
fireEvent.change(selectElement, { target: { value: 'proctortrack' } });
|
await act(async () => {
|
||||||
|
fireEvent.change(selectElement, { target: { value: 'proctortrack' } });
|
||||||
|
});
|
||||||
const submitButton = screen.getByTestId('submissionButton');
|
const submitButton = screen.getByTestId('submissionButton');
|
||||||
fireEvent.click(submitButton);
|
await act(async () => {
|
||||||
|
fireEvent.click(submitButton);
|
||||||
|
});
|
||||||
expect(axiosMock.history.post.length).toBe(1);
|
expect(axiosMock.history.post.length).toBe(1);
|
||||||
expect(JSON.parse(axiosMock.history.post[0].data)).toEqual({
|
expect(JSON.parse(axiosMock.history.post[0].data)).toEqual({
|
||||||
proctored_exam_settings: {
|
proctored_exam_settings: {
|
||||||
|
|||||||
@@ -1,16 +1,6 @@
|
|||||||
import { defineMessages } from '@edx/frontend-platform/i18n';
|
import { defineMessages } from '@edx/frontend-platform/i18n';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
'authoring.proctoring.alert.error': {
|
|
||||||
id: 'authoring.proctoring.alert.error',
|
|
||||||
defaultMessage: 'We encountered a technical error while trying to save proctored exam settings. This might be a temporary issue, so please try again in a few minutes. If the problem persists, please go to the {support_link} for help.',
|
|
||||||
description: 'Alert message for proctoring settings save error.',
|
|
||||||
},
|
|
||||||
'authoring.proctoring.alert.forbidden': {
|
|
||||||
id: 'authoring.proctoring.alert.forbidden',
|
|
||||||
defaultMessage: 'You do not have permission to edit proctored exam settings for this course. If you are a course team member and this problem persists, please go to the {support_link} for help.',
|
|
||||||
description: 'Alert message for proctoring settings permission error.',
|
|
||||||
},
|
|
||||||
'authoring.proctoring.no': {
|
'authoring.proctoring.no': {
|
||||||
id: 'authoring.proctoring.no',
|
id: 'authoring.proctoring.no',
|
||||||
defaultMessage: 'No',
|
defaultMessage: 'No',
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Proctoring configuration for courses using it",
|
"description": "Proctoring configuration for courses using it",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@edx/frontend-app-authoring": "*",
|
"@edx/frontend-app-course-authoring": "*",
|
||||||
"@edx/frontend-platform": "*",
|
"@edx/frontend-platform": "*",
|
||||||
"@openedx/paragon": "*",
|
"@openedx/paragon": "*",
|
||||||
"classnames": "*",
|
"classnames": "*",
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
"moment": "*"
|
"moment": "*"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"@edx/frontend-app-authoring": {
|
"@edx/frontend-app-course-authoring": {
|
||||||
"optional": true
|
"optional": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Progress configuration for courses using it",
|
"description": "Progress configuration for courses using it",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@edx/frontend-app-authoring": "*",
|
"@edx/frontend-app-course-authoring": "*",
|
||||||
"@edx/frontend-platform": "*",
|
"@edx/frontend-platform": "*",
|
||||||
"@openedx/paragon": "*",
|
"@openedx/paragon": "*",
|
||||||
"prop-types": "*",
|
"prop-types": "*",
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
"yup": "*"
|
"yup": "*"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"@edx/frontend-app-authoring": {
|
"@edx/frontend-app-course-authoring": {
|
||||||
"optional": true
|
"optional": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ const TeamSettings = ({
|
|||||||
description: '',
|
description: '',
|
||||||
type: GroupTypes.OPEN,
|
type: GroupTypes.OPEN,
|
||||||
maxTeamSize: null,
|
maxTeamSize: null,
|
||||||
userPartitionId: null,
|
|
||||||
id: null,
|
id: null,
|
||||||
key: uuid(),
|
key: uuid(),
|
||||||
};
|
};
|
||||||
@@ -39,7 +38,6 @@ const TeamSettings = ({
|
|||||||
type: group.type,
|
type: group.type,
|
||||||
description: group.description,
|
description: group.description,
|
||||||
max_team_size: group.maxTeamSize,
|
max_team_size: group.maxTeamSize,
|
||||||
user_partition_id: group.userPartitionId,
|
|
||||||
}));
|
}));
|
||||||
return saveSettings({
|
return saveSettings({
|
||||||
team_sets: groups,
|
team_sets: groups,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Teams configuration for courses using it",
|
"description": "Teams configuration for courses using it",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@edx/frontend-app-authoring": "*",
|
"@edx/frontend-app-course-authoring": "*",
|
||||||
"@edx/frontend-platform": "*",
|
"@edx/frontend-platform": "*",
|
||||||
"@openedx/paragon": "*",
|
"@openedx/paragon": "*",
|
||||||
"formik": "*",
|
"formik": "*",
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
"yup": "*"
|
"yup": "*"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"@edx/frontend-app-authoring": {
|
"@edx/frontend-app-course-authoring": {
|
||||||
"optional": true
|
"optional": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable import/prefer-default-export */
|
||||||
import { getConfig } from '@edx/frontend-platform';
|
import { getConfig } from '@edx/frontend-platform';
|
||||||
|
|
||||||
import { GroupTypes } from 'CourseAuthoring/data/constants';
|
import { GroupTypes } from 'CourseAuthoring/data/constants';
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ const messages = defineMessages({
|
|||||||
},
|
},
|
||||||
enablePublicWikiHelp: {
|
enablePublicWikiHelp: {
|
||||||
id: 'course-authoring.pages-resources.wiki.enable-public-wiki.help',
|
id: 'course-authoring.pages-resources.wiki.enable-public-wiki.help',
|
||||||
defaultMessage: `If enabled, any registered user can view the course wiki
|
defaultMessage: `If enabled, edX users can view the course wiki even when
|
||||||
even if they are not enrolled in the course`,
|
they're not enrolled in the course.`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Wiki configuration for courses using it",
|
"description": "Wiki configuration for courses using it",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@edx/frontend-app-authoring": "*",
|
"@edx/frontend-app-course-authoring": "*",
|
||||||
"@edx/frontend-platform": "*",
|
"@edx/frontend-platform": "*",
|
||||||
"@openedx/paragon": "*",
|
"@openedx/paragon": "*",
|
||||||
"prop-types": "*",
|
"prop-types": "*",
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
"yup": "*"
|
"yup": "*"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"@edx/frontend-app-authoring": {
|
"@edx/frontend-app-course-authoring": {
|
||||||
"optional": true
|
"optional": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
||||||
import { AppProvider, PageWrap } from '@edx/frontend-platform/react';
|
import { AppProvider, PageWrap } from '@edx/frontend-platform/react';
|
||||||
import {
|
import {
|
||||||
findByTestId, queryByTestId, render, waitFor, getByText, fireEvent,
|
queryByTestId, render, waitFor, getByText, fireEvent,
|
||||||
} from '@testing-library/react';
|
} from '@testing-library/react';
|
||||||
import MockAdapter from 'axios-mock-adapter';
|
import MockAdapter from 'axios-mock-adapter';
|
||||||
import PagesAndResourcesProvider from 'CourseAuthoring/pages-and-resources/PagesAndResourcesProvider';
|
import PagesAndResourcesProvider from 'CourseAuthoring/pages-and-resources/PagesAndResourcesProvider';
|
||||||
@@ -106,9 +106,8 @@ describe('XpertUnitSummarySettings', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Shows switch on if enabled from backend', async () => {
|
test('Shows switch on if enabled from backend', async () => {
|
||||||
const enableBadge = await findByTestId(container, 'enable-badge');
|
|
||||||
expect(container.querySelector('#enable-xpert-unit-summary-toggle').checked).toBeTruthy();
|
expect(container.querySelector('#enable-xpert-unit-summary-toggle').checked).toBeTruthy();
|
||||||
expect(enableBadge).toBeTruthy();
|
expect(queryByTestId(container, 'enable-badge')).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Shows switch on if disabled from backend', async () => {
|
test('Shows switch on if disabled from backend', async () => {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Xpert Unit Summaries configuration for courses using it",
|
"description": "Xpert Unit Summaries configuration for courses using it",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@edx/frontend-app-authoring": "*",
|
"@edx/frontend-app-course-authoring": "*",
|
||||||
"@edx/frontend-platform": "*",
|
"@edx/frontend-platform": "*",
|
||||||
"@openedx/paragon": "*",
|
"@openedx/paragon": "*",
|
||||||
"formik": "*",
|
"formik": "*",
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
"react-router-dom": "*"
|
"react-router-dom": "*"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"@edx/frontend-app-authoring": {
|
"@edx/frontend-app-course-authoring": {
|
||||||
"optional": true
|
"optional": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,12 +137,12 @@ const ResetUnitsButton = ({
|
|||||||
|
|
||||||
const getResetButtonState = () => {
|
const getResetButtonState = () => {
|
||||||
switch (resetStatusRequestStatus) {
|
switch (resetStatusRequestStatus) {
|
||||||
case RequestStatus.PENDING:
|
case RequestStatus.PENDING:
|
||||||
return 'pending';
|
return 'pending';
|
||||||
case RequestStatus.SUCCESSFUL:
|
case RequestStatus.SUCCESSFUL:
|
||||||
return 'finish';
|
return 'finish';
|
||||||
default:
|
default:
|
||||||
return 'default';
|
return 'default';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -246,7 +246,7 @@ const SettingsModal = ({
|
|||||||
success = success && await onSettingsSave(values);
|
success = success && await onSettingsSave(values);
|
||||||
}
|
}
|
||||||
setSaveError(!success);
|
setSaveError(!success);
|
||||||
!success && alertRef?.current.scrollIntoView(); // eslint-disable-line @typescript-eslint/no-unused-expressions
|
!success && alertRef?.current.scrollIntoView(); // eslint-disable-line no-unused-expressions
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleFormikSubmit = ({ handleSubmit, errors }) => async (event) => {
|
const handleFormikSubmit = ({ handleSubmit, errors }) => async (event) => {
|
||||||
|
|||||||
@@ -19,6 +19,15 @@
|
|||||||
"matchPackagePatterns": ["@edx", "@openedx"],
|
"matchPackagePatterns": ["@edx", "@openedx"],
|
||||||
"matchUpdateTypes": ["minor", "patch"],
|
"matchUpdateTypes": ["minor", "patch"],
|
||||||
"automerge": false
|
"automerge": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"matchPackagePatterns": ["@edx/frontend-lib-content-components"],
|
||||||
|
"matchUpdateTypes": ["minor", "patch"],
|
||||||
|
"automerge": false,
|
||||||
|
"schedule": [
|
||||||
|
"after 1am",
|
||||||
|
"before 11pm"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,29 +5,46 @@ import { useDispatch, useSelector } from 'react-redux';
|
|||||||
import {
|
import {
|
||||||
useLocation,
|
useLocation,
|
||||||
} from 'react-router-dom';
|
} from 'react-router-dom';
|
||||||
import { StudioFooterSlot } from '@openedx/frontend-slot-footer';
|
import { StudioFooter } from '@edx/frontend-component-footer';
|
||||||
import Header from './header';
|
import Header from './header';
|
||||||
import { fetchCourseDetail, fetchWaffleFlags } from './data/thunks';
|
import { fetchCourseDetail } from './data/thunks';
|
||||||
import { useModel } from './generic/model-store';
|
import { useModel } from './generic/model-store';
|
||||||
import NotFoundAlert from './generic/NotFoundAlert';
|
import NotFoundAlert from './generic/NotFoundAlert';
|
||||||
import PermissionDeniedAlert from './generic/PermissionDeniedAlert';
|
import PermissionDeniedAlert from './generic/PermissionDeniedAlert';
|
||||||
import { fetchOnlyStudioHomeData } from './studio-home/data/thunks';
|
|
||||||
import { getCourseAppsApiStatus } from './pages-and-resources/data/selectors';
|
import { getCourseAppsApiStatus } from './pages-and-resources/data/selectors';
|
||||||
import { RequestStatus } from './data/constants';
|
import { RequestStatus } from './data/constants';
|
||||||
import Loading from './generic/Loading';
|
import Loading from './generic/Loading';
|
||||||
|
|
||||||
|
const AppHeader = ({
|
||||||
|
courseNumber, courseOrg, courseTitle, courseId,
|
||||||
|
}) => (
|
||||||
|
<Header
|
||||||
|
courseNumber={courseNumber}
|
||||||
|
courseOrg={courseOrg}
|
||||||
|
courseTitle={courseTitle}
|
||||||
|
courseId={courseId}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
AppHeader.propTypes = {
|
||||||
|
courseId: PropTypes.string.isRequired,
|
||||||
|
courseNumber: PropTypes.string,
|
||||||
|
courseOrg: PropTypes.string,
|
||||||
|
courseTitle: PropTypes.string.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
AppHeader.defaultProps = {
|
||||||
|
courseNumber: null,
|
||||||
|
courseOrg: null,
|
||||||
|
};
|
||||||
|
|
||||||
const CourseAuthoringPage = ({ courseId, children }) => {
|
const CourseAuthoringPage = ({ courseId, children }) => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(fetchCourseDetail(courseId));
|
dispatch(fetchCourseDetail(courseId));
|
||||||
dispatch(fetchWaffleFlags(courseId));
|
|
||||||
}, [courseId]);
|
}, [courseId]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
dispatch(fetchOnlyStudioHomeData());
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const courseDetail = useModel('courseDetails', courseId);
|
const courseDetail = useModel('courseDetails', courseId);
|
||||||
|
|
||||||
const courseNumber = courseDetail ? courseDetail.number : null;
|
const courseNumber = courseDetail ? courseDetail.number : null;
|
||||||
@@ -50,23 +67,23 @@ const CourseAuthoringPage = ({ courseId, children }) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className={pathname.includes('/editor/') ? '' : 'bg-light-200'}>
|
||||||
{/* While V2 Editors are temporarily served from their own pages
|
{/* While V2 Editors are temporarily served from their own pages
|
||||||
using url pattern containing /editor/,
|
using url pattern containing /editor/,
|
||||||
we shouldn't have the header and footer on these pages.
|
we shouldn't have the header and footer on these pages.
|
||||||
This functionality will be removed in TNL-9591 */}
|
This functionality will be removed in TNL-9591 */}
|
||||||
{inProgress ? !isEditor && <Loading />
|
{inProgress ? !isEditor && <Loading />
|
||||||
: (!isEditor && (
|
: (!isEditor && (
|
||||||
<Header
|
<AppHeader
|
||||||
number={courseNumber}
|
courseNumber={courseNumber}
|
||||||
org={courseOrg}
|
courseOrg={courseOrg}
|
||||||
title={courseTitle}
|
courseTitle={courseTitle}
|
||||||
contextId={courseId}
|
courseId={courseId}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
{children}
|
{children}
|
||||||
{!inProgress && !isEditor && <StudioFooterSlot />}
|
{!inProgress && !isEditor && <StudioFooter />}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
import { getConfig } from '@edx/frontend-platform';
|
import React from 'react';
|
||||||
|
|
||||||
|
import { render } from '@testing-library/react';
|
||||||
|
|
||||||
|
import { getConfig, initializeMockApp } from '@edx/frontend-platform';
|
||||||
|
import MockAdapter from 'axios-mock-adapter';
|
||||||
|
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
||||||
|
import { AppProvider } from '@edx/frontend-platform/react';
|
||||||
|
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||||
|
import initializeStore from './store';
|
||||||
import CourseAuthoringPage from './CourseAuthoringPage';
|
import CourseAuthoringPage from './CourseAuthoringPage';
|
||||||
import PagesAndResources from './pages-and-resources/PagesAndResources';
|
import PagesAndResources from './pages-and-resources/PagesAndResources';
|
||||||
import { executeThunk } from './utils';
|
import { executeThunk } from './utils';
|
||||||
import { fetchCourseApps } from './pages-and-resources/data/thunks';
|
import { fetchCourseApps } from './pages-and-resources/data/thunks';
|
||||||
import { fetchCourseDetail, fetchWaffleFlags } from './data/thunks';
|
import { fetchCourseDetail } from './data/thunks';
|
||||||
import { getApiWaffleFlagsUrl } from './data/api';
|
|
||||||
import { initializeMocks, render } from './testUtils';
|
|
||||||
|
|
||||||
const courseId = 'course-v1:edX+TestX+Test_Course';
|
const courseId = 'course-v1:edX+TestX+Test_Course';
|
||||||
let mockPathname = '/evilguy/';
|
let mockPathname = '/evilguy/';
|
||||||
@@ -19,14 +25,17 @@ jest.mock('react-router-dom', () => ({
|
|||||||
let axiosMock;
|
let axiosMock;
|
||||||
let store;
|
let store;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(() => {
|
||||||
const mocks = initializeMocks();
|
initializeMockApp({
|
||||||
store = mocks.reduxStore;
|
authenticatedUser: {
|
||||||
axiosMock = mocks.axiosMock;
|
userId: 3,
|
||||||
axiosMock
|
username: 'abc123',
|
||||||
.onGet(getApiWaffleFlagsUrl(courseId))
|
administrator: true,
|
||||||
.reply(200, {});
|
roles: [],
|
||||||
await executeThunk(fetchWaffleFlags(courseId), store.dispatch);
|
},
|
||||||
|
});
|
||||||
|
store = initializeStore();
|
||||||
|
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Editor Pages Load no header', () => {
|
describe('Editor Pages Load no header', () => {
|
||||||
@@ -42,9 +51,13 @@ describe('Editor Pages Load no header', () => {
|
|||||||
mockPathname = '/editor/';
|
mockPathname = '/editor/';
|
||||||
await mockStoreSuccess();
|
await mockStoreSuccess();
|
||||||
const wrapper = render(
|
const wrapper = render(
|
||||||
<CourseAuthoringPage courseId={courseId}>
|
<AppProvider store={store}>
|
||||||
<PagesAndResources courseId={courseId} />
|
<IntlProvider locale="en">
|
||||||
</CourseAuthoringPage>
|
<CourseAuthoringPage courseId={courseId}>
|
||||||
|
<PagesAndResources courseId={courseId} />
|
||||||
|
</CourseAuthoringPage>
|
||||||
|
</IntlProvider>
|
||||||
|
</AppProvider>
|
||||||
,
|
,
|
||||||
);
|
);
|
||||||
expect(wrapper.queryByRole('status')).not.toBeInTheDocument();
|
expect(wrapper.queryByRole('status')).not.toBeInTheDocument();
|
||||||
@@ -53,9 +66,13 @@ describe('Editor Pages Load no header', () => {
|
|||||||
mockPathname = '/evilguy/';
|
mockPathname = '/evilguy/';
|
||||||
await mockStoreSuccess();
|
await mockStoreSuccess();
|
||||||
const wrapper = render(
|
const wrapper = render(
|
||||||
<CourseAuthoringPage courseId={courseId}>
|
<AppProvider store={store}>
|
||||||
<PagesAndResources courseId={courseId} />
|
<IntlProvider locale="en">
|
||||||
</CourseAuthoringPage>
|
<CourseAuthoringPage courseId={courseId}>
|
||||||
|
<PagesAndResources courseId={courseId} />
|
||||||
|
</CourseAuthoringPage>
|
||||||
|
</IntlProvider>
|
||||||
|
</AppProvider>
|
||||||
,
|
,
|
||||||
);
|
);
|
||||||
expect(wrapper.queryByRole('status')).toBeInTheDocument();
|
expect(wrapper.queryByRole('status')).toBeInTheDocument();
|
||||||
@@ -83,7 +100,14 @@ describe('Course authoring page', () => {
|
|||||||
};
|
};
|
||||||
test('renders not found page on non-existent course key', async () => {
|
test('renders not found page on non-existent course key', async () => {
|
||||||
await mockStoreNotFound();
|
await mockStoreNotFound();
|
||||||
const wrapper = render(<CourseAuthoringPage courseId={courseId} />);
|
const wrapper = render(
|
||||||
|
<AppProvider store={store}>
|
||||||
|
<IntlProvider locale="en">
|
||||||
|
<CourseAuthoringPage courseId={courseId} />
|
||||||
|
</IntlProvider>
|
||||||
|
</AppProvider>
|
||||||
|
,
|
||||||
|
);
|
||||||
expect(await wrapper.findByTestId('notFoundAlert')).toBeInTheDocument();
|
expect(await wrapper.findByTestId('notFoundAlert')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
test('does not render not found page on other kinds of error', async () => {
|
test('does not render not found page on other kinds of error', async () => {
|
||||||
@@ -94,9 +118,13 @@ describe('Course authoring page', () => {
|
|||||||
// found alert is not present.
|
// found alert is not present.
|
||||||
const contentTestId = 'courseAuthoringPageContent';
|
const contentTestId = 'courseAuthoringPageContent';
|
||||||
const wrapper = render(
|
const wrapper = render(
|
||||||
<CourseAuthoringPage courseId={courseId}>
|
<AppProvider store={store}>
|
||||||
<div data-testid={contentTestId} />
|
<IntlProvider locale="en">
|
||||||
</CourseAuthoringPage>
|
<CourseAuthoringPage courseId={courseId}>
|
||||||
|
<div data-testid={contentTestId} />
|
||||||
|
</CourseAuthoringPage>
|
||||||
|
</IntlProvider>
|
||||||
|
</AppProvider>
|
||||||
,
|
,
|
||||||
);
|
);
|
||||||
expect(await wrapper.findByTestId(contentTestId)).toBeInTheDocument();
|
expect(await wrapper.findByTestId(contentTestId)).toBeInTheDocument();
|
||||||
|
|||||||
@@ -20,13 +20,10 @@ import { CourseUpdates } from './course-updates';
|
|||||||
import { CourseUnit } from './course-unit';
|
import { CourseUnit } from './course-unit';
|
||||||
import { Certificates } from './certificates';
|
import { Certificates } from './certificates';
|
||||||
import CourseExportPage from './export-page/CourseExportPage';
|
import CourseExportPage from './export-page/CourseExportPage';
|
||||||
import CourseOptimizerPage from './optimizer-page/CourseOptimizerPage';
|
|
||||||
import CourseImportPage from './import-page/CourseImportPage';
|
import CourseImportPage from './import-page/CourseImportPage';
|
||||||
import { DECODED_ROUTES } from './constants';
|
import { DECODED_ROUTES } from './constants';
|
||||||
import CourseChecklist from './course-checklist';
|
import CourseChecklist from './course-checklist';
|
||||||
import GroupConfigurations from './group-configurations';
|
import GroupConfigurations from './group-configurations';
|
||||||
import { CourseLibraries } from './course-libraries';
|
|
||||||
import { IframeProvider } from './generic/hooks/context/iFrameContext';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* As of this writing, these routes are mounted at a path prefixed with the following:
|
* As of this writing, these routes are mounted at a path prefixed with the following:
|
||||||
@@ -58,10 +55,6 @@ const CourseAuthoringRoutes = () => {
|
|||||||
path="course_info"
|
path="course_info"
|
||||||
element={<PageWrap><CourseUpdates courseId={courseId} /></PageWrap>}
|
element={<PageWrap><CourseUpdates courseId={courseId} /></PageWrap>}
|
||||||
/>
|
/>
|
||||||
<Route
|
|
||||||
path="libraries"
|
|
||||||
element={<PageWrap><CourseLibraries courseId={courseId} /></PageWrap>}
|
|
||||||
/>
|
|
||||||
<Route
|
<Route
|
||||||
path="assets"
|
path="assets"
|
||||||
element={<PageWrap><FilesPage courseId={courseId} /></PageWrap>}
|
element={<PageWrap><FilesPage courseId={courseId} /></PageWrap>}
|
||||||
@@ -86,7 +79,7 @@ const CourseAuthoringRoutes = () => {
|
|||||||
<Route
|
<Route
|
||||||
key={path}
|
key={path}
|
||||||
path={path}
|
path={path}
|
||||||
element={<PageWrap><IframeProvider><CourseUnit courseId={courseId} /></IframeProvider></PageWrap>}
|
element={<PageWrap><CourseUnit courseId={courseId} /></PageWrap>}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
<Route
|
<Route
|
||||||
@@ -95,7 +88,7 @@ const CourseAuthoringRoutes = () => {
|
|||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="editor/:blockType/:blockId?"
|
path="editor/:blockType/:blockId?"
|
||||||
element={<PageWrap><EditorContainer learningContextId={courseId} /></PageWrap>}
|
element={<PageWrap><EditorContainer courseId={courseId} /></PageWrap>}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="settings/details"
|
path="settings/details"
|
||||||
@@ -125,17 +118,13 @@ const CourseAuthoringRoutes = () => {
|
|||||||
path="export"
|
path="export"
|
||||||
element={<PageWrap><CourseExportPage courseId={courseId} /></PageWrap>}
|
element={<PageWrap><CourseExportPage courseId={courseId} /></PageWrap>}
|
||||||
/>
|
/>
|
||||||
<Route
|
|
||||||
path="optimizer"
|
|
||||||
element={<PageWrap><CourseOptimizerPage courseId={courseId} /></PageWrap>}
|
|
||||||
/>
|
|
||||||
<Route
|
<Route
|
||||||
path="checklists"
|
path="checklists"
|
||||||
element={<PageWrap><CourseChecklist courseId={courseId} /></PageWrap>}
|
element={<PageWrap><CourseChecklist courseId={courseId} /></PageWrap>}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="certificates"
|
path="certificates"
|
||||||
element={getConfig().ENABLE_CERTIFICATE_PAGE === 'true' ? <PageWrap><Certificates courseId={courseId} /></PageWrap> : null}
|
element={<PageWrap><Certificates courseId={courseId} /></PageWrap>}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="textbooks"
|
path="textbooks"
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { AppProvider } from '@edx/frontend-platform/react';
|
||||||
|
import { initializeMockApp } from '@edx/frontend-platform';
|
||||||
|
import { render, screen } from '@testing-library/react';
|
||||||
|
import { MemoryRouter } from 'react-router-dom';
|
||||||
import CourseAuthoringRoutes from './CourseAuthoringRoutes';
|
import CourseAuthoringRoutes from './CourseAuthoringRoutes';
|
||||||
import { executeThunk } from './utils';
|
import initializeStore from './store';
|
||||||
import { getApiWaffleFlagsUrl } from './data/api';
|
|
||||||
import { fetchWaffleFlags } from './data/thunks';
|
|
||||||
import {
|
|
||||||
screen, initializeMocks, render, waitFor,
|
|
||||||
} from './testUtils';
|
|
||||||
|
|
||||||
const courseId = 'course-v1:edX+TestX+Test_Course';
|
const courseId = 'course-v1:edX+TestX+Test_Course';
|
||||||
const pagesAndResourcesMockText = 'Pages And Resources';
|
const pagesAndResourcesMockText = 'Pages And Resources';
|
||||||
@@ -21,10 +21,9 @@ jest.mock('react-router-dom', () => ({
|
|||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Mock the TinyMceWidget
|
// Mock the TinyMceWidget from frontend-lib-content-components
|
||||||
jest.mock('./editors/sharedComponents/TinyMceWidget', () => ({
|
jest.mock('@edx/frontend-lib-content-components', () => ({
|
||||||
__esModule: true, // Required to mock a default export
|
TinyMceWidget: () => <div>Widget</div>,
|
||||||
default: () => <div>Widget</div>,
|
|
||||||
Footer: () => <div>Footer</div>,
|
Footer: () => <div>Footer</div>,
|
||||||
prepareEditorRef: jest.fn(() => ({
|
prepareEditorRef: jest.fn(() => ({
|
||||||
refReady: true,
|
refReady: true,
|
||||||
@@ -50,59 +49,68 @@ jest.mock('./custom-pages/CustomPages', () => (props) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('<CourseAuthoringRoutes>', () => {
|
describe('<CourseAuthoringRoutes>', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(() => {
|
||||||
const { axiosMock, reduxStore } = initializeMocks();
|
initializeMockApp({
|
||||||
store = reduxStore;
|
authenticatedUser: {
|
||||||
axiosMock
|
userId: 3,
|
||||||
.onGet(getApiWaffleFlagsUrl(courseId))
|
username: 'abc123',
|
||||||
.reply(200, {});
|
administrator: true,
|
||||||
await executeThunk(fetchWaffleFlags(courseId), store.dispatch);
|
roles: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
store = initializeStore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders the PagesAndResources component when the pages and resources route is active', async () => {
|
fit('renders the PagesAndResources component when the pages and resources route is active', () => {
|
||||||
render(
|
render(
|
||||||
<CourseAuthoringRoutes />,
|
<AppProvider store={store} wrapWithRouter={false}>
|
||||||
{ routerProps: { initialEntries: ['/pages-and-resources'] } },
|
<MemoryRouter initialEntries={['/pages-and-resources']}>
|
||||||
|
<CourseAuthoringRoutes />
|
||||||
|
</MemoryRouter>
|
||||||
|
</AppProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(screen.getByText(pagesAndResourcesMockText)).toBeVisible();
|
||||||
|
expect(mockComponentFn).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
courseId,
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
await waitFor(() => {
|
|
||||||
expect(screen.getByText(pagesAndResourcesMockText)).toBeVisible();
|
|
||||||
expect(mockComponentFn).toHaveBeenCalledWith(
|
|
||||||
expect.objectContaining({
|
|
||||||
courseId,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders the EditorContainer component when the course editor route is active', async () => {
|
it('renders the EditorContainer component when the course editor route is active', () => {
|
||||||
render(
|
render(
|
||||||
<CourseAuthoringRoutes />,
|
<AppProvider store={store} wrapWithRouter={false}>
|
||||||
{ routerProps: { initialEntries: ['/editor/video/block-id'] } },
|
<MemoryRouter initialEntries={['/editor/video/block-id']}>
|
||||||
|
<CourseAuthoringRoutes />
|
||||||
|
</MemoryRouter>
|
||||||
|
</AppProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(screen.queryByText(editorContainerMockText)).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText(pagesAndResourcesMockText)).not.toBeInTheDocument();
|
||||||
|
expect(mockComponentFn).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
courseId,
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
await waitFor(() => {
|
|
||||||
expect(screen.queryByText(editorContainerMockText)).toBeInTheDocument();
|
|
||||||
expect(screen.queryByText(pagesAndResourcesMockText)).not.toBeInTheDocument();
|
|
||||||
expect(mockComponentFn).toHaveBeenCalledWith(
|
|
||||||
expect.objectContaining({
|
|
||||||
learningContextId: courseId,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders the VideoSelectorContainer component when the course videos route is active', async () => {
|
it('renders the VideoSelectorContainer component when the course videos route is active', () => {
|
||||||
render(
|
render(
|
||||||
<CourseAuthoringRoutes />,
|
<AppProvider store={store} wrapWithRouter={false}>
|
||||||
{ routerProps: { initialEntries: ['/editor/course-videos/block-id'] } },
|
<MemoryRouter initialEntries={['/editor/course-videos/block-id']}>
|
||||||
|
<CourseAuthoringRoutes />
|
||||||
|
</MemoryRouter>
|
||||||
|
</AppProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(screen.queryByText(videoSelectorContainerMockText)).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText(pagesAndResourcesMockText)).not.toBeInTheDocument();
|
||||||
|
expect(mockComponentFn).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
courseId,
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
await waitFor(() => {
|
|
||||||
expect(screen.queryByText(videoSelectorContainerMockText)).toBeInTheDocument();
|
|
||||||
expect(screen.queryByText(pagesAndResourcesMockText)).not.toBeInTheDocument();
|
|
||||||
expect(mockComponentFn).toHaveBeenCalledWith(
|
|
||||||
expect.objectContaining({
|
|
||||||
courseId,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
export default {
|
|
||||||
content: {
|
|
||||||
id: 67,
|
|
||||||
userId: 3,
|
|
||||||
created: '2024-01-16T13:09:11.540615Z',
|
|
||||||
purpose: 'clipboard',
|
|
||||||
status: 'ready',
|
|
||||||
blockType: 'sequential',
|
|
||||||
blockTypeDisplay: 'Subsection',
|
|
||||||
olxUrl: 'http://localhost:18010/api/content-staging/v1/staged-content/67/olx',
|
|
||||||
displayName: 'Sequences',
|
|
||||||
},
|
|
||||||
sourceUsageKey: 'block-v1:edX+DemoX+Demo_Course+type@sequential+block@sequential_0270f6de40fc',
|
|
||||||
sourceContextTitle: 'Demonstration Course',
|
|
||||||
sourceEditUrl: 'http://localhost:18010/container/block-v1:edX+DemoX+Demo_Course+type@sequential+block@sequential_0270f6de40fc',
|
|
||||||
};
|
|
||||||
@@ -1,3 +1,2 @@
|
|||||||
export { default as clipboardUnit } from './clipboardUnit';
|
export { default as clipboardUnit } from './clipboardUnit';
|
||||||
export { default as clipboardSubsection } from './clipboardSubsection';
|
|
||||||
export { default as clipboardXBlock } from './clipboardXBlock';
|
export { default as clipboardXBlock } from './clipboardXBlock';
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||||
import { Helmet } from 'react-helmet';
|
import { Helmet } from 'react-helmet';
|
||||||
import { Container } from '@openedx/paragon';
|
import { Container } from '@openedx/paragon';
|
||||||
import { StudioFooterSlot } from '@openedx/frontend-slot-footer';
|
import { StudioFooter } from '@edx/frontend-component-footer';
|
||||||
|
|
||||||
import Header from '../header';
|
import Header from '../header';
|
||||||
import messages from './messages';
|
import messages from './messages';
|
||||||
@@ -29,7 +29,7 @@ const AccessibilityPage = ({
|
|||||||
<AccessibilityBody {...{ email, communityAccessibilityLink }} />
|
<AccessibilityBody {...{ email, communityAccessibilityLink }} />
|
||||||
<AccessibilityForm accessibilityEmail={email} />
|
<AccessibilityForm accessibilityEmail={email} />
|
||||||
</Container>
|
</Container>
|
||||||
<StudioFooterSlot />
|
<StudioFooter />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { defineMessages } from '@edx/frontend-platform/i18n';
|
|||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
pageTitle: {
|
pageTitle: {
|
||||||
id: 'course-authoring.accessibility.page.title',
|
id: 'course-authoring.import.page.title',
|
||||||
defaultMessage: 'Studio Accessibility Policy| {siteName}',
|
defaultMessage: 'Studio Accessibility Policy| {siteName}',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
} from '@openedx/paragon';
|
} from '@openedx/paragon';
|
||||||
import { CheckCircle, Info, Warning } from '@openedx/paragon/icons';
|
import { CheckCircle, Info, Warning } from '@openedx/paragon/icons';
|
||||||
import { FormattedMessage, injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
import { FormattedMessage, injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||||
import Placeholder from '../editors/Placeholder';
|
import Placeholder from '@edx/frontend-lib-content-components';
|
||||||
|
|
||||||
import AlertProctoringError from '../generic/AlertProctoringError';
|
import AlertProctoringError from '../generic/AlertProctoringError';
|
||||||
import { useModel } from '../generic/model-store';
|
import { useModel } from '../generic/model-store';
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
|
// eslint-disable-next-line import/prefer-default-export
|
||||||
export { default as advancedSettingsMock } from './advancedSettings';
|
export { default as advancedSettingsMock } from './advancedSettings';
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable import/prefer-default-export */
|
||||||
import { camelCaseObject, getConfig } from '@edx/frontend-platform';
|
import { camelCaseObject, getConfig } from '@edx/frontend-platform';
|
||||||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
||||||
import { convertObjectToSnakeCase } from '../../utils';
|
import { convertObjectToSnakeCase } from '../../utils';
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
|
/* eslint-disable import/prefer-default-export */
|
||||||
export { default as AdvancedSettings } from './AdvancedSettings';
|
export { default as AdvancedSettings } from './AdvancedSettings';
|
||||||
|
|||||||
@@ -79,7 +79,3 @@
|
|||||||
color: $black;
|
color: $black;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.react-datepicker-popper {
|
|
||||||
z-index: 3;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,7 +9,3 @@
|
|||||||
.mw-300px {
|
.mw-300px {
|
||||||
max-width: 300px;
|
max-width: 300px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.right-0 {
|
|
||||||
right: 0;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Helmet } from 'react-helmet';
|
import { Helmet } from 'react-helmet';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import Placeholder from '@edx/frontend-lib-content-components';
|
||||||
|
|
||||||
import Placeholder from '../editors/Placeholder';
|
|
||||||
import { RequestStatus } from '../data/constants';
|
import { RequestStatus } from '../data/constants';
|
||||||
import Loading from '../generic/Loading';
|
import Loading from '../generic/Loading';
|
||||||
import useCertificates from './hooks/useCertificates';
|
import useCertificates from './hooks/useCertificates';
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
|
|
||||||
|
// eslint-disable-next-line import/prefer-default-export
|
||||||
export const defaultCertificate = {
|
export const defaultCertificate = {
|
||||||
courseTitle: '',
|
courseTitle: '',
|
||||||
signatories: [{
|
signatories: [{
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable import/prefer-default-export */
|
||||||
import { camelCaseObject, getConfig } from '@edx/frontend-platform';
|
import { camelCaseObject, getConfig } from '@edx/frontend-platform';
|
||||||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
|
/* eslint-disable import/prefer-default-export */
|
||||||
export { default as Certificates } from './Certificates';
|
export { default as Certificates } from './Certificates';
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// eslint-disable-next-line import/prefer-default-export
|
||||||
export const getSidebarData = ({ messages, intl }) => [
|
export const getSidebarData = ({ messages, intl }) => [
|
||||||
{
|
{
|
||||||
title: intl.formatMessage(messages.workingWithCertificatesTitle),
|
title: intl.formatMessage(messages.workingWithCertificatesTitle),
|
||||||
|
|||||||
@@ -59,10 +59,10 @@ describe('HeaderButtons Component', () => {
|
|||||||
expect(previewLink).toHaveAttribute('href', expect.stringContaining(certificatesDataMock.courseModes[0]));
|
expect(previewLink).toHaveAttribute('href', expect.stringContaining(certificatesDataMock.courseModes[0]));
|
||||||
|
|
||||||
const dropdownButton = getByRole('button', { name: certificatesDataMock.courseModes[0] });
|
const dropdownButton = getByRole('button', { name: certificatesDataMock.courseModes[0] });
|
||||||
userEvent.click(dropdownButton);
|
await userEvent.click(dropdownButton);
|
||||||
|
|
||||||
const verifiedMode = await getByRole('button', { name: certificatesDataMock.courseModes[1] });
|
const verifiedMode = await getByRole('button', { name: certificatesDataMock.courseModes[1] });
|
||||||
userEvent.click(verifiedMode);
|
await userEvent.click(verifiedMode);
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(previewLink).toHaveAttribute('href', expect.stringContaining(certificatesDataMock.courseModes[1]));
|
expect(previewLink).toHaveAttribute('href', expect.stringContaining(certificatesDataMock.courseModes[1]));
|
||||||
@@ -78,7 +78,7 @@ describe('HeaderButtons Component', () => {
|
|||||||
const { getByRole, queryByRole } = renderComponent();
|
const { getByRole, queryByRole } = renderComponent();
|
||||||
|
|
||||||
const activationButton = getByRole('button', { name: messages.headingActionsActivate.defaultMessage });
|
const activationButton = getByRole('button', { name: messages.headingActionsActivate.defaultMessage });
|
||||||
userEvent.click(activationButton);
|
await userEvent.click(activationButton);
|
||||||
|
|
||||||
axiosMock.onPost(
|
axiosMock.onPost(
|
||||||
getUpdateCertificateApiUrl(courseId, certificatesDataMock.certificates[0].id),
|
getUpdateCertificateApiUrl(courseId, certificatesDataMock.certificates[0].id),
|
||||||
@@ -110,7 +110,7 @@ describe('HeaderButtons Component', () => {
|
|||||||
const { getByRole, queryByRole } = renderComponent();
|
const { getByRole, queryByRole } = renderComponent();
|
||||||
|
|
||||||
const deactivateButton = getByRole('button', { name: messages.headingActionsDeactivate.defaultMessage });
|
const deactivateButton = getByRole('button', { name: messages.headingActionsDeactivate.defaultMessage });
|
||||||
userEvent.click(deactivateButton);
|
await userEvent.click(deactivateButton);
|
||||||
|
|
||||||
axiosMock.onPost(
|
axiosMock.onPost(
|
||||||
getUpdateCertificateApiUrl(courseId, certificatesDataMock.certificates[0].id),
|
getUpdateCertificateApiUrl(courseId, certificatesDataMock.certificates[0].id),
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { convertObjectToSnakeCase } from '../utils';
|
import { convertObjectToSnakeCase } from '../utils';
|
||||||
|
|
||||||
|
// eslint-disable-next-line import/prefer-default-export
|
||||||
export const prepareCertificatePayload = (data) => convertObjectToSnakeCase(({
|
export const prepareCertificatePayload = (data) => convertObjectToSnakeCase(({
|
||||||
...data,
|
...data,
|
||||||
courseTitle: data.courseTitle,
|
courseTitle: data.courseTitle,
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ export const NOTIFICATION_MESSAGES = {
|
|||||||
copying: 'Copying',
|
copying: 'Copying',
|
||||||
pasting: 'Pasting',
|
pasting: 'Pasting',
|
||||||
discardChanges: 'Discarding changes',
|
discardChanges: 'Discarding changes',
|
||||||
moving: 'Moving',
|
|
||||||
undoMoving: 'Undo moving',
|
|
||||||
publishing: 'Publishing',
|
publishing: 'Publishing',
|
||||||
hidingFromStudents: 'Hiding from students',
|
hidingFromStudents: 'Hiding from students',
|
||||||
makingVisibleToStudents: 'Making visible to students',
|
makingVisibleToStudents: 'Making visible to students',
|
||||||
@@ -58,8 +56,6 @@ export const COURSE_BLOCK_NAMES = ({
|
|||||||
chapter: { id: 'chapter', name: 'Section' },
|
chapter: { id: 'chapter', name: 'Section' },
|
||||||
sequential: { id: 'sequential', name: 'Subsection' },
|
sequential: { id: 'sequential', name: 'Subsection' },
|
||||||
vertical: { id: 'vertical', name: 'Unit' },
|
vertical: { id: 'vertical', name: 'Unit' },
|
||||||
libraryContent: { id: 'library_content', name: 'Library content' },
|
|
||||||
splitTest: { id: 'split_test', name: 'Split Test' },
|
|
||||||
component: { id: 'component', name: 'Component' },
|
component: { id: 'component', name: 'Component' },
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -73,36 +69,3 @@ export const CLIPBOARD_STATUS = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const STRUCTURAL_XBLOCK_TYPES = ['vertical', 'sequential', 'chapter', 'course'];
|
export const STRUCTURAL_XBLOCK_TYPES = ['vertical', 'sequential', 'chapter', 'course'];
|
||||||
|
|
||||||
export const REGEX_RULES = {
|
|
||||||
specialCharsRule: /^[a-zA-Z0-9_\-.'*~\s]+$/,
|
|
||||||
noSpaceRule: /^\S*$/,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Feature policy for iframe, allowing access to certain courseware-related media.
|
|
||||||
*
|
|
||||||
* We must use the wildcard (*) origin for each feature, as courseware content
|
|
||||||
* may be embedded in external iframes. Notably, xblock-lti-consumer is a popular
|
|
||||||
* block that iframes external course content.
|
|
||||||
|
|
||||||
* This policy was selected in conference with the edX Security Working Group.
|
|
||||||
* Changes to it should be vetted by them (security@edx.org).
|
|
||||||
*/
|
|
||||||
export const IFRAME_FEATURE_POLICY = (
|
|
||||||
'microphone *; camera *; midi *; geolocation *; encrypted-media *; clipboard-write *'
|
|
||||||
);
|
|
||||||
|
|
||||||
export const iframeStateKeys = {
|
|
||||||
iframeHeight: 'iframeHeight',
|
|
||||||
hasLoaded: 'hasLoaded',
|
|
||||||
showError: 'showError',
|
|
||||||
windowTopOffset: 'windowTopOffset',
|
|
||||||
};
|
|
||||||
|
|
||||||
export const iframeMessageTypes = {
|
|
||||||
modal: 'plugin.modal',
|
|
||||||
resize: 'plugin.resize',
|
|
||||||
videoFullScreen: 'plugin.videoFullScreen',
|
|
||||||
xblockEvent: 'xblock-event',
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -5,24 +5,24 @@ import type {} from 'react-select/base';
|
|||||||
// and add our custom property 'myCustomProp' to it.
|
// and add our custom property 'myCustomProp' to it.
|
||||||
|
|
||||||
export interface TagTreeEntry {
|
export interface TagTreeEntry {
|
||||||
explicit: boolean;
|
explicit: boolean;
|
||||||
children: Record<string, TagTreeEntry>;
|
children: Record<string, TagTreeEntry>;
|
||||||
canChangeObjecttag: boolean;
|
canChangeObjecttag: boolean;
|
||||||
canDeleteObjecttag: boolean;
|
canDeleteObjecttag: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TaxonomySelectProps {
|
export interface TaxonomySelectProps {
|
||||||
taxonomyId: number;
|
taxonomyId: number;
|
||||||
searchTerm: string;
|
searchTerm: string;
|
||||||
appliedContentTagsTree: Record<string, TagTreeEntry>;
|
appliedContentTagsTree: Record<string, TagTreeEntry>;
|
||||||
stagedContentTagsTree: Record<string, TagTreeEntry>;
|
stagedContentTagsTree: Record<string, TagTreeEntry>;
|
||||||
checkedTags: string[];
|
checkedTags: string[];
|
||||||
selectCancelRef: Ref,
|
selectCancelRef: Ref,
|
||||||
selectAddRef: Ref,
|
selectAddRef: Ref,
|
||||||
selectInlineAddRef: Ref,
|
selectInlineAddRef: Ref,
|
||||||
handleCommitStagedTags: () => void;
|
handleCommitStagedTags: () => void;
|
||||||
handleCancelStagedTags: () => void;
|
handleCancelStagedTags: () => void;
|
||||||
handleSelectableBoxChange: React.ChangeEventHandler;
|
handleSelectableBoxChange: React.ChangeEventHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unfortunately the only way to specify the custom props we pass into React Select
|
// Unfortunately the only way to specify the custom props we pass into React Select
|
||||||
@@ -32,8 +32,11 @@ export interface TaxonomySelectProps {
|
|||||||
// we should change to using a 'react context' to share this data within <ContentTagsCollapsible>,
|
// we should change to using a 'react context' to share this data within <ContentTagsCollapsible>,
|
||||||
// rather than using the custom <Select> Props (selectProps).
|
// rather than using the custom <Select> Props (selectProps).
|
||||||
declare module 'react-select/base' {
|
declare module 'react-select/base' {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
export interface Props<
|
||||||
export interface Props<Option, IsMulti extends boolean, Group extends GroupBase<Option>> extends TaxonomySelectProps {
|
Option,
|
||||||
|
IsMulti extends boolean,
|
||||||
|
Group extends GroupBase<Option>
|
||||||
|
> extends TaxonomySelectProps {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,9 @@ import {
|
|||||||
Icon,
|
Icon,
|
||||||
} from '@openedx/paragon';
|
} from '@openedx/paragon';
|
||||||
import { Tag, KeyboardArrowDown, KeyboardArrowUp } from '@openedx/paragon/icons';
|
import { Tag, KeyboardArrowDown, KeyboardArrowUp } from '@openedx/paragon/icons';
|
||||||
|
import { SelectableBox } from '@edx/frontend-lib-content-components';
|
||||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
|
|
||||||
import SelectableBox from '../editors/sharedComponents/SelectableBox';
|
|
||||||
import messages from './messages';
|
import messages from './messages';
|
||||||
|
|
||||||
import ContentTagsDropDownSelector from './ContentTagsDropDownSelector';
|
import ContentTagsDropDownSelector from './ContentTagsDropDownSelector';
|
||||||
@@ -25,9 +24,9 @@ import TagsTree from './TagsTree';
|
|||||||
import { ContentTagsDrawerContext } from './common/context';
|
import { ContentTagsDrawerContext } from './common/context';
|
||||||
|
|
||||||
/** @typedef {import("./ContentTagsCollapsible").TaxonomySelectProps} TaxonomySelectProps */
|
/** @typedef {import("./ContentTagsCollapsible").TaxonomySelectProps} TaxonomySelectProps */
|
||||||
/** @typedef {import("../taxonomy/data/types.js").TaxonomyData} TaxonomyData */
|
/** @typedef {import("../taxonomy/data/types.mjs").TaxonomyData} TaxonomyData */
|
||||||
/** @typedef {import("./data/types.js").Tag} ContentTagData */
|
/** @typedef {import("./data/types.mjs").Tag} ContentTagData */
|
||||||
/** @typedef {import("./data/types.js").StagedTagData} StagedTagData */
|
/** @typedef {import("./data/types.mjs").StagedTagData} StagedTagData */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom Menu component for our Select box
|
* Custom Menu component for our Select box
|
||||||
@@ -75,7 +74,7 @@ const CustomMenu = (props) => {
|
|||||||
<div className="d-flex flex-row justify-content-end">
|
<div className="d-flex flex-row justify-content-end">
|
||||||
<div className="d-inline">
|
<div className="d-inline">
|
||||||
<Button
|
<Button
|
||||||
tabIndex={0}
|
tabIndex="0"
|
||||||
ref={selectCancelRef}
|
ref={selectCancelRef}
|
||||||
variant="tertiary"
|
variant="tertiary"
|
||||||
className="tags-drawer-cancel-button"
|
className="tags-drawer-cancel-button"
|
||||||
@@ -84,7 +83,7 @@ const CustomMenu = (props) => {
|
|||||||
{ intl.formatMessage(messages.collapsibleCancelStagedTagsButtonText) }
|
{ intl.formatMessage(messages.collapsibleCancelStagedTagsButtonText) }
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
tabIndex={0}
|
tabIndex="0"
|
||||||
ref={selectAddRef}
|
ref={selectAddRef}
|
||||||
variant="tertiary"
|
variant="tertiary"
|
||||||
className="text-info-500 add-tags-button"
|
className="text-info-500 add-tags-button"
|
||||||
@@ -140,7 +139,7 @@ const CustomIndicatorsContainer = (props) => {
|
|||||||
onClick={handleCommitStagedTags}
|
onClick={handleCommitStagedTags}
|
||||||
onMouseDown={(e) => { e.stopPropagation(); e.preventDefault(); }}
|
onMouseDown={(e) => { e.stopPropagation(); e.preventDefault(); }}
|
||||||
ref={selectInlineAddRef}
|
ref={selectInlineAddRef}
|
||||||
tabIndex={0}
|
tabIndex="0"
|
||||||
onKeyDown={disableActionKeys} // To prevent navigating staged tags when button focused
|
onKeyDown={disableActionKeys} // To prevent navigating staged tags when button focused
|
||||||
>
|
>
|
||||||
{ intl.formatMessage(messages.collapsibleInlineAddStagedTagsButtonText) }
|
{ intl.formatMessage(messages.collapsibleInlineAddStagedTagsButtonText) }
|
||||||
@@ -241,7 +240,7 @@ const ContentTagsCollapsible = ({
|
|||||||
const selectCancelRef = React.useRef(/** @type {HTMLSelectElement | null} */(null));
|
const selectCancelRef = React.useRef(/** @type {HTMLSelectElement | null} */(null));
|
||||||
const selectAddRef = React.useRef(/** @type {HTMLSelectElement | null} */(null));
|
const selectAddRef = React.useRef(/** @type {HTMLSelectElement | null} */(null));
|
||||||
const selectInlineAddRef = React.useRef(/** @type {HTMLSelectElement | null} */(null));
|
const selectInlineAddRef = React.useRef(/** @type {HTMLSelectElement | null} */(null));
|
||||||
const selectInlineEditModeRef = React.useRef(/** @type {HTMLButtonElement | null} */(null));
|
const selectInlineEditModeRef = React.useRef(/** @type {HTMLSelectElement | null} */(null));
|
||||||
const selectRef = React.useRef(/** @type {HTMLSelectElement | null} */(null));
|
const selectRef = React.useRef(/** @type {HTMLSelectElement | null} */(null));
|
||||||
|
|
||||||
const [selectMenuIsOpen, setSelectMenuIsOpen] = React.useState(false);
|
const [selectMenuIsOpen, setSelectMenuIsOpen] = React.useState(false);
|
||||||
@@ -393,18 +392,16 @@ const ContentTagsCollapsible = ({
|
|||||||
&& (
|
&& (
|
||||||
<div className="mb-3" key={taxonomyId}>
|
<div className="mb-3" key={taxonomyId}>
|
||||||
<p className="text-gray-500">{intl.formatMessage(messages.collapsibleNoTagsAddedText)}
|
<p className="text-gray-500">{intl.formatMessage(messages.collapsibleNoTagsAddedText)}
|
||||||
{canTagObject && (
|
<Button
|
||||||
<Button
|
tabIndex="0"
|
||||||
tabIndex={0}
|
size="inline"
|
||||||
size="inline"
|
ref={selectInlineEditModeRef}
|
||||||
ref={selectInlineEditModeRef}
|
variant="link"
|
||||||
variant="link"
|
className="text-info-500 add-tags-button"
|
||||||
className="text-info-500 add-tags-button"
|
onClick={toEditMode}
|
||||||
onClick={toEditMode}
|
>
|
||||||
>
|
{ intl.formatMessage(messages.collapsibleAddStagedTagsButtonText) }
|
||||||
{ intl.formatMessage(messages.collapsibleAddStagedTagsButtonText) }
|
</Button>
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -420,7 +417,7 @@ const ContentTagsCollapsible = ({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="d-flex taxonomy-tags-selector-menu">
|
<div className="d-flex taxonomy-tags-selector-menu">
|
||||||
{isEditMode && (
|
{isEditMode && canTagObject && (
|
||||||
<Select
|
<Select
|
||||||
onBlur={handleOnBlur}
|
onBlur={handleOnBlur}
|
||||||
styles={{
|
styles={{
|
||||||
|
|||||||
@@ -280,30 +280,6 @@ describe('<ContentTagsCollapsible />', () => {
|
|||||||
expect(data.toEditMode).toHaveBeenCalledTimes(1);
|
expect(data.toEditMode).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not render "add tags" button when expanded and not allowed to tag objects', async () => {
|
|
||||||
await getComponent({
|
|
||||||
...data,
|
|
||||||
isEditMode: false,
|
|
||||||
taxonomyAndTagsData: {
|
|
||||||
id: 123,
|
|
||||||
name: 'Taxonomy 1',
|
|
||||||
canTagObject: false,
|
|
||||||
contentTags: [],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const expandToggle = screen.getByRole('button', {
|
|
||||||
name: /taxonomy 1/i,
|
|
||||||
});
|
|
||||||
fireEvent.click(expandToggle);
|
|
||||||
expect(screen.queryByText(/no tags added yet/i)).toBeInTheDocument();
|
|
||||||
|
|
||||||
const addTags = screen.queryByRole('button', {
|
|
||||||
name: /add tags/i,
|
|
||||||
});
|
|
||||||
expect(addTags).not.toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call `openCollapsible` when click in the collapsible', async () => {
|
it('should call `openCollapsible` when click in the collapsible', async () => {
|
||||||
await getComponent({
|
await getComponent({
|
||||||
...data,
|
...data,
|
||||||
@@ -420,7 +396,7 @@ describe('<ContentTagsCollapsible />', () => {
|
|||||||
expect(data.removeGlobalStagedContentTag).toHaveBeenCalledWith(taxonomyId, 'Tag 3');
|
expect(data.removeGlobalStagedContentTag).toHaveBeenCalledWith(taxonomyId, 'Tag 3');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call `addRemovedContentTag` when a fetched tag is deleted', async () => {
|
it('should call `addRemovedContentTag` when a feched tag is deleted', async () => {
|
||||||
await getComponent();
|
await getComponent();
|
||||||
|
|
||||||
const tag = screen.getByText(/tag 2/i);
|
const tag = screen.getByText(/tag 2/i);
|
||||||
@@ -699,7 +675,7 @@ describe('<ContentTagsCollapsible />', () => {
|
|||||||
const xButtonAppliedTag = within(appliedTag).getByRole('button', {
|
const xButtonAppliedTag = within(appliedTag).getByRole('button', {
|
||||||
name: /delete/i,
|
name: /delete/i,
|
||||||
});
|
});
|
||||||
await userEvent.click(xButtonAppliedTag);
|
xButtonAppliedTag.click();
|
||||||
|
|
||||||
// Check that the applied tag has been removed
|
// Check that the applied tag has been removed
|
||||||
expect(appliedTag).not.toBeInTheDocument();
|
expect(appliedTag).not.toBeInTheDocument();
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import { cloneDeep } from 'lodash';
|
|||||||
import { useContentTaxonomyTagsUpdater } from './data/apiHooks';
|
import { useContentTaxonomyTagsUpdater } from './data/apiHooks';
|
||||||
import { ContentTagsDrawerContext } from './common/context';
|
import { ContentTagsDrawerContext } from './common/context';
|
||||||
|
|
||||||
/** @typedef {import("../taxonomy/data/types.js").TaxonomyData} TaxonomyData */
|
/** @typedef {import("../taxonomy/data/types.mjs").TaxonomyData} TaxonomyData */
|
||||||
/** @typedef {import("./data/types.js").Tag} ContentTagData */
|
/** @typedef {import("./data/types.mjs").Tag} ContentTagData */
|
||||||
/** @typedef {import("./ContentTagsCollapsible").TagTreeEntry} TagTreeEntry */
|
/** @typedef {import("./ContentTagsCollapsible").TagTreeEntry} TagTreeEntry */
|
||||||
/** @typedef {import("./data/types.js").StagedTagData} StagedTagData */
|
/** @typedef {import("./data/types.mjs").StagedTagData} StagedTagData */
|
||||||
/** @typedef {import("./data/types.js").UpdateTagsData} UpdateTagsData */
|
/** @typedef {import("./data/types.mjs").UpdateTagsData} UpdateTagsData */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Util function that sorts the keys of a tree in alphabetical order.
|
* Util function that sorts the keys of a tree in alphabetical order.
|
||||||
@@ -116,7 +116,7 @@ const useContentTagsCollapsibleHelper = (
|
|||||||
// State to keep track of the staged tags (and along with ancestors) that should be removed
|
// State to keep track of the staged tags (and along with ancestors) that should be removed
|
||||||
const [stagedTagsToRemove, setStagedTagsToRemove] = React.useState(/** @type string[] */([]));
|
const [stagedTagsToRemove, setStagedTagsToRemove] = React.useState(/** @type string[] */([]));
|
||||||
|
|
||||||
// State to keep track of the global tags (staged and fetched) that should be removed
|
// State to keep track of the global tags (stagged and feched) that should be removed
|
||||||
const [globalTagsToRemove, setGlobalTagsToRemove] = React.useState(/** @type string[] */([]));
|
const [globalTagsToRemove, setGlobalTagsToRemove] = React.useState(/** @type string[] */([]));
|
||||||
|
|
||||||
// Handles the removal of staged content tags based on what was removed
|
// Handles the removal of staged content tags based on what was removed
|
||||||
@@ -140,7 +140,7 @@ const useContentTagsCollapsibleHelper = (
|
|||||||
// A new tag has been removed
|
// A new tag has been removed
|
||||||
removeGlobalStagedContentTag(id, tag);
|
removeGlobalStagedContentTag(id, tag);
|
||||||
} else if (contentTags.some(t => t.value === tag)) {
|
} else if (contentTags.some(t => t.value === tag)) {
|
||||||
// A fetched tag has been removed
|
// A feched tag has been removed
|
||||||
addRemovedContentTag(id, tag);
|
addRemovedContentTag(id, tag);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -157,7 +157,7 @@ const useContentTagsCollapsibleHelper = (
|
|||||||
explicitStaged.forEach((tag) => {
|
explicitStaged.forEach((tag) => {
|
||||||
if (globalStagedRemovedContentTags[id]
|
if (globalStagedRemovedContentTags[id]
|
||||||
&& globalStagedRemovedContentTags[id].includes(tag.value)) {
|
&& globalStagedRemovedContentTags[id].includes(tag.value)) {
|
||||||
// A fetched tag that has been removed has been added again
|
// A feched tag that has been removed has been added again
|
||||||
deleteRemovedContentTag(id, tag.value);
|
deleteRemovedContentTag(id, tag.value);
|
||||||
} else {
|
} else {
|
||||||
// New tag added
|
// New tag added
|
||||||
@@ -298,7 +298,7 @@ const useContentTagsCollapsibleHelper = (
|
|||||||
traversal[tag].lineage = tagLineage;
|
traversal[tag].lineage = tagLineage;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
// eslint-disable-next-line no-unused-expressions
|
||||||
isExplicit ? add(value.join(',')) : remove(value.join(','));
|
isExplicit ? add(value.join(',')) : remove(value.join(','));
|
||||||
traversal = traversal[tag].children;
|
traversal = traversal[tag].children;
|
||||||
});
|
});
|
||||||
|
|||||||
263
src/content-tags-drawer/ContentTagsDrawer.jsx
Normal file
263
src/content-tags-drawer/ContentTagsDrawer.jsx
Normal file
@@ -0,0 +1,263 @@
|
|||||||
|
// @ts-check
|
||||||
|
import React, { useContext, useEffect } from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import {
|
||||||
|
Container,
|
||||||
|
Spinner,
|
||||||
|
Stack,
|
||||||
|
Button,
|
||||||
|
Toast,
|
||||||
|
} from '@openedx/paragon';
|
||||||
|
import { useIntl, FormattedMessage } from '@edx/frontend-platform/i18n';
|
||||||
|
import { useParams, useNavigate } from 'react-router-dom';
|
||||||
|
import messages from './messages';
|
||||||
|
import ContentTagsCollapsible from './ContentTagsCollapsible';
|
||||||
|
import Loading from '../generic/Loading';
|
||||||
|
import useContentTagsDrawerContext from './ContentTagsDrawerHelper';
|
||||||
|
import { ContentTagsDrawerContext, ContentTagsDrawerSheetContext } from './common/context';
|
||||||
|
|
||||||
|
const TaxonomyList = ({ contentId }) => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const intl = useIntl();
|
||||||
|
|
||||||
|
const {
|
||||||
|
isTaxonomyListLoaded,
|
||||||
|
isContentTaxonomyTagsLoaded,
|
||||||
|
tagsByTaxonomy,
|
||||||
|
stagedContentTags,
|
||||||
|
collapsibleStates,
|
||||||
|
} = React.useContext(ContentTagsDrawerContext);
|
||||||
|
|
||||||
|
if (isTaxonomyListLoaded && isContentTaxonomyTagsLoaded) {
|
||||||
|
if (tagsByTaxonomy.length !== 0) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{ tagsByTaxonomy.map((data) => (
|
||||||
|
<div key={`taxonomy-tags-collapsible-${data.id}`}>
|
||||||
|
<ContentTagsCollapsible
|
||||||
|
contentId={contentId}
|
||||||
|
taxonomyAndTagsData={data}
|
||||||
|
stagedContentTags={stagedContentTags[data.id] || []}
|
||||||
|
collapsibleState={collapsibleStates[data.id] || false}
|
||||||
|
/>
|
||||||
|
<hr />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FormattedMessage
|
||||||
|
{...messages.emptyDrawerContent}
|
||||||
|
values={{
|
||||||
|
link: (
|
||||||
|
<Button
|
||||||
|
tabIndex="0"
|
||||||
|
size="inline"
|
||||||
|
variant="link"
|
||||||
|
className="text-info-500 p-0 enable-taxonomies-button"
|
||||||
|
onClick={() => navigate('/taxonomies')}
|
||||||
|
>
|
||||||
|
{ intl.formatMessage(messages.emptyDrawerContentLink) }
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Loading />;
|
||||||
|
};
|
||||||
|
|
||||||
|
TaxonomyList.propTypes = {
|
||||||
|
contentId: PropTypes.string.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drawer with the functionality to show and manage tags in a certain content.
|
||||||
|
* It is used both in interfaces of this MFE and in edx-platform interfaces such as iframe.
|
||||||
|
* - If you want to use it as an iframe, the component obtains the `contentId` from the url parameters.
|
||||||
|
* Functions to close the drawer are handled internally.
|
||||||
|
* TODO: We can delete this method when is no longer used on edx-platform.
|
||||||
|
* - If you want to use it as react component, you need to pass the content id and the close functions
|
||||||
|
* through the component parameters.
|
||||||
|
*/
|
||||||
|
const ContentTagsDrawer = ({ id, onClose }) => {
|
||||||
|
const intl = useIntl();
|
||||||
|
// TODO: We can delete 'params' when the iframe is no longer used on edx-platform
|
||||||
|
const params = useParams();
|
||||||
|
const contentId = id ?? params.contentId;
|
||||||
|
|
||||||
|
const context = useContentTagsDrawerContext(contentId);
|
||||||
|
const { blockingSheet } = useContext(ContentTagsDrawerSheetContext);
|
||||||
|
|
||||||
|
const {
|
||||||
|
showToastAfterSave,
|
||||||
|
toReadMode,
|
||||||
|
commitGlobalStagedTagsStatus,
|
||||||
|
isContentDataLoaded,
|
||||||
|
contentName,
|
||||||
|
isTaxonomyListLoaded,
|
||||||
|
isContentTaxonomyTagsLoaded,
|
||||||
|
stagedContentTags,
|
||||||
|
collapsibleStates,
|
||||||
|
isEditMode,
|
||||||
|
commitGlobalStagedTags,
|
||||||
|
toEditMode,
|
||||||
|
toastMessage,
|
||||||
|
closeToast,
|
||||||
|
setCollapsibleToInitalState,
|
||||||
|
otherTaxonomies,
|
||||||
|
} = context;
|
||||||
|
|
||||||
|
let onCloseDrawer = onClose;
|
||||||
|
if (onCloseDrawer === undefined) {
|
||||||
|
onCloseDrawer = () => {
|
||||||
|
// "*" allows communication with any origin
|
||||||
|
window.parent.postMessage('closeManageTagsDrawer', '*');
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleEsc = (event) => {
|
||||||
|
/* Close drawer when ESC-key is pressed and selectable dropdown box not open */
|
||||||
|
const selectableBoxOpen = document.querySelector('[data-selectable-box="taxonomy-tags"]');
|
||||||
|
if (event.key === 'Escape' && !selectableBoxOpen && !blockingSheet) {
|
||||||
|
onCloseDrawer();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
document.addEventListener('keydown', handleEsc);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('keydown', handleEsc);
|
||||||
|
};
|
||||||
|
}, [blockingSheet]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
/* istanbul ignore next */
|
||||||
|
if (commitGlobalStagedTagsStatus === 'success') {
|
||||||
|
showToastAfterSave();
|
||||||
|
toReadMode();
|
||||||
|
}
|
||||||
|
}, [commitGlobalStagedTagsStatus]);
|
||||||
|
|
||||||
|
// First call of the initial collapsible states
|
||||||
|
React.useEffect(() => {
|
||||||
|
setCollapsibleToInitalState();
|
||||||
|
}, [isTaxonomyListLoaded, isContentTaxonomyTagsLoaded]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ContentTagsDrawerContext.Provider value={context}>
|
||||||
|
<div id="content-tags-drawer" className="mt-1 tags-drawer d-flex flex-column justify-content-between min-vh-100 pt-3">
|
||||||
|
<Container size="xl">
|
||||||
|
{ isContentDataLoaded
|
||||||
|
? <h2 className="h3 pl-2.5">{ contentName }</h2>
|
||||||
|
: (
|
||||||
|
<div className="d-flex justify-content-center align-items-center flex-column">
|
||||||
|
<Spinner
|
||||||
|
animation="border"
|
||||||
|
size="xl"
|
||||||
|
screenReaderText={intl.formatMessage(messages.loadingMessage)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<hr />
|
||||||
|
<Container>
|
||||||
|
<p className="h4 text-gray-500 font-weight-bold">
|
||||||
|
{intl.formatMessage(messages.headerSubtitle)}
|
||||||
|
</p>
|
||||||
|
<TaxonomyList contentId={contentId} />
|
||||||
|
{otherTaxonomies.length !== 0 && (
|
||||||
|
<div>
|
||||||
|
<p className="h4 text-gray-500 font-weight-bold">
|
||||||
|
{intl.formatMessage(messages.otherTagsHeader)}
|
||||||
|
</p>
|
||||||
|
<p className="other-description text-gray-500">
|
||||||
|
{intl.formatMessage(messages.otherTagsDescription)}
|
||||||
|
</p>
|
||||||
|
{ isTaxonomyListLoaded && isContentTaxonomyTagsLoaded && (
|
||||||
|
otherTaxonomies.map((data) => (
|
||||||
|
<div key={`taxonomy-tags-collapsible-${data.id}`}>
|
||||||
|
<ContentTagsCollapsible
|
||||||
|
contentId={contentId}
|
||||||
|
taxonomyAndTagsData={data}
|
||||||
|
stagedContentTags={stagedContentTags[data.id] || []}
|
||||||
|
collapsibleState={collapsibleStates[data.id] || false}
|
||||||
|
/>
|
||||||
|
<hr />
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Container>
|
||||||
|
</Container>
|
||||||
|
|
||||||
|
{ isTaxonomyListLoaded && isContentTaxonomyTagsLoaded && (
|
||||||
|
<Container
|
||||||
|
className="bg-white position-sticky p-3.5 box-shadow-up-2 tags-drawer-footer"
|
||||||
|
>
|
||||||
|
<div className="d-flex justify-content-end">
|
||||||
|
{ commitGlobalStagedTagsStatus !== 'loading' ? (
|
||||||
|
<Stack direction="horizontal" gap={2}>
|
||||||
|
<Button
|
||||||
|
className="font-weight-bold tags-drawer-cancel-button"
|
||||||
|
variant="tertiary"
|
||||||
|
onClick={isEditMode
|
||||||
|
? toReadMode
|
||||||
|
: onCloseDrawer}
|
||||||
|
>
|
||||||
|
{ intl.formatMessage(isEditMode
|
||||||
|
? messages.tagsDrawerCancelButtonText
|
||||||
|
: messages.tagsDrawerCloseButtonText)}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="dark"
|
||||||
|
className="rounded-0"
|
||||||
|
onClick={isEditMode
|
||||||
|
? commitGlobalStagedTags
|
||||||
|
: toEditMode}
|
||||||
|
>
|
||||||
|
{ intl.formatMessage(isEditMode
|
||||||
|
? messages.tagsDrawerSaveButtonText
|
||||||
|
: messages.tagsDrawerEditTagsButtonText)}
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
)
|
||||||
|
: (
|
||||||
|
<Spinner
|
||||||
|
animation="border"
|
||||||
|
size="xl"
|
||||||
|
screenReaderText={intl.formatMessage(messages.loadingMessage)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</Container>
|
||||||
|
)}
|
||||||
|
{/* istanbul ignore next */
|
||||||
|
toastMessage && (
|
||||||
|
<Toast
|
||||||
|
show
|
||||||
|
onClose={closeToast}
|
||||||
|
>
|
||||||
|
{toastMessage}
|
||||||
|
</Toast>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</ContentTagsDrawerContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
ContentTagsDrawer.propTypes = {
|
||||||
|
id: PropTypes.string,
|
||||||
|
onClose: PropTypes.func,
|
||||||
|
};
|
||||||
|
|
||||||
|
ContentTagsDrawer.defaultProps = {
|
||||||
|
id: undefined,
|
||||||
|
onClose: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ContentTagsDrawer;
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
min-width: max(500px, 33vw);
|
min-width: max(500px, 33vw);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media only screen and (width <= 500px) {
|
@media only screen and (max-width: 500px) {
|
||||||
.pgn__sheet-component:has(#content-tags-drawer) {
|
.pgn__sheet-component:has(#content-tags-drawer) {
|
||||||
min-width: 100vw;
|
min-width: 100vw;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,111 +1,589 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||||
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||||
import {
|
import {
|
||||||
|
act,
|
||||||
fireEvent,
|
fireEvent,
|
||||||
initializeMocks,
|
|
||||||
render,
|
render,
|
||||||
waitFor,
|
waitFor,
|
||||||
screen,
|
screen,
|
||||||
within,
|
within,
|
||||||
} from '../testUtils';
|
} from '@testing-library/react';
|
||||||
|
|
||||||
import ContentTagsDrawer from './ContentTagsDrawer';
|
import ContentTagsDrawer from './ContentTagsDrawer';
|
||||||
|
import {
|
||||||
|
useContentTaxonomyTagsData,
|
||||||
|
useContentData,
|
||||||
|
useTaxonomyTagsData,
|
||||||
|
useContentTaxonomyTagsUpdater,
|
||||||
|
} from './data/apiHooks';
|
||||||
|
import { getTaxonomyListData } from '../taxonomy/data/api';
|
||||||
import messages from './messages';
|
import messages from './messages';
|
||||||
import { ContentTagsDrawerSheetContext } from './common/context';
|
import { ContentTagsDrawerSheetContext } from './common/context';
|
||||||
import {
|
import { languageExportId } from './utils';
|
||||||
mockContentData,
|
|
||||||
mockContentTaxonomyTagsData,
|
|
||||||
mockTaxonomyListData,
|
|
||||||
mockTaxonomyTagsData,
|
|
||||||
} from './data/api.mocks';
|
|
||||||
import { getContentTaxonomyTagsApiUrl } from './data/api';
|
|
||||||
|
|
||||||
const path = '/content/:contentId?/*';
|
const contentId = 'block-v1:SampleTaxonomyOrg1+STC1+2023_1+type@vertical+block@7f47fe2dbcaf47c5a071671c741fe1ab';
|
||||||
const mockOnClose = jest.fn();
|
const mockOnClose = jest.fn();
|
||||||
|
const mockMutate = jest.fn();
|
||||||
const mockSetBlockingSheet = jest.fn();
|
const mockSetBlockingSheet = jest.fn();
|
||||||
const mockNavigate = jest.fn();
|
const mockNavigate = jest.fn();
|
||||||
mockContentTaxonomyTagsData.applyMock();
|
|
||||||
mockTaxonomyListData.applyMock();
|
|
||||||
mockTaxonomyTagsData.applyMock();
|
|
||||||
mockContentData.applyMock();
|
|
||||||
|
|
||||||
const {
|
|
||||||
stagedTagsId,
|
|
||||||
otherTagsId,
|
|
||||||
languageWithTagsId,
|
|
||||||
languageWithoutTagsId,
|
|
||||||
largeTagsId,
|
|
||||||
emptyTagsId,
|
|
||||||
} = mockContentTaxonomyTagsData;
|
|
||||||
|
|
||||||
jest.mock('react-router-dom', () => ({
|
jest.mock('react-router-dom', () => ({
|
||||||
...jest.requireActual('react-router-dom'),
|
...jest.requireActual('react-router-dom'),
|
||||||
|
useParams: () => ({
|
||||||
|
contentId,
|
||||||
|
}),
|
||||||
useNavigate: () => mockNavigate,
|
useNavigate: () => mockNavigate,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const renderDrawer = (contentId, drawerParams = {}) => (
|
// FIXME: replace these mocks with API mocks
|
||||||
render(
|
jest.mock('./data/apiHooks', () => ({
|
||||||
<ContentTagsDrawerSheetContext.Provider value={drawerParams}>
|
useContentTaxonomyTagsData: jest.fn(() => {}),
|
||||||
<ContentTagsDrawer {...drawerParams} />
|
useContentData: jest.fn(() => ({
|
||||||
</ContentTagsDrawerSheetContext.Provider>,
|
isSuccess: false,
|
||||||
{ path, params: { contentId } },
|
data: {},
|
||||||
)
|
})),
|
||||||
|
useContentTaxonomyTagsUpdater: jest.fn(() => ({
|
||||||
|
isError: false,
|
||||||
|
mutate: mockMutate,
|
||||||
|
})),
|
||||||
|
useTaxonomyTagsData: jest.fn(() => ({
|
||||||
|
hasMorePages: false,
|
||||||
|
tagPages: {
|
||||||
|
isLoading: true,
|
||||||
|
isError: false,
|
||||||
|
canAddTag: false,
|
||||||
|
data: [],
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
}));
|
||||||
|
|
||||||
|
jest.mock('../taxonomy/data/api', () => ({
|
||||||
|
// By default, the mock taxonomy list will never load (promise never resolves):
|
||||||
|
getTaxonomyListData: jest.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const queryClient = new QueryClient();
|
||||||
|
|
||||||
|
const RootWrapper = (params) => (
|
||||||
|
<ContentTagsDrawerSheetContext.Provider value={params}>
|
||||||
|
<IntlProvider locale="en" messages={{}}>
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
|
<ContentTagsDrawer {...params} />
|
||||||
|
</QueryClientProvider>
|
||||||
|
</IntlProvider>
|
||||||
|
</ContentTagsDrawerSheetContext.Provider>
|
||||||
);
|
);
|
||||||
|
|
||||||
describe('<ContentTagsDrawer />', () => {
|
describe('<ContentTagsDrawer />', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
initializeMocks();
|
jest.clearAllMocks();
|
||||||
|
await queryClient.resetQueries();
|
||||||
|
// By default, we mock the API call with a promise that never resolves.
|
||||||
|
// You can override this in specific test.
|
||||||
|
getTaxonomyListData.mockReturnValue(new Promise(() => {}));
|
||||||
|
useContentTaxonomyTagsUpdater.mockReturnValue({
|
||||||
|
isError: false,
|
||||||
|
mutate: mockMutate,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const setupMockDataForStagedTagsTesting = () => {
|
||||||
|
useContentTaxonomyTagsData.mockReturnValue({
|
||||||
|
isSuccess: true,
|
||||||
|
data: {
|
||||||
|
taxonomies: [
|
||||||
|
{
|
||||||
|
name: 'Taxonomy 1',
|
||||||
|
taxonomyId: 123,
|
||||||
|
canTagObject: true,
|
||||||
|
tags: [
|
||||||
|
{
|
||||||
|
value: 'Tag 1',
|
||||||
|
lineage: ['Tag 1'],
|
||||||
|
canDeleteObjecttag: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 'Tag 2',
|
||||||
|
lineage: ['Tag 2'],
|
||||||
|
canDeleteObjecttag: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
getTaxonomyListData.mockResolvedValue({
|
||||||
|
results: [
|
||||||
|
{
|
||||||
|
id: 123,
|
||||||
|
name: 'Taxonomy 1',
|
||||||
|
description: 'This is a description 1',
|
||||||
|
canTagObject: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
useTaxonomyTagsData.mockReturnValue({
|
||||||
|
hasMorePages: false,
|
||||||
|
canAddTag: false,
|
||||||
|
tagPages: {
|
||||||
|
isLoading: false,
|
||||||
|
isError: false,
|
||||||
|
data: [{
|
||||||
|
value: 'Tag 1',
|
||||||
|
externalId: null,
|
||||||
|
childCount: 0,
|
||||||
|
depth: 0,
|
||||||
|
parentValue: null,
|
||||||
|
id: 12345,
|
||||||
|
subTagsUrl: null,
|
||||||
|
canChangeTag: false,
|
||||||
|
canDeleteTag: false,
|
||||||
|
}, {
|
||||||
|
value: 'Tag 2',
|
||||||
|
externalId: null,
|
||||||
|
childCount: 0,
|
||||||
|
depth: 0,
|
||||||
|
parentValue: null,
|
||||||
|
id: 12346,
|
||||||
|
subTagsUrl: null,
|
||||||
|
canChangeTag: false,
|
||||||
|
canDeleteTag: false,
|
||||||
|
}, {
|
||||||
|
value: 'Tag 3',
|
||||||
|
externalId: null,
|
||||||
|
childCount: 0,
|
||||||
|
depth: 0,
|
||||||
|
parentValue: null,
|
||||||
|
id: 12347,
|
||||||
|
subTagsUrl: null,
|
||||||
|
canChangeTag: false,
|
||||||
|
canDeleteTag: false,
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const setupMockDataWithOtherTagsTestings = () => {
|
||||||
|
useContentTaxonomyTagsData.mockReturnValue({
|
||||||
|
isSuccess: true,
|
||||||
|
data: {
|
||||||
|
taxonomies: [
|
||||||
|
{
|
||||||
|
name: 'Taxonomy 1',
|
||||||
|
taxonomyId: 123,
|
||||||
|
canTagObject: true,
|
||||||
|
tags: [
|
||||||
|
{
|
||||||
|
value: 'Tag 1',
|
||||||
|
lineage: ['Tag 1'],
|
||||||
|
canDeleteObjecttag: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 'Tag 2',
|
||||||
|
lineage: ['Tag 2'],
|
||||||
|
canDeleteObjecttag: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Taxonomy 2',
|
||||||
|
taxonomyId: 1234,
|
||||||
|
canTagObject: false,
|
||||||
|
tags: [
|
||||||
|
{
|
||||||
|
value: 'Tag 3',
|
||||||
|
lineage: ['Tag 3'],
|
||||||
|
canDeleteObjecttag: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 'Tag 4',
|
||||||
|
lineage: ['Tag 4'],
|
||||||
|
canDeleteObjecttag: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
getTaxonomyListData.mockResolvedValue({
|
||||||
|
results: [
|
||||||
|
{
|
||||||
|
id: 123,
|
||||||
|
name: 'Taxonomy 1',
|
||||||
|
description: 'This is a description 1',
|
||||||
|
canTagObject: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
useTaxonomyTagsData.mockReturnValue({
|
||||||
|
hasMorePages: false,
|
||||||
|
canAddTag: false,
|
||||||
|
tagPages: {
|
||||||
|
isLoading: false,
|
||||||
|
isError: false,
|
||||||
|
data: [{
|
||||||
|
value: 'Tag 1',
|
||||||
|
externalId: null,
|
||||||
|
childCount: 0,
|
||||||
|
depth: 0,
|
||||||
|
parentValue: null,
|
||||||
|
id: 12345,
|
||||||
|
subTagsUrl: null,
|
||||||
|
canChangeTag: false,
|
||||||
|
canDeleteTag: false,
|
||||||
|
}, {
|
||||||
|
value: 'Tag 2',
|
||||||
|
externalId: null,
|
||||||
|
childCount: 0,
|
||||||
|
depth: 0,
|
||||||
|
parentValue: null,
|
||||||
|
id: 12346,
|
||||||
|
subTagsUrl: null,
|
||||||
|
canChangeTag: false,
|
||||||
|
canDeleteTag: false,
|
||||||
|
}, {
|
||||||
|
value: 'Tag 3',
|
||||||
|
externalId: null,
|
||||||
|
childCount: 0,
|
||||||
|
depth: 0,
|
||||||
|
parentValue: null,
|
||||||
|
id: 12347,
|
||||||
|
subTagsUrl: null,
|
||||||
|
canChangeTag: false,
|
||||||
|
canDeleteTag: false,
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const setupMockDataLanguageTaxonomyTestings = (hasTags) => {
|
||||||
|
useContentTaxonomyTagsData.mockReturnValue({
|
||||||
|
isSuccess: true,
|
||||||
|
data: {
|
||||||
|
taxonomies: [
|
||||||
|
{
|
||||||
|
name: 'Languages',
|
||||||
|
taxonomyId: 123,
|
||||||
|
exportId: languageExportId,
|
||||||
|
canTagObject: true,
|
||||||
|
tags: hasTags ? [
|
||||||
|
{
|
||||||
|
value: 'Tag 1',
|
||||||
|
lineage: ['Tag 1'],
|
||||||
|
canDeleteObjecttag: true,
|
||||||
|
},
|
||||||
|
] : [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Taxonomy 1',
|
||||||
|
taxonomyId: 1234,
|
||||||
|
canTagObject: true,
|
||||||
|
tags: [
|
||||||
|
{
|
||||||
|
value: 'Tag 1',
|
||||||
|
lineage: ['Tag 1'],
|
||||||
|
canDeleteObjecttag: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 'Tag 2',
|
||||||
|
lineage: ['Tag 2'],
|
||||||
|
canDeleteObjecttag: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
getTaxonomyListData.mockResolvedValue({
|
||||||
|
results: [
|
||||||
|
{
|
||||||
|
id: 123,
|
||||||
|
name: 'Languages',
|
||||||
|
description: 'This is a description 1',
|
||||||
|
exportId: languageExportId,
|
||||||
|
canTagObject: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1234,
|
||||||
|
name: 'Taxonomy 1',
|
||||||
|
description: 'This is a description 2',
|
||||||
|
canTagObject: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
useTaxonomyTagsData.mockReturnValue({
|
||||||
|
hasMorePages: false,
|
||||||
|
canAddTag: false,
|
||||||
|
tagPages: {
|
||||||
|
isLoading: false,
|
||||||
|
isError: false,
|
||||||
|
data: [{
|
||||||
|
value: 'Tag 1',
|
||||||
|
externalId: null,
|
||||||
|
childCount: 0,
|
||||||
|
depth: 0,
|
||||||
|
parentValue: null,
|
||||||
|
id: 12345,
|
||||||
|
subTagsUrl: null,
|
||||||
|
canChangeTag: false,
|
||||||
|
canDeleteTag: false,
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const setupLargeMockDataForStagedTagsTesting = () => {
|
||||||
|
useContentTaxonomyTagsData.mockReturnValue({
|
||||||
|
isSuccess: true,
|
||||||
|
data: {
|
||||||
|
taxonomies: [
|
||||||
|
{
|
||||||
|
name: 'Taxonomy 1',
|
||||||
|
taxonomyId: 123,
|
||||||
|
canTagObject: true,
|
||||||
|
tags: [
|
||||||
|
{
|
||||||
|
value: 'Tag 1',
|
||||||
|
lineage: ['Tag 1'],
|
||||||
|
canDeleteObjecttag: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 'Tag 2',
|
||||||
|
lineage: ['Tag 2'],
|
||||||
|
canDeleteObjecttag: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Taxonomy 2',
|
||||||
|
taxonomyId: 124,
|
||||||
|
canTagObject: true,
|
||||||
|
tags: [
|
||||||
|
{
|
||||||
|
value: 'Tag 1',
|
||||||
|
lineage: ['Tag 1'],
|
||||||
|
canDeleteObjecttag: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Taxonomy 3',
|
||||||
|
taxonomyId: 125,
|
||||||
|
canTagObject: true,
|
||||||
|
tags: [
|
||||||
|
{
|
||||||
|
value: 'Tag 1.1.1',
|
||||||
|
lineage: ['Tag 1', 'Tag 1.1', 'Tag 1.1.1'],
|
||||||
|
canDeleteObjecttag: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '(B) Taxonomy 4',
|
||||||
|
taxonomyId: 126,
|
||||||
|
canTagObject: true,
|
||||||
|
tags: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '(A) Taxonomy 5',
|
||||||
|
taxonomyId: 127,
|
||||||
|
canTagObject: true,
|
||||||
|
tags: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
getTaxonomyListData.mockResolvedValue({
|
||||||
|
results: [
|
||||||
|
{
|
||||||
|
id: 123,
|
||||||
|
name: 'Taxonomy 1',
|
||||||
|
description: 'This is a description 1',
|
||||||
|
canTagObject: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 124,
|
||||||
|
name: 'Taxonomy 2',
|
||||||
|
description: 'This is a description 2',
|
||||||
|
canTagObject: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 125,
|
||||||
|
name: 'Taxonomy 3',
|
||||||
|
description: 'This is a description 3',
|
||||||
|
canTagObject: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 127,
|
||||||
|
name: '(A) Taxonomy 5',
|
||||||
|
description: 'This is a description 5',
|
||||||
|
canTagObject: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 126,
|
||||||
|
name: '(B) Taxonomy 4',
|
||||||
|
description: 'This is a description 4',
|
||||||
|
canTagObject: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
useTaxonomyTagsData.mockReturnValue({
|
||||||
|
hasMorePages: false,
|
||||||
|
canAddTag: false,
|
||||||
|
tagPages: {
|
||||||
|
isLoading: false,
|
||||||
|
isError: false,
|
||||||
|
data: [{
|
||||||
|
value: 'Tag 1',
|
||||||
|
externalId: null,
|
||||||
|
childCount: 0,
|
||||||
|
depth: 0,
|
||||||
|
parentValue: null,
|
||||||
|
id: 12345,
|
||||||
|
subTagsUrl: null,
|
||||||
|
canChangeTag: false,
|
||||||
|
canDeleteTag: false,
|
||||||
|
}, {
|
||||||
|
value: 'Tag 2',
|
||||||
|
externalId: null,
|
||||||
|
childCount: 0,
|
||||||
|
depth: 0,
|
||||||
|
parentValue: null,
|
||||||
|
id: 12346,
|
||||||
|
subTagsUrl: null,
|
||||||
|
canChangeTag: false,
|
||||||
|
canDeleteTag: false,
|
||||||
|
}, {
|
||||||
|
value: 'Tag 3',
|
||||||
|
externalId: null,
|
||||||
|
childCount: 0,
|
||||||
|
depth: 0,
|
||||||
|
parentValue: null,
|
||||||
|
id: 12347,
|
||||||
|
subTagsUrl: null,
|
||||||
|
canChangeTag: false,
|
||||||
|
canDeleteTag: false,
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
it('should render page and page title correctly', () => {
|
it('should render page and page title correctly', () => {
|
||||||
renderDrawer(stagedTagsId);
|
setupMockDataForStagedTagsTesting();
|
||||||
expect(screen.getByText('Manage tags')).toBeInTheDocument();
|
const { getByText } = render(<RootWrapper />);
|
||||||
|
expect(getByText('Manage tags')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows spinner before the content data query is complete', async () => {
|
it('shows spinner before the content data query is complete', async () => {
|
||||||
renderDrawer(stagedTagsId);
|
await act(async () => {
|
||||||
const spinner = (await screen.findAllByRole('status'))[0];
|
const { getAllByRole } = render(<RootWrapper />);
|
||||||
expect(spinner.textContent).toEqual('Loading'); // Uses <Spinner />
|
const spinner = getAllByRole('status')[0];
|
||||||
|
expect(spinner.textContent).toEqual('Loading'); // Uses <Spinner />
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows spinner before the taxonomy tags query is complete', async () => {
|
it('shows spinner before the taxonomy tags query is complete', async () => {
|
||||||
renderDrawer(stagedTagsId);
|
await act(async () => {
|
||||||
const spinner = (await screen.findAllByRole('status'))[1];
|
const { getAllByRole } = render(<RootWrapper />);
|
||||||
expect(spinner.textContent).toEqual('Loading...'); // Uses <Loading />
|
const spinner = getAllByRole('status')[1];
|
||||||
|
expect(spinner.textContent).toEqual('Loading...'); // Uses <Loading />
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows the content display name after the query is complete in drawer variant', async () => {
|
it('shows the content display name after the query is complete', async () => {
|
||||||
renderDrawer('test');
|
useContentData.mockReturnValue({
|
||||||
expect(await screen.findByText('Loading...')).toBeInTheDocument();
|
isSuccess: true,
|
||||||
expect(await screen.findByText('Unit 1')).toBeInTheDocument();
|
data: {
|
||||||
expect(await screen.findByText('Manage tags')).toBeInTheDocument();
|
displayName: 'Unit 1',
|
||||||
});
|
},
|
||||||
|
});
|
||||||
it('shows the content display name after the query is complete in component variant', async () => {
|
await act(async () => {
|
||||||
renderDrawer('test', { variant: 'component' });
|
const { getByText } = render(<RootWrapper />);
|
||||||
expect(await screen.findByText('Loading...')).toBeInTheDocument();
|
expect(getByText('Unit 1')).toBeInTheDocument();
|
||||||
expect(screen.queryByText('Unit 1')).not.toBeInTheDocument();
|
});
|
||||||
expect(screen.queryByText('Manage tags')).not.toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows content using params', async () => {
|
it('shows content using params', async () => {
|
||||||
renderDrawer(undefined, { id: 'test' });
|
useContentData.mockReturnValue({
|
||||||
expect(await screen.findByText('Loading...')).toBeInTheDocument();
|
isSuccess: true,
|
||||||
expect(await screen.findByText('Unit 1')).toBeInTheDocument();
|
data: {
|
||||||
expect(await screen.findByText('Manage tags')).toBeInTheDocument();
|
displayName: 'Unit 1',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
render(<RootWrapper id={contentId} />);
|
||||||
|
expect(screen.getByText('Unit 1')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows the taxonomies data including tag numbers after the query is complete', async () => {
|
it('shows the taxonomies data including tag numbers after the query is complete', async () => {
|
||||||
const { container } = renderDrawer(largeTagsId);
|
useContentTaxonomyTagsData.mockReturnValue({
|
||||||
await screen.findByText('Taxonomy 1');
|
isSuccess: true,
|
||||||
await screen.findByText('Taxonomy 2');
|
data: {
|
||||||
const tagCountBadges = container.getElementsByClassName('taxonomy-tags-count-chip');
|
taxonomies: [
|
||||||
expect(tagCountBadges[0].textContent).toBe('3');
|
{
|
||||||
expect(tagCountBadges[1].textContent).toBe('2');
|
name: 'Taxonomy 1',
|
||||||
|
taxonomyId: 123,
|
||||||
|
canTagObject: true,
|
||||||
|
tags: [
|
||||||
|
{
|
||||||
|
value: 'Tag 1',
|
||||||
|
lineage: ['Tag 1'],
|
||||||
|
canDeleteObjecttag: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 'Tag 2',
|
||||||
|
lineage: ['Tag 2'],
|
||||||
|
canDeleteObjecttag: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Taxonomy 2',
|
||||||
|
taxonomyId: 124,
|
||||||
|
canTagObject: true,
|
||||||
|
tags: [
|
||||||
|
{
|
||||||
|
value: 'Tag 3',
|
||||||
|
lineage: ['Tag 3'],
|
||||||
|
canDeleteObjecttag: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
getTaxonomyListData.mockResolvedValue({
|
||||||
|
results: [{
|
||||||
|
id: 123,
|
||||||
|
name: 'Taxonomy 1',
|
||||||
|
description: 'This is a description 1',
|
||||||
|
canTagObject: false,
|
||||||
|
}, {
|
||||||
|
id: 124,
|
||||||
|
name: 'Taxonomy 2',
|
||||||
|
description: 'This is a description 2',
|
||||||
|
canTagObject: false,
|
||||||
|
}],
|
||||||
|
});
|
||||||
|
await act(async () => {
|
||||||
|
const { container, getByText } = render(<RootWrapper />);
|
||||||
|
await waitFor(() => { expect(getByText('Taxonomy 1')).toBeInTheDocument(); });
|
||||||
|
expect(getByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
|
expect(getByText('Taxonomy 2')).toBeInTheDocument();
|
||||||
|
const tagCountBadges = container.getElementsByClassName('taxonomy-tags-count-chip');
|
||||||
|
expect(tagCountBadges[0].textContent).toBe('2');
|
||||||
|
expect(tagCountBadges[1].textContent).toBe('1');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be read only on first render on drawer variant', async () => {
|
it('should be read only on first render', async () => {
|
||||||
renderDrawer(stagedTagsId);
|
setupMockDataForStagedTagsTesting();
|
||||||
|
render(<RootWrapper />);
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
expect(screen.getByRole('button', { name: /close/i }));
|
|
||||||
expect(screen.getByRole('button', { name: /edit tags/i }));
|
|
||||||
|
|
||||||
// Not show delete tag buttons
|
// Not show delete tag buttons
|
||||||
expect(screen.queryByRole('button', { name: /delete/i })).not.toBeInTheDocument();
|
expect(screen.queryByRole('button', { name: /delete/i })).not.toBeInTheDocument();
|
||||||
@@ -120,26 +598,9 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
expect(screen.queryByRole('button', { name: /save/i })).not.toBeInTheDocument();
|
expect(screen.queryByRole('button', { name: /save/i })).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be read only on first render on component variant', async () => {
|
it('should change to edit mode when click on `Edit tags`', async () => {
|
||||||
renderDrawer(stagedTagsId, { variant: 'component' });
|
setupMockDataForStagedTagsTesting();
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
render(<RootWrapper />);
|
||||||
expect(screen.getByRole('button', { name: /manage tags/i }));
|
|
||||||
|
|
||||||
// Not show delete tag buttons
|
|
||||||
expect(screen.queryByRole('button', { name: /delete/i })).not.toBeInTheDocument();
|
|
||||||
|
|
||||||
// Not show add a tag select
|
|
||||||
expect(screen.queryByText(/add a tag/i)).not.toBeInTheDocument();
|
|
||||||
|
|
||||||
// Not show cancel button
|
|
||||||
expect(screen.queryByRole('button', { name: /cancel/i })).not.toBeInTheDocument();
|
|
||||||
|
|
||||||
// Not show save button
|
|
||||||
expect(screen.queryByRole('button', { name: /save/i })).not.toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should change to edit mode when click on `Edit tags` on drawer variant', async () => {
|
|
||||||
renderDrawer(stagedTagsId);
|
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
const editTagsButton = screen.getByRole('button', {
|
const editTagsButton = screen.getByRole('button', {
|
||||||
name: /edit tags/i,
|
name: /edit tags/i,
|
||||||
@@ -161,31 +622,9 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
expect(screen.getByRole('button', { name: /save/i })).toBeInTheDocument();
|
expect(screen.getByRole('button', { name: /save/i })).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should change to edit mode when click on `Manage tags` on component variant', async () => {
|
it('should change to read mode when click on `Cancel`', async () => {
|
||||||
renderDrawer(stagedTagsId, { variant: 'component' });
|
setupMockDataForStagedTagsTesting();
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
render(<RootWrapper />);
|
||||||
const manageTagsButton = screen.getByRole('button', {
|
|
||||||
name: /manage tags/i,
|
|
||||||
});
|
|
||||||
fireEvent.click(manageTagsButton);
|
|
||||||
|
|
||||||
// Show delete tag buttons
|
|
||||||
expect(screen.getAllByRole('button', {
|
|
||||||
name: /delete/i,
|
|
||||||
}).length).toBe(2);
|
|
||||||
|
|
||||||
// Show add a tag select
|
|
||||||
expect(screen.getByText(/add a tag/i)).toBeInTheDocument();
|
|
||||||
|
|
||||||
// Show cancel button
|
|
||||||
expect(screen.getByRole('button', { name: /cancel/i })).toBeInTheDocument();
|
|
||||||
|
|
||||||
// Show save button
|
|
||||||
expect(screen.getByRole('button', { name: /save/i })).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should change to read mode when click on `Cancel` on drawer variant', async () => {
|
|
||||||
renderDrawer(stagedTagsId);
|
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
const editTagsButton = screen.getByRole('button', {
|
const editTagsButton = screen.getByRole('button', {
|
||||||
name: /edit tags/i,
|
name: /edit tags/i,
|
||||||
@@ -210,57 +649,21 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
expect(screen.queryByRole('button', { name: /save/i })).not.toBeInTheDocument();
|
expect(screen.queryByRole('button', { name: /save/i })).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should change to read mode when click on `Cancel` on component variant', async () => {
|
it('shows spinner when loading commit tags', async () => {
|
||||||
renderDrawer(stagedTagsId, { variant: 'component' });
|
setupMockDataForStagedTagsTesting();
|
||||||
|
useContentTaxonomyTagsUpdater.mockReturnValue({
|
||||||
|
status: 'loading',
|
||||||
|
isError: false,
|
||||||
|
mutate: mockMutate,
|
||||||
|
});
|
||||||
|
render(<RootWrapper />);
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
const manageTagsButton = screen.getByRole('button', {
|
expect(screen.getByRole('status')).toBeInTheDocument();
|
||||||
name: /manage tags/i,
|
|
||||||
});
|
|
||||||
fireEvent.click(manageTagsButton);
|
|
||||||
|
|
||||||
const cancelButton = screen.getByRole('button', {
|
|
||||||
name: /cancel/i,
|
|
||||||
});
|
|
||||||
fireEvent.click(cancelButton);
|
|
||||||
|
|
||||||
// Not show delete tag buttons
|
|
||||||
expect(screen.queryByRole('button', { name: /delete/i })).not.toBeInTheDocument();
|
|
||||||
|
|
||||||
// Not show add a tag select
|
|
||||||
expect(screen.queryByText(/add a tag/i)).not.toBeInTheDocument();
|
|
||||||
|
|
||||||
// Not show cancel button
|
|
||||||
expect(screen.queryByRole('button', { name: /cancel/i })).not.toBeInTheDocument();
|
|
||||||
|
|
||||||
// Not show save button
|
|
||||||
expect(screen.queryByRole('button', { name: /save/i })).not.toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test.each([
|
|
||||||
{
|
|
||||||
variant: 'drawer',
|
|
||||||
editButton: /edit tags/i,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
variant: 'component',
|
|
||||||
editButton: /manage tags/i,
|
|
||||||
},
|
|
||||||
])(
|
|
||||||
'should hide "$editButton" button on $variant variant if not allowed to tag object',
|
|
||||||
async ({ variant, editButton }) => {
|
|
||||||
renderDrawer(stagedTagsId, { variant, readOnly: true });
|
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
|
||||||
|
|
||||||
expect(screen.queryByRole('button', { name: editButton })).not.toBeInTheDocument();
|
|
||||||
expect(screen.queryByRole('button', { name: /delete/i })).not.toBeInTheDocument();
|
|
||||||
expect(screen.queryByText(/add a tag/i)).not.toBeInTheDocument();
|
|
||||||
expect(screen.queryByRole('button', { name: /cancel/i })).not.toBeInTheDocument();
|
|
||||||
expect(screen.queryByRole('button', { name: /save/i })).not.toBeInTheDocument();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
it('should test adding a content tag to the staged tags for a taxonomy', async () => {
|
it('should test adding a content tag to the staged tags for a taxonomy', async () => {
|
||||||
renderDrawer(stagedTagsId);
|
setupMockDataForStagedTagsTesting();
|
||||||
|
render(<RootWrapper />);
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
|
|
||||||
// To edit mode
|
// To edit mode
|
||||||
@@ -275,7 +678,7 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
fireEvent.mouseDown(addTagsButton);
|
fireEvent.mouseDown(addTagsButton);
|
||||||
|
|
||||||
// Tag 3 should only appear in dropdown selector, (i.e. the dropdown is open, since Tag 3 is not applied)
|
// Tag 3 should only appear in dropdown selector, (i.e. the dropdown is open, since Tag 3 is not applied)
|
||||||
expect((await screen.findAllByText('Tag 3')).length).toBe(1);
|
expect(screen.getAllByText('Tag 3').length).toBe(1);
|
||||||
|
|
||||||
// Click to check Tag 3
|
// Click to check Tag 3
|
||||||
const tag3 = screen.getByText('Tag 3');
|
const tag3 = screen.getByText('Tag 3');
|
||||||
@@ -286,7 +689,8 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should test removing a staged content from a taxonomy', async () => {
|
it('should test removing a staged content from a taxonomy', async () => {
|
||||||
renderDrawer(stagedTagsId);
|
setupMockDataForStagedTagsTesting();
|
||||||
|
render(<RootWrapper />);
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
|
|
||||||
// To edit mode
|
// To edit mode
|
||||||
@@ -301,7 +705,7 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
fireEvent.mouseDown(addTagsButton);
|
fireEvent.mouseDown(addTagsButton);
|
||||||
|
|
||||||
// Tag 3 should only appear in dropdown selector, (i.e. the dropdown is open, since Tag 3 is not applied)
|
// Tag 3 should only appear in dropdown selector, (i.e. the dropdown is open, since Tag 3 is not applied)
|
||||||
expect((await screen.findAllByText('Tag 3')).length).toBe(1);
|
expect(screen.getAllByText('Tag 3').length).toBe(1);
|
||||||
|
|
||||||
// Click to check Tag 3
|
// Click to check Tag 3
|
||||||
const tag3 = screen.getByText('Tag 3');
|
const tag3 = screen.getByText('Tag 3');
|
||||||
@@ -316,9 +720,11 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should test clearing staged tags for a taxonomy', async () => {
|
it('should test clearing staged tags for a taxonomy', async () => {
|
||||||
|
setupMockDataForStagedTagsTesting();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
container,
|
container,
|
||||||
} = renderDrawer(stagedTagsId);
|
} = render(<RootWrapper />);
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
|
|
||||||
// To edit mode
|
// To edit mode
|
||||||
@@ -333,7 +739,7 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
fireEvent.mouseDown(addTagsButton);
|
fireEvent.mouseDown(addTagsButton);
|
||||||
|
|
||||||
// Tag 3 should only appear in dropdown selector, (i.e. the dropdown is open, since Tag 3 is not applied)
|
// Tag 3 should only appear in dropdown selector, (i.e. the dropdown is open, since Tag 3 is not applied)
|
||||||
expect((await screen.findAllByText('Tag 3')).length).toBe(1);
|
expect(screen.getAllByText('Tag 3').length).toBe(1);
|
||||||
|
|
||||||
// Click to check Tag 3
|
// Click to check Tag 3
|
||||||
const tag3 = screen.getByText('Tag 3');
|
const tag3 = screen.getByText('Tag 3');
|
||||||
@@ -352,7 +758,8 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should test adding global staged tags and cancel', async () => {
|
it('should test adding global staged tags and cancel', async () => {
|
||||||
renderDrawer(stagedTagsId);
|
setupMockDataForStagedTagsTesting();
|
||||||
|
render(<RootWrapper />);
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
|
|
||||||
// To edit mode
|
// To edit mode
|
||||||
@@ -367,7 +774,7 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
fireEvent.mouseDown(addTagsButton);
|
fireEvent.mouseDown(addTagsButton);
|
||||||
|
|
||||||
// Click to check Tag 3
|
// Click to check Tag 3
|
||||||
const tag3 = await screen.findByText(/tag 3/i);
|
const tag3 = screen.getByText(/tag 3/i);
|
||||||
fireEvent.click(tag3);
|
fireEvent.click(tag3);
|
||||||
|
|
||||||
// Click "Add tags" to save to global staged tags
|
// Click "Add tags" to save to global staged tags
|
||||||
@@ -383,8 +790,9 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
expect(screen.queryByText(/tag 3/i)).not.toBeInTheDocument();
|
expect(screen.queryByText(/tag 3/i)).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should test delete fetched tags and cancel', async () => {
|
it('should test delete feched tags and cancel', async () => {
|
||||||
renderDrawer(stagedTagsId);
|
setupMockDataForStagedTagsTesting();
|
||||||
|
render(<RootWrapper />);
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
|
|
||||||
// To edit mode
|
// To edit mode
|
||||||
@@ -394,7 +802,7 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
fireEvent.click(editTagsButton);
|
fireEvent.click(editTagsButton);
|
||||||
|
|
||||||
// Delete the tag
|
// Delete the tag
|
||||||
const tag = await screen.findByText(/tag 2/i);
|
const tag = screen.getByText(/tag 2/i);
|
||||||
const deleteButton = within(tag).getByRole('button', {
|
const deleteButton = within(tag).getByRole('button', {
|
||||||
name: /delete/i,
|
name: /delete/i,
|
||||||
});
|
});
|
||||||
@@ -410,7 +818,8 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should test delete global staged tags and cancel', async () => {
|
it('should test delete global staged tags and cancel', async () => {
|
||||||
renderDrawer(stagedTagsId);
|
setupMockDataForStagedTagsTesting();
|
||||||
|
render(<RootWrapper />);
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
|
|
||||||
// To edit mode
|
// To edit mode
|
||||||
@@ -425,7 +834,7 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
fireEvent.mouseDown(addTagsButton);
|
fireEvent.mouseDown(addTagsButton);
|
||||||
|
|
||||||
// Click to check Tag 3
|
// Click to check Tag 3
|
||||||
const tag3 = await screen.findByText(/tag 3/i);
|
const tag3 = screen.getByText(/tag 3/i);
|
||||||
fireEvent.click(tag3);
|
fireEvent.click(tag3);
|
||||||
|
|
||||||
// Click "Add tags" to save to global staged tags
|
// Click "Add tags" to save to global staged tags
|
||||||
@@ -450,8 +859,9 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
expect(screen.queryByText(/tag 3/i)).not.toBeInTheDocument();
|
expect(screen.queryByText(/tag 3/i)).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should test add removed fetched tags and cancel', async () => {
|
it('should test add removed feched tags and cancel', async () => {
|
||||||
renderDrawer(stagedTagsId);
|
setupMockDataForStagedTagsTesting();
|
||||||
|
render(<RootWrapper />);
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
|
|
||||||
// To edit mode
|
// To edit mode
|
||||||
@@ -461,7 +871,7 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
fireEvent.click(editTagsButton);
|
fireEvent.click(editTagsButton);
|
||||||
|
|
||||||
// Delete the tag
|
// Delete the tag
|
||||||
const tag = await screen.findByText(/tag 2/i);
|
const tag = screen.getByText(/tag 2/i);
|
||||||
const deleteButton = within(tag).getByRole('button', {
|
const deleteButton = within(tag).getByRole('button', {
|
||||||
name: /delete/i,
|
name: /delete/i,
|
||||||
});
|
});
|
||||||
@@ -475,7 +885,7 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
fireEvent.mouseDown(addTagsButton);
|
fireEvent.mouseDown(addTagsButton);
|
||||||
|
|
||||||
// Click to check Tag 2
|
// Click to check Tag 2
|
||||||
const tag2 = await screen.findByText(/tag 2/i);
|
const tag2 = screen.getByText(/tag 2/i);
|
||||||
fireEvent.click(tag2);
|
fireEvent.click(tag2);
|
||||||
|
|
||||||
// Click "Add tags" to save to global staged tags
|
// Click "Add tags" to save to global staged tags
|
||||||
@@ -492,7 +902,8 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should call onClose when cancel is clicked', async () => {
|
it('should call onClose when cancel is clicked', async () => {
|
||||||
renderDrawer(stagedTagsId, { onClose: mockOnClose });
|
setupMockDataForStagedTagsTesting();
|
||||||
|
render(<RootWrapper onClose={mockOnClose} />);
|
||||||
|
|
||||||
const cancelButton = await screen.findByRole('button', {
|
const cancelButton = await screen.findByRole('button', {
|
||||||
name: /close/i,
|
name: /close/i,
|
||||||
@@ -506,7 +917,7 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
it('should call closeManageTagsDrawer when Escape key is pressed and no selectable box is active', () => {
|
it('should call closeManageTagsDrawer when Escape key is pressed and no selectable box is active', () => {
|
||||||
const postMessageSpy = jest.spyOn(window.parent, 'postMessage');
|
const postMessageSpy = jest.spyOn(window.parent, 'postMessage');
|
||||||
|
|
||||||
const { container } = renderDrawer(stagedTagsId);
|
const { container } = render(<RootWrapper />);
|
||||||
|
|
||||||
fireEvent.keyDown(container, {
|
fireEvent.keyDown(container, {
|
||||||
key: 'Escape',
|
key: 'Escape',
|
||||||
@@ -518,7 +929,7 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should call `onClose` when Escape key is pressed and no selectable box is active', () => {
|
it('should call `onClose` when Escape key is pressed and no selectable box is active', () => {
|
||||||
const { container } = renderDrawer(stagedTagsId, { onClose: mockOnClose });
|
const { container } = render(<RootWrapper onClose={mockOnClose} />);
|
||||||
|
|
||||||
fireEvent.keyDown(container, {
|
fireEvent.keyDown(container, {
|
||||||
key: 'Escape',
|
key: 'Escape',
|
||||||
@@ -530,7 +941,7 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
it('should not call closeManageTagsDrawer when Escape key is pressed and a selectable box is active', () => {
|
it('should not call closeManageTagsDrawer when Escape key is pressed and a selectable box is active', () => {
|
||||||
const postMessageSpy = jest.spyOn(window.parent, 'postMessage');
|
const postMessageSpy = jest.spyOn(window.parent, 'postMessage');
|
||||||
|
|
||||||
const { container } = renderDrawer(stagedTagsId);
|
const { container } = render(<RootWrapper />);
|
||||||
|
|
||||||
// Simulate that the selectable box is open by adding an element with the data attribute
|
// Simulate that the selectable box is open by adding an element with the data attribute
|
||||||
const selectableBox = document.createElement('div');
|
const selectableBox = document.createElement('div');
|
||||||
@@ -550,7 +961,7 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not call `onClose` when Escape key is pressed and a selectable box is active', () => {
|
it('should not call `onClose` when Escape key is pressed and a selectable box is active', () => {
|
||||||
const { container } = renderDrawer(stagedTagsId, { onClose: mockOnClose });
|
const { container } = render(<RootWrapper onClose={mockOnClose} />);
|
||||||
|
|
||||||
// Simulate that the selectable box is open by adding an element with the data attribute
|
// Simulate that the selectable box is open by adding an element with the data attribute
|
||||||
const selectableBox = document.createElement('div');
|
const selectableBox = document.createElement('div');
|
||||||
@@ -569,7 +980,8 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
|
|
||||||
it('should not call closeManageTagsDrawer when Escape key is pressed and container is blocked', () => {
|
it('should not call closeManageTagsDrawer when Escape key is pressed and container is blocked', () => {
|
||||||
const postMessageSpy = jest.spyOn(window.parent, 'postMessage');
|
const postMessageSpy = jest.spyOn(window.parent, 'postMessage');
|
||||||
const { container } = renderDrawer(stagedTagsId, { blockingSheet: true });
|
|
||||||
|
const { container } = render(<RootWrapper blockingSheet />);
|
||||||
fireEvent.keyDown(container, {
|
fireEvent.keyDown(container, {
|
||||||
key: 'Escape',
|
key: 'Escape',
|
||||||
});
|
});
|
||||||
@@ -580,10 +992,7 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not call `onClose` when Escape key is pressed and container is blocked', () => {
|
it('should not call `onClose` when Escape key is pressed and container is blocked', () => {
|
||||||
const { container } = renderDrawer(stagedTagsId, {
|
const { container } = render(<RootWrapper blockingSheet onClose={mockOnClose} />);
|
||||||
blockingSheet: true,
|
|
||||||
onClose: mockOnClose,
|
|
||||||
});
|
|
||||||
fireEvent.keyDown(container, {
|
fireEvent.keyDown(container, {
|
||||||
key: 'Escape',
|
key: 'Escape',
|
||||||
});
|
});
|
||||||
@@ -592,10 +1001,8 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should call `setBlockingSheet` on add a tag', async () => {
|
it('should call `setBlockingSheet` on add a tag', async () => {
|
||||||
renderDrawer(stagedTagsId, {
|
setupMockDataForStagedTagsTesting();
|
||||||
blockingSheet: true,
|
render(<RootWrapper blockingSheet setBlockingSheet={mockSetBlockingSheet} />);
|
||||||
setBlockingSheet: mockSetBlockingSheet,
|
|
||||||
});
|
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
|
|
||||||
expect(mockSetBlockingSheet).toHaveBeenCalledWith(false);
|
expect(mockSetBlockingSheet).toHaveBeenCalledWith(false);
|
||||||
@@ -612,7 +1019,7 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
fireEvent.mouseDown(addTagsButton);
|
fireEvent.mouseDown(addTagsButton);
|
||||||
|
|
||||||
// Click to check Tag 3
|
// Click to check Tag 3
|
||||||
const tag3 = await screen.findByText(/tag 3/i);
|
const tag3 = screen.getByText(/tag 3/i);
|
||||||
fireEvent.click(tag3);
|
fireEvent.click(tag3);
|
||||||
|
|
||||||
// Click "Add tags" to save to global staged tags
|
// Click "Add tags" to save to global staged tags
|
||||||
@@ -623,10 +1030,8 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should call `setBlockingSheet` on delete a tag', async () => {
|
it('should call `setBlockingSheet` on delete a tag', async () => {
|
||||||
renderDrawer(stagedTagsId, {
|
setupMockDataForStagedTagsTesting();
|
||||||
blockingSheet: true,
|
render(<RootWrapper blockingSheet setBlockingSheet={mockSetBlockingSheet} />);
|
||||||
setBlockingSheet: mockSetBlockingSheet,
|
|
||||||
});
|
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
|
|
||||||
expect(mockSetBlockingSheet).toHaveBeenCalledWith(false);
|
expect(mockSetBlockingSheet).toHaveBeenCalledWith(false);
|
||||||
@@ -648,10 +1053,8 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should call `updateTags` mutation on save', async () => {
|
it('should call `updateTags` mutation on save', async () => {
|
||||||
const { axiosMock } = initializeMocks();
|
setupMockDataForStagedTagsTesting();
|
||||||
const url = getContentTaxonomyTagsApiUrl(stagedTagsId);
|
render(<RootWrapper />);
|
||||||
axiosMock.onPut(url).reply(200);
|
|
||||||
renderDrawer(stagedTagsId);
|
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
const editTagsButton = screen.getByRole('button', {
|
const editTagsButton = screen.getByRole('button', {
|
||||||
name: /edit tags/i,
|
name: /edit tags/i,
|
||||||
@@ -663,11 +1066,12 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
});
|
});
|
||||||
fireEvent.click(saveButton);
|
fireEvent.click(saveButton);
|
||||||
|
|
||||||
await waitFor(() => expect(axiosMock.history.put[0].url).toEqual(url));
|
expect(mockMutate).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should taxonomies must be ordered', async () => {
|
it('should taxonomies must be ordered', async () => {
|
||||||
renderDrawer(largeTagsId);
|
setupLargeMockDataForStagedTagsTesting();
|
||||||
|
render(<RootWrapper />);
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
|
|
||||||
// First, taxonomies with content sorted by count implicit
|
// First, taxonomies with content sorted by count implicit
|
||||||
@@ -687,14 +1091,18 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not show "Other tags" section', async () => {
|
it('should not show "Other tags" section', async () => {
|
||||||
renderDrawer(stagedTagsId);
|
setupMockDataForStagedTagsTesting();
|
||||||
|
|
||||||
|
render(<RootWrapper />);
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
|
|
||||||
expect(screen.queryByText('Other tags')).not.toBeInTheDocument();
|
expect(screen.queryByText('Other tags')).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show "Other tags" section', async () => {
|
it('should show "Other tags" section', async () => {
|
||||||
renderDrawer(otherTagsId);
|
setupMockDataWithOtherTagsTestings();
|
||||||
|
|
||||||
|
render(<RootWrapper />);
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
|
|
||||||
expect(screen.getByText('Other tags')).toBeInTheDocument();
|
expect(screen.getByText('Other tags')).toBeInTheDocument();
|
||||||
@@ -704,7 +1112,8 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should test delete "Other tags" and cancel', async () => {
|
it('should test delete "Other tags" and cancel', async () => {
|
||||||
renderDrawer(otherTagsId);
|
setupMockDataWithOtherTagsTestings();
|
||||||
|
render(<RootWrapper />);
|
||||||
expect(await screen.findByText('Taxonomy 2')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 2')).toBeInTheDocument();
|
||||||
|
|
||||||
// To edit mode
|
// To edit mode
|
||||||
@@ -730,18 +1139,40 @@ describe('<ContentTagsDrawer />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should show Language Taxonomy', async () => {
|
it('should show Language Taxonomy', async () => {
|
||||||
renderDrawer(languageWithTagsId);
|
setupMockDataLanguageTaxonomyTestings(true);
|
||||||
|
render(<RootWrapper />);
|
||||||
expect(await screen.findByText('Languages')).toBeInTheDocument();
|
expect(await screen.findByText('Languages')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should hide Language Taxonomy', async () => {
|
it('should hide Language Taxonomy', async () => {
|
||||||
renderDrawer(languageWithoutTagsId);
|
setupMockDataLanguageTaxonomyTestings(false);
|
||||||
|
render(<RootWrapper />);
|
||||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
|
||||||
|
|
||||||
expect(screen.queryByText('Languages')).not.toBeInTheDocument();
|
expect(screen.queryByText('Languages')).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show empty drawer message', async () => {
|
it('should show empty drawer message', async () => {
|
||||||
renderDrawer(emptyTagsId);
|
useContentTaxonomyTagsData.mockReturnValue({
|
||||||
|
isSuccess: true,
|
||||||
|
data: {
|
||||||
|
taxonomies: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
getTaxonomyListData.mockResolvedValue({
|
||||||
|
results: [],
|
||||||
|
});
|
||||||
|
useTaxonomyTagsData.mockReturnValue({
|
||||||
|
hasMorePages: false,
|
||||||
|
canAddTag: false,
|
||||||
|
tagPages: {
|
||||||
|
isLoading: false,
|
||||||
|
isError: false,
|
||||||
|
data: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<RootWrapper />);
|
||||||
expect(await screen.findByText(/to use tags, please or contact your administrator\./i)).toBeInTheDocument();
|
expect(await screen.findByText(/to use tags, please or contact your administrator\./i)).toBeInTheDocument();
|
||||||
const enableButton = screen.getByRole('button', {
|
const enableButton = screen.getByRole('button', {
|
||||||
name: /enable a taxonomy/i,
|
name: /enable a taxonomy/i,
|
||||||
|
|||||||
@@ -1,398 +0,0 @@
|
|||||||
import React, { useContext, useEffect } from 'react';
|
|
||||||
import {
|
|
||||||
Container,
|
|
||||||
Spinner,
|
|
||||||
Stack,
|
|
||||||
Button,
|
|
||||||
Toast,
|
|
||||||
} from '@openedx/paragon';
|
|
||||||
import { useIntl, FormattedMessage } from '@edx/frontend-platform/i18n';
|
|
||||||
import { useParams, useNavigate } from 'react-router-dom';
|
|
||||||
import classNames from 'classnames';
|
|
||||||
import messages from './messages';
|
|
||||||
import ContentTagsCollapsible from './ContentTagsCollapsible';
|
|
||||||
import Loading from '../generic/Loading';
|
|
||||||
import { useCreateContentTagsDrawerContext } from './ContentTagsDrawerHelper';
|
|
||||||
import { ContentTagsDrawerContext, ContentTagsDrawerSheetContext } from './common/context';
|
|
||||||
|
|
||||||
interface TaxonomyListProps {
|
|
||||||
contentId: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const TaxonomyList = ({ contentId }: TaxonomyListProps) => {
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const intl = useIntl();
|
|
||||||
|
|
||||||
const {
|
|
||||||
isTaxonomyListLoaded,
|
|
||||||
isContentTaxonomyTagsLoaded,
|
|
||||||
tagsByTaxonomy,
|
|
||||||
stagedContentTags,
|
|
||||||
collapsibleStates,
|
|
||||||
} = React.useContext(ContentTagsDrawerContext);
|
|
||||||
|
|
||||||
if (isTaxonomyListLoaded && isContentTaxonomyTagsLoaded) {
|
|
||||||
if (tagsByTaxonomy.length !== 0) {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{ tagsByTaxonomy.map((data) => (
|
|
||||||
<div key={data.id}>
|
|
||||||
<ContentTagsCollapsible
|
|
||||||
contentId={contentId}
|
|
||||||
taxonomyAndTagsData={data}
|
|
||||||
stagedContentTags={stagedContentTags[data.id] || []}
|
|
||||||
collapsibleState={collapsibleStates[data.id] || false}
|
|
||||||
/>
|
|
||||||
<hr />
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<FormattedMessage
|
|
||||||
{...messages.emptyDrawerContent}
|
|
||||||
values={{
|
|
||||||
link: (
|
|
||||||
<Button
|
|
||||||
tabIndex={0}
|
|
||||||
size="inline"
|
|
||||||
variant="link"
|
|
||||||
className="text-info-500 p-0 enable-taxonomies-button"
|
|
||||||
onClick={() => navigate('/taxonomies')}
|
|
||||||
>
|
|
||||||
{ intl.formatMessage(messages.emptyDrawerContentLink) }
|
|
||||||
</Button>
|
|
||||||
),
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return <Loading />;
|
|
||||||
};
|
|
||||||
|
|
||||||
const ContentTagsDrawerTitle = () => {
|
|
||||||
const intl = useIntl();
|
|
||||||
const {
|
|
||||||
isContentDataLoaded,
|
|
||||||
contentName,
|
|
||||||
} = useContext(ContentTagsDrawerContext);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{ isContentDataLoaded
|
|
||||||
? <h2 className="h3 pl-2.5">{ contentName }</h2>
|
|
||||||
: (
|
|
||||||
<div className="d-flex justify-content-center align-items-center flex-column">
|
|
||||||
<Spinner
|
|
||||||
animation="border"
|
|
||||||
size="xl"
|
|
||||||
screenReaderText={intl.formatMessage(messages.loadingMessage)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<hr />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
interface ContentTagsDrawerVariantFooterProps {
|
|
||||||
onClose: () => void,
|
|
||||||
readOnly: boolean,
|
|
||||||
}
|
|
||||||
|
|
||||||
const ContentTagsDrawerVariantFooter = ({ onClose, readOnly }: ContentTagsDrawerVariantFooterProps) => {
|
|
||||||
const intl = useIntl();
|
|
||||||
const {
|
|
||||||
commitGlobalStagedTagsStatus,
|
|
||||||
commitGlobalStagedTags,
|
|
||||||
isEditMode,
|
|
||||||
toReadMode,
|
|
||||||
toEditMode,
|
|
||||||
} = useContext(ContentTagsDrawerContext);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Container
|
|
||||||
className="bg-white position-sticky p-3.5 box-shadow-up-2 tags-drawer-footer"
|
|
||||||
>
|
|
||||||
<div className="d-flex justify-content-end">
|
|
||||||
{ commitGlobalStagedTagsStatus !== 'loading' ? (
|
|
||||||
<Stack direction="horizontal" gap={2}>
|
|
||||||
<Button
|
|
||||||
className="font-weight-bold tags-drawer-cancel-button"
|
|
||||||
variant="tertiary"
|
|
||||||
onClick={isEditMode
|
|
||||||
? toReadMode
|
|
||||||
: onClose}
|
|
||||||
>
|
|
||||||
{ intl.formatMessage(isEditMode
|
|
||||||
? messages.tagsDrawerCancelButtonText
|
|
||||||
: messages.tagsDrawerCloseButtonText)}
|
|
||||||
</Button>
|
|
||||||
{!readOnly && (
|
|
||||||
<Button
|
|
||||||
className="rounded-0"
|
|
||||||
onClick={isEditMode
|
|
||||||
? commitGlobalStagedTags
|
|
||||||
: toEditMode}
|
|
||||||
>
|
|
||||||
{ intl.formatMessage(isEditMode
|
|
||||||
? messages.tagsDrawerSaveButtonText
|
|
||||||
: messages.tagsDrawerEditTagsButtonText)}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
)
|
|
||||||
: (
|
|
||||||
<Spinner
|
|
||||||
animation="border"
|
|
||||||
size="xl"
|
|
||||||
screenReaderText={intl.formatMessage(messages.loadingMessage)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</Container>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
interface ContentTagsComponentVariantFooterProps {
|
|
||||||
readOnly?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ContentTagsComponentVariantFooter = ({ readOnly = false }: ContentTagsComponentVariantFooterProps) => {
|
|
||||||
const intl = useIntl();
|
|
||||||
const {
|
|
||||||
commitGlobalStagedTagsStatus,
|
|
||||||
commitGlobalStagedTags,
|
|
||||||
isEditMode,
|
|
||||||
toReadMode,
|
|
||||||
toEditMode,
|
|
||||||
} = useContext(ContentTagsDrawerContext);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{isEditMode ? (
|
|
||||||
<div>
|
|
||||||
{ commitGlobalStagedTagsStatus !== 'loading' ? (
|
|
||||||
<Stack direction="horizontal" gap={2}>
|
|
||||||
<Button
|
|
||||||
className="font-weight-bold tags-drawer-cancel-button"
|
|
||||||
variant="tertiary"
|
|
||||||
onClick={toReadMode}
|
|
||||||
>
|
|
||||||
{intl.formatMessage(messages.tagsDrawerCancelButtonText)}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
className="rounded-0"
|
|
||||||
onClick={commitGlobalStagedTags}
|
|
||||||
block
|
|
||||||
>
|
|
||||||
{intl.formatMessage(messages.tagsDrawerSaveButtonText)}
|
|
||||||
</Button>
|
|
||||||
</Stack>
|
|
||||||
) : (
|
|
||||||
<div className="d-flex justify-content-center">
|
|
||||||
<Spinner
|
|
||||||
animation="border"
|
|
||||||
size="xl"
|
|
||||||
screenReaderText={intl.formatMessage(messages.loadingMessage)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
) : !readOnly && (
|
|
||||||
<Button
|
|
||||||
variant="outline-primary"
|
|
||||||
onClick={toEditMode}
|
|
||||||
block
|
|
||||||
>
|
|
||||||
{intl.formatMessage(messages.manageTagsButton)}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
interface ContentTagsDrawerProps {
|
|
||||||
id?: string;
|
|
||||||
onClose?: () => void;
|
|
||||||
variant?: 'drawer' | 'component';
|
|
||||||
readOnly?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Drawer with the functionality to show and manage tags in a certain content.
|
|
||||||
* It is used both in interfaces of this MFE and in edx-platform interfaces such as iframe.
|
|
||||||
* - If you want to use it as an iframe, the component obtains the `contentId` from the url parameters.
|
|
||||||
* Functions to close the drawer are handled internally.
|
|
||||||
* - If you want to use it as react component, you need to pass the content id and the close functions
|
|
||||||
* through the component parameters.
|
|
||||||
*/
|
|
||||||
const ContentTagsDrawer = ({
|
|
||||||
id,
|
|
||||||
onClose,
|
|
||||||
variant = 'drawer',
|
|
||||||
readOnly = false,
|
|
||||||
}: ContentTagsDrawerProps) => {
|
|
||||||
const intl = useIntl();
|
|
||||||
// TODO: We can delete 'params' when the iframe is no longer used on edx-platform
|
|
||||||
const params = useParams();
|
|
||||||
const contentId = id ?? params.contentId;
|
|
||||||
|
|
||||||
if (contentId === undefined) {
|
|
||||||
throw new Error('Error: contentId cannot be null.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const context = useCreateContentTagsDrawerContext(contentId, !readOnly, variant === 'drawer');
|
|
||||||
const { blockingSheet } = useContext(ContentTagsDrawerSheetContext);
|
|
||||||
|
|
||||||
const {
|
|
||||||
showToastAfterSave,
|
|
||||||
toReadMode,
|
|
||||||
commitGlobalStagedTagsStatus,
|
|
||||||
isTaxonomyListLoaded,
|
|
||||||
isContentTaxonomyTagsLoaded,
|
|
||||||
stagedContentTags,
|
|
||||||
collapsibleStates,
|
|
||||||
toastMessage,
|
|
||||||
closeToast,
|
|
||||||
setCollapsibleToInitalState,
|
|
||||||
otherTaxonomies,
|
|
||||||
} = context;
|
|
||||||
|
|
||||||
let onCloseDrawer: () => void;
|
|
||||||
if (variant === 'drawer') {
|
|
||||||
if (onClose === undefined) {
|
|
||||||
onCloseDrawer = () => {
|
|
||||||
// "*" allows communication with any origin
|
|
||||||
window.parent.postMessage('closeManageTagsDrawer', '*');
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
onCloseDrawer = onClose;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (variant === 'drawer') {
|
|
||||||
const handleEsc = (event) => {
|
|
||||||
/* Close drawer when ESC-key is pressed and selectable dropdown box not open */
|
|
||||||
const selectableBoxOpen = document.querySelector('[data-selectable-box="taxonomy-tags"]');
|
|
||||||
if (event.key === 'Escape' && !selectableBoxOpen && !blockingSheet) {
|
|
||||||
onCloseDrawer();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
document.addEventListener('keydown', handleEsc);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
document.removeEventListener('keydown', handleEsc);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return () => {};
|
|
||||||
}, [blockingSheet]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
/* istanbul ignore next */
|
|
||||||
if (commitGlobalStagedTagsStatus === 'success') {
|
|
||||||
showToastAfterSave();
|
|
||||||
toReadMode();
|
|
||||||
}
|
|
||||||
}, [commitGlobalStagedTagsStatus]);
|
|
||||||
|
|
||||||
// First call of the initial collapsible states
|
|
||||||
React.useEffect(() => {
|
|
||||||
setCollapsibleToInitalState();
|
|
||||||
}, [isTaxonomyListLoaded, isContentTaxonomyTagsLoaded]);
|
|
||||||
|
|
||||||
const renderFooter = () => {
|
|
||||||
if (isTaxonomyListLoaded && isContentTaxonomyTagsLoaded) {
|
|
||||||
switch (variant) {
|
|
||||||
case 'drawer':
|
|
||||||
return <ContentTagsDrawerVariantFooter onClose={onCloseDrawer} readOnly={readOnly} />;
|
|
||||||
case 'component':
|
|
||||||
return <ContentTagsComponentVariantFooter readOnly={readOnly} />;
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ContentTagsDrawerContext.Provider value={context}>
|
|
||||||
<div
|
|
||||||
id="content-tags-drawer"
|
|
||||||
className={classNames(
|
|
||||||
'mt-1 tags-drawer d-flex flex-column justify-content-between pt-3',
|
|
||||||
{
|
|
||||||
'min-vh-100': variant === 'drawer',
|
|
||||||
},
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<Container
|
|
||||||
size="xl"
|
|
||||||
className={classNames(
|
|
||||||
{
|
|
||||||
'p-0': variant === 'component',
|
|
||||||
},
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{variant === 'drawer' && (
|
|
||||||
<ContentTagsDrawerTitle />
|
|
||||||
)}
|
|
||||||
<Container
|
|
||||||
className={classNames(
|
|
||||||
{
|
|
||||||
'p-0': variant === 'component',
|
|
||||||
},
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{variant === 'drawer' && (
|
|
||||||
<p className="h4 text-gray-500 font-weight-bold">
|
|
||||||
{intl.formatMessage(messages.headerSubtitle)}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
<TaxonomyList contentId={contentId} />
|
|
||||||
{otherTaxonomies.length !== 0 && (
|
|
||||||
<div>
|
|
||||||
<p className="h4 text-gray-500 font-weight-bold">
|
|
||||||
{intl.formatMessage(messages.otherTagsHeader)}
|
|
||||||
</p>
|
|
||||||
<p className="other-description text-gray-500">
|
|
||||||
{intl.formatMessage(messages.otherTagsDescription)}
|
|
||||||
</p>
|
|
||||||
{ isTaxonomyListLoaded && isContentTaxonomyTagsLoaded && (
|
|
||||||
otherTaxonomies.map((data) => (
|
|
||||||
<div key={data.id}>
|
|
||||||
<ContentTagsCollapsible
|
|
||||||
contentId={contentId}
|
|
||||||
taxonomyAndTagsData={data}
|
|
||||||
stagedContentTags={stagedContentTags[data.id] || []}
|
|
||||||
collapsibleState={collapsibleStates[data.id] || false}
|
|
||||||
/>
|
|
||||||
<hr />
|
|
||||||
</div>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</Container>
|
|
||||||
</Container>
|
|
||||||
{renderFooter()}
|
|
||||||
{/* istanbul ignore next */
|
|
||||||
toastMessage && (
|
|
||||||
<Toast
|
|
||||||
show
|
|
||||||
onClose={closeToast}
|
|
||||||
>
|
|
||||||
{toastMessage}
|
|
||||||
</Toast>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</ContentTagsDrawerContext.Provider>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ContentTagsDrawer;
|
|
||||||
@@ -8,23 +8,45 @@ import { extractOrgFromContentId, languageExportId } from './utils';
|
|||||||
import messages from './messages';
|
import messages from './messages';
|
||||||
import { ContentTagsDrawerSheetContext } from './common/context';
|
import { ContentTagsDrawerSheetContext } from './common/context';
|
||||||
|
|
||||||
/** @typedef {import("./data/types.js").Tag} ContentTagData */
|
/** @typedef {import("./data/types.mjs").Tag} ContentTagData */
|
||||||
/** @typedef {import("./data/types.js").StagedTagData} StagedTagData */
|
/** @typedef {import("./data/types.mjs").StagedTagData} StagedTagData */
|
||||||
/** @typedef {import("./data/types.js").TagsInTaxonomy} TagsInTaxonomy */
|
/** @typedef {import("./data/types.mjs").TagsInTaxonomy} TagsInTaxonomy */
|
||||||
/** @typedef {import("./common/context").ContentTagsDrawerContextData} ContentTagsDrawerContextData */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper hook for *creating* a `ContentTagsDrawerContext`.
|
* Handles the context and all the underlying logic for the ContentTagsDrawer component
|
||||||
* Handles the context and all the underlying logic for the ContentTagsDrawer component.
|
|
||||||
*
|
|
||||||
* To *use* the context, just use `useContext(ContentTagsDrawerContext)`
|
|
||||||
* @param {string} contentId
|
* @param {string} contentId
|
||||||
* @param {boolean} canTagObject
|
* @returns {{
|
||||||
* @param {boolean} fetchMetadata=false If true, fetches metadata for the contentId. This is used on `edx-platform`
|
* stagedContentTags: Record<number, StagedTagData[]>,
|
||||||
* and the Course/Unit Outline to show the content name as the drawer title.
|
* addStagedContentTag: (taxonomyId: number, addedTag: StagedTagData) => void,
|
||||||
* @returns {ContentTagsDrawerContextData}
|
* removeStagedContentTag: (taxonomyId: number, tagValue: string) => void,
|
||||||
|
* removeGlobalStagedContentTag: (taxonomyId: number, tagValue: string) => void,
|
||||||
|
* addRemovedContentTag: (taxonomyId: number, tagValue: string) => void,
|
||||||
|
* deleteRemovedContentTag: (taxonomyId: number, tagValue: string) => void,
|
||||||
|
* setStagedTags: (taxonomyId: number, tagsList: StagedTagData[]) => void,
|
||||||
|
* globalStagedContentTags: Record<number, StagedTagData[]>,
|
||||||
|
* globalStagedRemovedContentTags: Record<number, string>,
|
||||||
|
* setGlobalStagedContentTags: Function,
|
||||||
|
* commitGlobalStagedTags: () => void,
|
||||||
|
* commitGlobalStagedTagsStatus: string,
|
||||||
|
* isContentDataLoaded: boolean,
|
||||||
|
* isContentTaxonomyTagsLoaded: boolean,
|
||||||
|
* isTaxonomyListLoaded: boolean,
|
||||||
|
* contentName: string,
|
||||||
|
* tagsByTaxonomy: TagsInTaxonomy[],
|
||||||
|
* isEditMode: boolean,
|
||||||
|
* toEditMode: () => void,
|
||||||
|
* toReadMode: () => void,
|
||||||
|
* collapsibleStates: Record<number, boolean>,
|
||||||
|
* openCollapsible: (taxonomyId: number) => void,
|
||||||
|
* closeCollapsible: (taxonomyId: number) => void,
|
||||||
|
* toastMessage: string | undefined,
|
||||||
|
* showToastAfterSave: () => void,
|
||||||
|
* closeToast: () => void,
|
||||||
|
* setCollapsibleToInitalState: () => void,
|
||||||
|
* otherTaxonomies: TagsInTaxonomy[],
|
||||||
|
* }}
|
||||||
*/
|
*/
|
||||||
export const useCreateContentTagsDrawerContext = (contentId, canTagObject, fetchMetadata = false) => {
|
const useContentTagsDrawerContext = (contentId) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const org = extractOrgFromContentId(contentId);
|
const org = extractOrgFromContentId(contentId);
|
||||||
|
|
||||||
@@ -36,9 +58,9 @@ export const useCreateContentTagsDrawerContext = (contentId, canTagObject, fetch
|
|||||||
const [stagedContentTags, setStagedContentTags] = React.useState({});
|
const [stagedContentTags, setStagedContentTags] = React.useState({});
|
||||||
// When a staged tags on a taxonomy is commitet then is saved on this map.
|
// When a staged tags on a taxonomy is commitet then is saved on this map.
|
||||||
const [globalStagedContentTags, setGlobalStagedContentTags] = React.useState({});
|
const [globalStagedContentTags, setGlobalStagedContentTags] = React.useState({});
|
||||||
// This stores fetched tags deleted by the user.
|
// This stores feched tags deleted by the user.
|
||||||
const [globalStagedRemovedContentTags, setGlobalStagedRemovedContentTags] = React.useState({});
|
const [globalStagedRemovedContentTags, setGlobalStagedRemovedContentTags] = React.useState({});
|
||||||
// Merges fetched tags, global staged tags and global removed staged tags
|
// Merges feched tags, global staged tags and global removed staged tags
|
||||||
const [tagsByTaxonomy, setTagsByTaxonomy] = React.useState(/** @type TagsInTaxonomy[] */ ([]));
|
const [tagsByTaxonomy, setTagsByTaxonomy] = React.useState(/** @type TagsInTaxonomy[] */ ([]));
|
||||||
// Other taxonomies that the user doesn't have permissions
|
// Other taxonomies that the user doesn't have permissions
|
||||||
const [otherTaxonomies, setOtherTaxonomies] = React.useState(/** @type TagsInTaxonomy[] */ ([]));
|
const [otherTaxonomies, setOtherTaxonomies] = React.useState(/** @type TagsInTaxonomy[] */ ([]));
|
||||||
@@ -50,15 +72,15 @@ export const useCreateContentTagsDrawerContext = (contentId, canTagObject, fetch
|
|||||||
const updateTags = useContentTaxonomyTagsUpdater(contentId);
|
const updateTags = useContentTaxonomyTagsUpdater(contentId);
|
||||||
|
|
||||||
// Fetch from database
|
// Fetch from database
|
||||||
const { data: contentData, isSuccess: isContentDataLoaded } = useContentData(contentId, fetchMetadata);
|
const { data: contentData, isSuccess: isContentDataLoaded } = useContentData(contentId);
|
||||||
const {
|
const {
|
||||||
data: contentTaxonomyTagsData,
|
data: contentTaxonomyTagsData,
|
||||||
isSuccess: isContentTaxonomyTagsLoaded,
|
isSuccess: isContentTaxonomyTagsLoaded,
|
||||||
} = useContentTaxonomyTagsData(contentId);
|
} = useContentTaxonomyTagsData(contentId);
|
||||||
const { data: taxonomyListData, isSuccess: isTaxonomyListLoaded } = useTaxonomyList(org);
|
const { data: taxonomyListData, isSuccess: isTaxonomyListLoaded } = useTaxonomyList(org);
|
||||||
|
|
||||||
// Tags fetched from database
|
// Tags feched from database
|
||||||
const { fetchedTaxonomies, fetchedOtherTaxonomies } = React.useMemo(() => {
|
const { fechedTaxonomies, fechedOtherTaxonomies } = React.useMemo(() => {
|
||||||
const sortTaxonomies = (taxonomiesList) => {
|
const sortTaxonomies = (taxonomiesList) => {
|
||||||
const taxonomiesWithData = taxonomiesList.filter(
|
const taxonomiesWithData = taxonomiesList.filter(
|
||||||
(t) => t.contentTags.length !== 0,
|
(t) => t.contentTags.length !== 0,
|
||||||
@@ -93,7 +115,6 @@ export const useCreateContentTagsDrawerContext = (contentId, canTagObject, fetch
|
|||||||
// Initialize list of content tags in taxonomies to populate
|
// Initialize list of content tags in taxonomies to populate
|
||||||
const taxonomiesList = taxonomyListData.results.map((taxonomy) => ({
|
const taxonomiesList = taxonomyListData.results.map((taxonomy) => ({
|
||||||
...taxonomy,
|
...taxonomy,
|
||||||
canTagObject: taxonomy.canTagObject && canTagObject,
|
|
||||||
contentTags: /** @type {ContentTagData[]} */([]),
|
contentTags: /** @type {ContentTagData[]} */([]),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -128,13 +149,13 @@ export const useCreateContentTagsDrawerContext = (contentId, canTagObject, fetch
|
|||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fetchedTaxonomies: sortTaxonomies(filteredTaxonomies),
|
fechedTaxonomies: sortTaxonomies(filteredTaxonomies),
|
||||||
fetchedOtherTaxonomies: otherTaxonomiesList,
|
fechedOtherTaxonomies: otherTaxonomiesList,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
fetchedTaxonomies: [],
|
fechedTaxonomies: [],
|
||||||
fetchedOtherTaxonomies: [],
|
fechedOtherTaxonomies: [],
|
||||||
};
|
};
|
||||||
}, [taxonomyListData, contentTaxonomyTagsData]);
|
}, [taxonomyListData, contentTaxonomyTagsData]);
|
||||||
|
|
||||||
@@ -209,28 +230,28 @@ export const useCreateContentTagsDrawerContext = (contentId, canTagObject, fetch
|
|||||||
|
|
||||||
const openAllCollapsible = React.useCallback(() => {
|
const openAllCollapsible = React.useCallback(() => {
|
||||||
const updatedState = {};
|
const updatedState = {};
|
||||||
fetchedTaxonomies.forEach((taxonomy) => {
|
fechedTaxonomies.forEach((taxonomy) => {
|
||||||
updatedState[taxonomy.id] = true;
|
updatedState[taxonomy.id] = true;
|
||||||
});
|
});
|
||||||
fetchedOtherTaxonomies.forEach((taxonomy) => {
|
fechedOtherTaxonomies.forEach((taxonomy) => {
|
||||||
updatedState[taxonomy.id] = true;
|
updatedState[taxonomy.id] = true;
|
||||||
});
|
});
|
||||||
setColapsibleStates(updatedState);
|
setColapsibleStates(updatedState);
|
||||||
}, [fetchedTaxonomies, setColapsibleStates]);
|
}, [fechedTaxonomies, setColapsibleStates]);
|
||||||
|
|
||||||
// Set initial state of collapsible based on content tags
|
// Set initial state of collapsible based on content tags
|
||||||
const setCollapsibleToInitalState = React.useCallback(() => {
|
const setCollapsibleToInitalState = React.useCallback(() => {
|
||||||
const updatedState = {};
|
const updatedState = {};
|
||||||
fetchedTaxonomies.forEach((taxonomy) => {
|
fechedTaxonomies.forEach((taxonomy) => {
|
||||||
// Taxonomy with content tags must be open
|
// Taxonomy with content tags must be open
|
||||||
updatedState[taxonomy.id] = taxonomy.contentTags.length !== 0;
|
updatedState[taxonomy.id] = taxonomy.contentTags.length !== 0;
|
||||||
});
|
});
|
||||||
fetchedOtherTaxonomies.forEach((taxonomy) => {
|
fechedOtherTaxonomies.forEach((taxonomy) => {
|
||||||
// Taxonomy with content tags must be open
|
// Taxonomy with content tags must be open
|
||||||
updatedState[taxonomy.id] = taxonomy.contentTags.length !== 0;
|
updatedState[taxonomy.id] = taxonomy.contentTags.length !== 0;
|
||||||
});
|
});
|
||||||
setColapsibleStates(updatedState);
|
setColapsibleStates(updatedState);
|
||||||
}, [fetchedTaxonomies, setColapsibleStates]);
|
}, [fechedTaxonomies, setColapsibleStates]);
|
||||||
|
|
||||||
// Changes the drawer mode to edit
|
// Changes the drawer mode to edit
|
||||||
const toEditMode = React.useCallback(() => {
|
const toEditMode = React.useCallback(() => {
|
||||||
@@ -310,7 +331,7 @@ export const useCreateContentTagsDrawerContext = (contentId, canTagObject, fetch
|
|||||||
const closeToast = React.useCallback(() => setToastMessage(undefined), [setToastMessage]);
|
const closeToast = React.useCallback(() => setToastMessage(undefined), [setToastMessage]);
|
||||||
|
|
||||||
let contentName = '';
|
let contentName = '';
|
||||||
if (isContentDataLoaded && contentData) {
|
if (isContentDataLoaded) {
|
||||||
if ('displayName' in contentData) {
|
if ('displayName' in contentData) {
|
||||||
contentName = contentData.displayName;
|
contentName = contentData.displayName;
|
||||||
} else {
|
} else {
|
||||||
@@ -318,14 +339,14 @@ export const useCreateContentTagsDrawerContext = (contentId, canTagObject, fetch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates `tagsByTaxonomy` merged fetched tags, global staged tags
|
// Updates `tagsByTaxonomy` merged feched tags, global staged tags
|
||||||
// and global removed staged tags.
|
// and global removed staged tags.
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const mergedTags = cloneDeep(fetchedTaxonomies).reduce((acc, obj) => (
|
const mergedTags = cloneDeep(fechedTaxonomies).reduce((acc, obj) => (
|
||||||
{ ...acc, [obj.id]: obj }
|
{ ...acc, [obj.id]: obj }
|
||||||
), {});
|
), {});
|
||||||
|
|
||||||
const mergedOtherTaxonomies = cloneDeep(fetchedOtherTaxonomies).reduce((acc, obj) => (
|
const mergedOtherTaxonomies = cloneDeep(fechedOtherTaxonomies).reduce((acc, obj) => (
|
||||||
{ ...acc, [obj.id]: obj }
|
{ ...acc, [obj.id]: obj }
|
||||||
), {});
|
), {});
|
||||||
|
|
||||||
@@ -334,10 +355,10 @@ export const useCreateContentTagsDrawerContext = (contentId, canTagObject, fetch
|
|||||||
// TODO test this
|
// TODO test this
|
||||||
// Filter out applied tags that should become implicit because a child tag was committed
|
// Filter out applied tags that should become implicit because a child tag was committed
|
||||||
const stagedLineages = globalStagedContentTags[taxonomyId].map((t) => t.lineage.slice(0, -1)).flat();
|
const stagedLineages = globalStagedContentTags[taxonomyId].map((t) => t.lineage.slice(0, -1)).flat();
|
||||||
const fetchedTags = mergedTags[taxonomyId].contentTags.filter((t) => !stagedLineages.includes(t.value));
|
const fechedTags = mergedTags[taxonomyId].contentTags.filter((t) => !stagedLineages.includes(t.value));
|
||||||
|
|
||||||
mergedTags[taxonomyId].contentTags = [
|
mergedTags[taxonomyId].contentTags = [
|
||||||
...fetchedTags,
|
...fechedTags,
|
||||||
...globalStagedContentTags[taxonomyId],
|
...globalStagedContentTags[taxonomyId],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -356,8 +377,8 @@ export const useCreateContentTagsDrawerContext = (contentId, canTagObject, fetch
|
|||||||
});
|
});
|
||||||
|
|
||||||
// It is constructed this way to maintain the order
|
// It is constructed this way to maintain the order
|
||||||
// of the list `fetchedTaxonomies`
|
// of the list `fechedTaxonomies`
|
||||||
const mergedTagsArray = fetchedTaxonomies.map(obj => mergedTags[obj.id]);
|
const mergedTagsArray = fechedTaxonomies.map(obj => mergedTags[obj.id]);
|
||||||
|
|
||||||
setTagsByTaxonomy(mergedTagsArray);
|
setTagsByTaxonomy(mergedTagsArray);
|
||||||
setOtherTaxonomies(Object.values(mergedOtherTaxonomies));
|
setOtherTaxonomies(Object.values(mergedOtherTaxonomies));
|
||||||
@@ -387,8 +408,8 @@ export const useCreateContentTagsDrawerContext = (contentId, canTagObject, fetch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
fetchedTaxonomies,
|
fechedTaxonomies,
|
||||||
fetchedOtherTaxonomies,
|
fechedOtherTaxonomies,
|
||||||
globalStagedContentTags,
|
globalStagedContentTags,
|
||||||
globalStagedRemovedContentTags,
|
globalStagedRemovedContentTags,
|
||||||
]);
|
]);
|
||||||
@@ -442,3 +463,5 @@ export const useCreateContentTagsDrawerContext = (contentId, canTagObject, fetch
|
|||||||
otherTaxonomies,
|
otherTaxonomies,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default useContentTagsDrawerContext;
|
||||||
|
|||||||
@@ -12,10 +12,6 @@ const ContentTagsDrawerSheet = ({ id, onClose, showSheet }) => {
|
|||||||
blockingSheet, setBlockingSheet,
|
blockingSheet, setBlockingSheet,
|
||||||
}), [blockingSheet, setBlockingSheet]);
|
}), [blockingSheet, setBlockingSheet]);
|
||||||
|
|
||||||
// ContentTagsDrawerSheet is only used when editing Courses/Course Units,
|
|
||||||
// so we assume it's ok to edit the object tags too.
|
|
||||||
const readOnly = false;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ContentTagsDrawerSheetContext.Provider value={context}>
|
<ContentTagsDrawerSheetContext.Provider value={context}>
|
||||||
<Sheet
|
<Sheet
|
||||||
@@ -27,7 +23,6 @@ const ContentTagsDrawerSheet = ({ id, onClose, showSheet }) => {
|
|||||||
<ContentTagsDrawer
|
<ContentTagsDrawer
|
||||||
id={id}
|
id={id}
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
readOnly={readOnly}
|
|
||||||
/>
|
/>
|
||||||
</Sheet>
|
</Sheet>
|
||||||
</ContentTagsDrawerSheetContext.Provider>
|
</ContentTagsDrawerSheetContext.Provider>
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ import {
|
|||||||
Spinner,
|
Spinner,
|
||||||
Button,
|
Button,
|
||||||
} from '@openedx/paragon';
|
} from '@openedx/paragon';
|
||||||
|
import { SelectableBox } from '@edx/frontend-lib-content-components';
|
||||||
import { useIntl, FormattedMessage } from '@edx/frontend-platform/i18n';
|
import { useIntl, FormattedMessage } from '@edx/frontend-platform/i18n';
|
||||||
import { ArrowDropDown, ArrowDropUp, Add } from '@openedx/paragon/icons';
|
import { ArrowDropDown, ArrowDropUp, Add } from '@openedx/paragon/icons';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import SelectableBox from '../editors/sharedComponents/SelectableBox';
|
|
||||||
import { useTaxonomyTagsData } from './data/apiHooks';
|
|
||||||
import messages from './messages';
|
import messages from './messages';
|
||||||
|
|
||||||
|
import { useTaxonomyTagsData } from './data/apiHooks';
|
||||||
|
|
||||||
const HighlightedText = ({ text, highlight }) => {
|
const HighlightedText = ({ text, highlight }) => {
|
||||||
if (!highlight) {
|
if (!highlight) {
|
||||||
return <span>{text}</span>;
|
return <span>{text}</span>;
|
||||||
@@ -309,7 +309,7 @@ const ContentTagsDropDownSelector = ({
|
|||||||
? (
|
? (
|
||||||
<div>
|
<div>
|
||||||
<Button
|
<Button
|
||||||
tabIndex={0}
|
tabIndex="0"
|
||||||
variant="tertiary"
|
variant="tertiary"
|
||||||
iconBefore={Add}
|
iconBefore={Add}
|
||||||
onClick={loadMoreTags}
|
onClick={loadMoreTags}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||||
import {
|
import {
|
||||||
|
act,
|
||||||
render,
|
render,
|
||||||
waitFor,
|
waitFor,
|
||||||
fireEvent,
|
fireEvent,
|
||||||
@@ -73,9 +74,11 @@ describe('<ContentTagsDropDownSelector />', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it('should render taxonomy tags drop down selector loading with spinner', async () => {
|
it('should render taxonomy tags drop down selector loading with spinner', async () => {
|
||||||
const { getByRole } = await getComponent();
|
await act(async () => {
|
||||||
const spinner = getByRole('status');
|
const { getByRole } = await getComponent();
|
||||||
expect(spinner.textContent).toEqual('Loading tags'); // Uses <Spinner />
|
const spinner = getByRole('status');
|
||||||
|
expect(spinner.textContent).toEqual('Loading tags'); // Uses <Spinner />
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render taxonomy tags drop down selector with no sub tags', async () => {
|
it('should render taxonomy tags drop down selector with no sub tags', async () => {
|
||||||
@@ -96,11 +99,13 @@ describe('<ContentTagsDropDownSelector />', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { container, getByText } = await getComponent();
|
await act(async () => {
|
||||||
|
const { container, getByText } = await getComponent();
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(getByText('Tag 1')).toBeInTheDocument();
|
expect(getByText('Tag 1')).toBeInTheDocument();
|
||||||
expect(container.getElementsByClassName('taxonomy-tags-arrow-drop-down').length).toBe(0);
|
expect(container.getElementsByClassName('taxonomy-tags-arrow-drop-down').length).toBe(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -122,11 +127,13 @@ describe('<ContentTagsDropDownSelector />', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { container, getByText } = await getComponent();
|
await act(async () => {
|
||||||
|
const { container, getByText } = await getComponent();
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(getByText('Tag 2')).toBeInTheDocument();
|
expect(getByText('Tag 2')).toBeInTheDocument();
|
||||||
expect(container.getElementsByClassName('taxonomy-tags-arrow-drop-down').length).toBe(1);
|
expect(container.getElementsByClassName('taxonomy-tags-arrow-drop-down').length).toBe(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -148,45 +155,47 @@ describe('<ContentTagsDropDownSelector />', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const dataWithTagsTree = {
|
await act(async () => {
|
||||||
...data,
|
const dataWithTagsTree = {
|
||||||
tagsTree: {
|
...data,
|
||||||
'Tag 3': {
|
tagsTree: {
|
||||||
explicit: false,
|
'Tag 3': {
|
||||||
children: {},
|
explicit: false,
|
||||||
|
children: {},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
};
|
||||||
};
|
const { container, getByText } = await getComponent(dataWithTagsTree);
|
||||||
const { container, getByText } = await getComponent(dataWithTagsTree);
|
await waitFor(() => {
|
||||||
await waitFor(() => {
|
expect(getByText('Tag 2')).toBeInTheDocument();
|
||||||
expect(getByText('Tag 2')).toBeInTheDocument();
|
expect(container.getElementsByClassName('taxonomy-tags-arrow-drop-down').length).toBe(1);
|
||||||
expect(container.getElementsByClassName('taxonomy-tags-arrow-drop-down').length).toBe(1);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// Mock useTaxonomyTagsData again since it gets called in the recursive call
|
// Mock useTaxonomyTagsData again since it gets called in the recursive call
|
||||||
useTaxonomyTagsData.mockReturnValueOnce({
|
useTaxonomyTagsData.mockReturnValueOnce({
|
||||||
hasMorePages: false,
|
hasMorePages: false,
|
||||||
tagPages: {
|
tagPages: {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isError: false,
|
isError: false,
|
||||||
data: [{
|
data: [{
|
||||||
value: 'Tag 3',
|
value: 'Tag 3',
|
||||||
externalId: null,
|
externalId: null,
|
||||||
childCount: 0,
|
childCount: 0,
|
||||||
depth: 1,
|
depth: 1,
|
||||||
parentValue: 'Tag 2',
|
parentValue: 'Tag 2',
|
||||||
id: 12346,
|
id: 12346,
|
||||||
subTagsUrl: null,
|
subTagsUrl: null,
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Expand the dropdown to see the subtags selectors
|
// Expand the dropdown to see the subtags selectors
|
||||||
const expandToggle = container.querySelector('.taxonomy-tags-arrow-drop-down span');
|
const expandToggle = container.querySelector('.taxonomy-tags-arrow-drop-down span');
|
||||||
fireEvent.click(expandToggle);
|
fireEvent.click(expandToggle);
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(getByText('Tag 3')).toBeInTheDocument();
|
expect(getByText('Tag 3')).toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -210,46 +219,48 @@ describe('<ContentTagsDropDownSelector />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const initalSearchTerm = 'test 1';
|
const initalSearchTerm = 'test 1';
|
||||||
const { rerender } = await getComponent({ ...data, searchTerm: initalSearchTerm });
|
await act(async () => {
|
||||||
|
const { rerender } = await getComponent({ ...data, searchTerm: initalSearchTerm });
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(useTaxonomyTagsData).toHaveBeenCalledWith(data.taxonomyId, null, 1, initalSearchTerm);
|
expect(useTaxonomyTagsData).toBeCalledWith(data.taxonomyId, null, 1, initalSearchTerm);
|
||||||
});
|
});
|
||||||
|
|
||||||
const updatedSearchTerm = 'test 2';
|
const updatedSearchTerm = 'test 2';
|
||||||
rerender(<ContentTagsDropDownSelectorComponent
|
rerender(<ContentTagsDropDownSelectorComponent
|
||||||
key={`selector-${data.taxonomyId}`}
|
key={`selector-${data.taxonomyId}`}
|
||||||
taxonomyId={data.taxonomyId}
|
taxonomyId={data.taxonomyId}
|
||||||
level={data.level}
|
level={data.level}
|
||||||
tagsTree={data.tagsTree}
|
tagsTree={data.tagsTree}
|
||||||
searchTerm={updatedSearchTerm}
|
searchTerm={updatedSearchTerm}
|
||||||
appliedContentTagsTree={{}}
|
appliedContentTagsTree={{}}
|
||||||
stagedContentTagsTree={{}}
|
stagedContentTagsTree={{}}
|
||||||
/>);
|
/>);
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(useTaxonomyTagsData).toHaveBeenCalledWith(data.taxonomyId, null, 1, updatedSearchTerm);
|
expect(useTaxonomyTagsData).toBeCalledWith(data.taxonomyId, null, 1, updatedSearchTerm);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Clean search term
|
// Clean search term
|
||||||
const cleanSearchTerm = '';
|
const cleanSearchTerm = '';
|
||||||
rerender(<ContentTagsDropDownSelectorComponent
|
rerender(<ContentTagsDropDownSelectorComponent
|
||||||
key={`selector-${data.taxonomyId}`}
|
key={`selector-${data.taxonomyId}`}
|
||||||
taxonomyId={data.taxonomyId}
|
taxonomyId={data.taxonomyId}
|
||||||
level={data.level}
|
level={data.level}
|
||||||
tagsTree={data.tagsTree}
|
tagsTree={data.tagsTree}
|
||||||
searchTerm={cleanSearchTerm}
|
searchTerm={cleanSearchTerm}
|
||||||
appliedContentTagsTree={{}}
|
appliedContentTagsTree={{}}
|
||||||
stagedContentTagsTree={{}}
|
stagedContentTagsTree={{}}
|
||||||
/>);
|
/>);
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(useTaxonomyTagsData).toHaveBeenCalledWith(data.taxonomyId, null, 1, cleanSearchTerm);
|
expect(useTaxonomyTagsData).toBeCalledWith(data.taxonomyId, null, 1, cleanSearchTerm);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render "noTag" message if search doesnt return taxonomies', async () => {
|
it('should render "noTag" message if search doesnt return taxonomies', async () => {
|
||||||
useTaxonomyTagsData.mockReturnValue({
|
useTaxonomyTagsData.mockReturnValueOnce({
|
||||||
hasMorePages: false,
|
hasMorePages: false,
|
||||||
tagPages: {
|
tagPages: {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@@ -260,18 +271,20 @@ describe('<ContentTagsDropDownSelector />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const searchTerm = 'uncommon search term';
|
const searchTerm = 'uncommon search term';
|
||||||
const { getByText } = await getComponent({ ...data, searchTerm });
|
await act(async () => {
|
||||||
|
const { getByText } = await getComponent({ ...data, searchTerm });
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(useTaxonomyTagsData).toHaveBeenCalledWith(data.taxonomyId, null, 1, searchTerm);
|
expect(useTaxonomyTagsData).toBeCalledWith(data.taxonomyId, null, 1, searchTerm);
|
||||||
|
});
|
||||||
|
|
||||||
|
const message = `No tags found with the search term "${searchTerm}"`;
|
||||||
|
expect(getByText(message)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
const message = `No tags found with the search term "${searchTerm}"`;
|
|
||||||
expect(getByText(message)).toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render "noTagsInTaxonomy" message if taxonomy is empty', async () => {
|
it('should render "noTagsInTaxonomy" message if taxonomy is empty', async () => {
|
||||||
useTaxonomyTagsData.mockReturnValue({
|
useTaxonomyTagsData.mockReturnValueOnce({
|
||||||
hasMorePages: false,
|
hasMorePages: false,
|
||||||
tagPages: {
|
tagPages: {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@@ -282,13 +295,15 @@ describe('<ContentTagsDropDownSelector />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const searchTerm = '';
|
const searchTerm = '';
|
||||||
const { getByText } = await getComponent({ ...data, searchTerm });
|
await act(async () => {
|
||||||
|
const { getByText } = await getComponent({ ...data, searchTerm });
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(useTaxonomyTagsData).toHaveBeenCalledWith(data.taxonomyId, null, 1, searchTerm);
|
expect(useTaxonomyTagsData).toBeCalledWith(data.taxonomyId, null, 1, searchTerm);
|
||||||
|
});
|
||||||
|
|
||||||
|
const message = 'No tags in this taxonomy yet';
|
||||||
|
expect(getByText(message)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
const message = 'No tags in this taxonomy yet';
|
|
||||||
expect(getByText(message)).toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
49
src/content-tags-drawer/common/context.js
Normal file
49
src/content-tags-drawer/common/context.js
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
// @ts-check
|
||||||
|
/* eslint-disable import/prefer-default-export */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
/** @typedef {import("../data/types.mjs").TagsInTaxonomy} TagsInTaxonomy */
|
||||||
|
/** @typedef {import("../data/types.mjs").StagedTagData} StagedTagData */
|
||||||
|
|
||||||
|
/* istanbul ignore next */
|
||||||
|
export const ContentTagsDrawerContext = React.createContext({
|
||||||
|
stagedContentTags: /** @type{Record<number, StagedTagData[]>} */ ({}),
|
||||||
|
globalStagedContentTags: /** @type{Record<number, StagedTagData[]>} */ ({}),
|
||||||
|
globalStagedRemovedContentTags: /** @type{Record<number, string>} */ ({}),
|
||||||
|
addStagedContentTag: /** @type{(taxonomyId: number, addedTag: StagedTagData) => void} */ (() => {}),
|
||||||
|
removeStagedContentTag: /** @type{(taxonomyId: number, tagValue: string) => void} */ (() => {}),
|
||||||
|
removeGlobalStagedContentTag: /** @type{(taxonomyId: number, tagValue: string) => void} */ (() => {}),
|
||||||
|
addRemovedContentTag: /** @type{(taxonomyId: number, tagValue: string) => void} */ (() => {}),
|
||||||
|
deleteRemovedContentTag: /** @type{(taxonomyId: number, tagValue: string) => void} */ (() => {}),
|
||||||
|
setStagedTags: /** @type{(taxonomyId: number, tagsList: StagedTagData[]) => void} */ (() => {}),
|
||||||
|
setGlobalStagedContentTags: /** @type{Function} */ (() => {}),
|
||||||
|
commitGlobalStagedTags: /** @type{() => void} */ (() => {}),
|
||||||
|
commitGlobalStagedTagsStatus: /** @type{null|string} */ (null),
|
||||||
|
isContentDataLoaded: /** @type{boolean} */ (false),
|
||||||
|
isContentTaxonomyTagsLoaded: /** @type{boolean} */ (false),
|
||||||
|
isTaxonomyListLoaded: /** @type{boolean} */ (false),
|
||||||
|
contentName: /** @type{string} */ (''),
|
||||||
|
tagsByTaxonomy: /** @type{TagsInTaxonomy[]} */ ([]),
|
||||||
|
isEditMode: /** @type{boolean} */ (false),
|
||||||
|
toEditMode: /** @type{() => void} */ (() => {}),
|
||||||
|
toReadMode: /** @type{() => void} */ (() => {}),
|
||||||
|
collapsibleStates: /** @type{Record<number, boolean>} */ ({}),
|
||||||
|
openCollapsible: /** @type{(taxonomyId: number) => void} */ (() => {}),
|
||||||
|
closeCollapsible: /** @type{(taxonomyId: number) => void} */ (() => {}),
|
||||||
|
toastMessage: /** @type{string|undefined} */ (undefined),
|
||||||
|
showToastAfterSave: /** @type{() => void} */ (() => {}),
|
||||||
|
closeToast: /** @type{() => void} */ (() => {}),
|
||||||
|
setCollapsibleToInitalState: /** @type{() => void} */ (() => {}),
|
||||||
|
otherTaxonomies: /** @type{TagsInTaxonomy[]} */ ([]),
|
||||||
|
});
|
||||||
|
|
||||||
|
// This context has not been added to ContentTagsDrawerContext because it has been
|
||||||
|
// created one level higher to control the behavior of the Sheet that contatins the Drawer.
|
||||||
|
// This logic is not used in legacy edx-platform screens. But it can be separated if we keep
|
||||||
|
// the contexts separate.
|
||||||
|
// TODO We can join both contexts when the Drawer is no longer used on edx-platform
|
||||||
|
/* istanbul ignore next */
|
||||||
|
export const ContentTagsDrawerSheetContext = React.createContext({
|
||||||
|
blockingSheet: /** @type{boolean} */ (false),
|
||||||
|
setBlockingSheet: /** @type{Function} */ (() => {}),
|
||||||
|
});
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
|
|
||||||
import type { TagsInTaxonomy, StagedTagData } from '../data/types';
|
|
||||||
|
|
||||||
export interface ContentTagsDrawerContextData {
|
|
||||||
stagedContentTags: Record<number, StagedTagData[]>;
|
|
||||||
globalStagedContentTags: Record<number, StagedTagData[]>;
|
|
||||||
globalStagedRemovedContentTags: Record<number, string>;
|
|
||||||
addStagedContentTag: (taxonomyId: number, addedTag: StagedTagData) => void;
|
|
||||||
removeStagedContentTag: (taxonomyId: number, tagValue: string) => void;
|
|
||||||
removeGlobalStagedContentTag: (taxonomyId: number, tagValue: string) => void;
|
|
||||||
addRemovedContentTag: (taxonomyId: number, tagValue: string) => void;
|
|
||||||
deleteRemovedContentTag: (taxonomyId: number, tagValue: string) => void;
|
|
||||||
setStagedTags: (taxonomyId: number, tagsList: StagedTagData[]) => void;
|
|
||||||
setGlobalStagedContentTags: Function;
|
|
||||||
commitGlobalStagedTags: () => void;
|
|
||||||
commitGlobalStagedTagsStatus: null | string;
|
|
||||||
isContentDataLoaded: boolean;
|
|
||||||
isContentTaxonomyTagsLoaded: boolean;
|
|
||||||
isTaxonomyListLoaded: boolean;
|
|
||||||
contentName: string;
|
|
||||||
tagsByTaxonomy: TagsInTaxonomy[];
|
|
||||||
isEditMode: boolean;
|
|
||||||
toEditMode: () => void;
|
|
||||||
toReadMode: () => void;
|
|
||||||
collapsibleStates: Record<number, boolean>;
|
|
||||||
openCollapsible: (taxonomyId: number) => void;
|
|
||||||
closeCollapsible: (taxonomyId: number) => void;
|
|
||||||
toastMessage: string | undefined;
|
|
||||||
showToastAfterSave: () => void;
|
|
||||||
closeToast: () => void;
|
|
||||||
setCollapsibleToInitalState: () => void;
|
|
||||||
otherTaxonomies: TagsInTaxonomy[];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* istanbul ignore next */
|
|
||||||
export const ContentTagsDrawerContext = React.createContext<ContentTagsDrawerContextData>({
|
|
||||||
stagedContentTags: {},
|
|
||||||
globalStagedContentTags: {},
|
|
||||||
globalStagedRemovedContentTags: {},
|
|
||||||
addStagedContentTag: () => {},
|
|
||||||
removeStagedContentTag: () => {},
|
|
||||||
removeGlobalStagedContentTag: () => {},
|
|
||||||
addRemovedContentTag: () => {},
|
|
||||||
deleteRemovedContentTag: () => {},
|
|
||||||
setStagedTags: () => {},
|
|
||||||
setGlobalStagedContentTags: () => {},
|
|
||||||
commitGlobalStagedTags: () => {},
|
|
||||||
commitGlobalStagedTagsStatus: null,
|
|
||||||
isContentDataLoaded: false,
|
|
||||||
isContentTaxonomyTagsLoaded: false,
|
|
||||||
isTaxonomyListLoaded: false,
|
|
||||||
contentName: '',
|
|
||||||
tagsByTaxonomy: [],
|
|
||||||
isEditMode: false,
|
|
||||||
toEditMode: () => {},
|
|
||||||
toReadMode: () => {},
|
|
||||||
collapsibleStates: {},
|
|
||||||
openCollapsible: () => {},
|
|
||||||
closeCollapsible: () => {},
|
|
||||||
toastMessage: undefined,
|
|
||||||
showToastAfterSave: () => {},
|
|
||||||
closeToast: () => {},
|
|
||||||
setCollapsibleToInitalState: () => {},
|
|
||||||
otherTaxonomies: [],
|
|
||||||
});
|
|
||||||
|
|
||||||
// This context has not been added to ContentTagsDrawerContext because it has been
|
|
||||||
// created one level higher to control the behavior of the Sheet that contatins the Drawer.
|
|
||||||
// This logic is not used in legacy edx-platform screens. But it can be separated if we keep
|
|
||||||
// the contexts separate.
|
|
||||||
// TODO We can join both contexts when the Drawer is no longer used on edx-platform
|
|
||||||
/* istanbul ignore next */
|
|
||||||
export const ContentTagsDrawerSheetContext = React.createContext({
|
|
||||||
blockingSheet: false,
|
|
||||||
setBlockingSheet: (() => {}) as (blockingSheet: boolean) => void,
|
|
||||||
});
|
|
||||||
@@ -38,7 +38,7 @@ export const getContentTaxonomyTagsCountApiUrl = (contentId) => new URL(`api/con
|
|||||||
* Get all tags that belong to taxonomy.
|
* Get all tags that belong to taxonomy.
|
||||||
* @param {number} taxonomyId The id of the taxonomy to fetch tags for
|
* @param {number} taxonomyId The id of the taxonomy to fetch tags for
|
||||||
* @param {{page?: number, searchTerm?: string, parentTag?: string}} options
|
* @param {{page?: number, searchTerm?: string, parentTag?: string}} options
|
||||||
* @returns {Promise<import("../../taxonomy/data/types.js").TagListData>}
|
* @returns {Promise<import("../../taxonomy/tag-list/data/types.mjs").TagListData>}
|
||||||
*/
|
*/
|
||||||
export async function getTaxonomyTagsData(taxonomyId, options = {}) {
|
export async function getTaxonomyTagsData(taxonomyId, options = {}) {
|
||||||
const url = getTaxonomyTagsApiUrl(taxonomyId, options);
|
const url = getTaxonomyTagsApiUrl(taxonomyId, options);
|
||||||
@@ -49,7 +49,7 @@ export async function getTaxonomyTagsData(taxonomyId, options = {}) {
|
|||||||
/**
|
/**
|
||||||
* Get the tags that are applied to the content object
|
* Get the tags that are applied to the content object
|
||||||
* @param {string} contentId The id of the content object to fetch the applied tags for
|
* @param {string} contentId The id of the content object to fetch the applied tags for
|
||||||
* @returns {Promise<import("./types.js").ContentTaxonomyTagsData>}
|
* @returns {Promise<import("./types.mjs").ContentTaxonomyTagsData>}
|
||||||
*/
|
*/
|
||||||
export async function getContentTaxonomyTagsData(contentId) {
|
export async function getContentTaxonomyTagsData(contentId) {
|
||||||
const { data } = await getAuthenticatedHttpClient().get(getContentTaxonomyTagsApiUrl(contentId));
|
const { data } = await getAuthenticatedHttpClient().get(getContentTaxonomyTagsApiUrl(contentId));
|
||||||
@@ -70,13 +70,12 @@ export async function getContentTaxonomyTagsCount(contentId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch meta data (eg: display_name) about the content object (unit/component)
|
* Fetch meta data (eg: display_name) about the content object (unit/compoenent)
|
||||||
* @param {string} contentId The id of the content object (unit/component)
|
* @param {string} contentId The id of the content object (unit/component)
|
||||||
* @returns {Promise<import("./types.js").ContentData>}
|
* @returns {Promise<import("./types.mjs").ContentData>}
|
||||||
*/
|
*/
|
||||||
export async function getContentData(contentId) {
|
export async function getContentData(contentId) {
|
||||||
let url;
|
let url;
|
||||||
|
|
||||||
if (contentId.startsWith('lb:')) {
|
if (contentId.startsWith('lb:')) {
|
||||||
url = getLibraryContentDataApiUrl(contentId);
|
url = getLibraryContentDataApiUrl(contentId);
|
||||||
} else if (contentId.startsWith('course-v1:')) {
|
} else if (contentId.startsWith('course-v1:')) {
|
||||||
@@ -91,8 +90,8 @@ export async function getContentData(contentId) {
|
|||||||
/**
|
/**
|
||||||
* Update content object's applied tags
|
* Update content object's applied tags
|
||||||
* @param {string} contentId The id of the content object (unit/component)
|
* @param {string} contentId The id of the content object (unit/component)
|
||||||
* @param {Promise<import("./types.js").UpdateTagsData[]>} tagsData The list of tags (values) to set on content object
|
* @param {Promise<import("./types.mjs").UpdateTagsData[]>} tagsData The list of tags (values) to set on content object
|
||||||
* @returns {Promise<import("./types.js").ContentTaxonomyTagsData>}
|
* @returns {Promise<import("./types.mjs").ContentTaxonomyTagsData>}
|
||||||
*/
|
*/
|
||||||
export async function updateContentTaxonomyTags(contentId, tagsData) {
|
export async function updateContentTaxonomyTags(contentId, tagsData) {
|
||||||
const url = getContentTaxonomyTagsApiUrl(contentId);
|
const url = getContentTaxonomyTagsApiUrl(contentId);
|
||||||
|
|||||||
@@ -1,380 +0,0 @@
|
|||||||
import * as api from './api';
|
|
||||||
import * as taxonomyApi from '../../taxonomy/data/api';
|
|
||||||
import { languageExportId } from '../utils';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mock for `getContentTaxonomyTagsData()`
|
|
||||||
*/
|
|
||||||
export async function mockContentTaxonomyTagsData(contentId: string): Promise<any> {
|
|
||||||
const thisMock = mockContentTaxonomyTagsData;
|
|
||||||
switch (contentId) {
|
|
||||||
case thisMock.stagedTagsId: return thisMock.stagedTags;
|
|
||||||
case thisMock.otherTagsId: return thisMock.otherTags;
|
|
||||||
case thisMock.languageWithTagsId: return thisMock.languageWithTags;
|
|
||||||
case thisMock.languageWithoutTagsId: return thisMock.languageWithoutTags;
|
|
||||||
case thisMock.largeTagsId: return thisMock.largeTags;
|
|
||||||
case thisMock.containerTagsId: return thisMock.largeTags;
|
|
||||||
case thisMock.emptyTagsId: return thisMock.emptyTags;
|
|
||||||
default: throw new Error(`No mock has been set up for contentId "${contentId}"`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mockContentTaxonomyTagsData.stagedTagsId = 'block-v1:StagedTagsOrg+STC1+2023_1+type@vertical+block@stagedTagsId';
|
|
||||||
mockContentTaxonomyTagsData.stagedTags = {
|
|
||||||
taxonomies: [
|
|
||||||
{
|
|
||||||
name: 'Taxonomy 1',
|
|
||||||
taxonomyId: 123,
|
|
||||||
canTagObject: true,
|
|
||||||
tags: [
|
|
||||||
{
|
|
||||||
value: 'Tag 1',
|
|
||||||
lineage: ['Tag 1'],
|
|
||||||
canDeleteObjecttag: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'Tag 2',
|
|
||||||
lineage: ['Tag 2'],
|
|
||||||
canDeleteObjecttag: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
mockContentTaxonomyTagsData.otherTagsId = 'block-v1:StagedTagsOrg+STC1+2023_1+type@vertical+block@otherTagsId';
|
|
||||||
mockContentTaxonomyTagsData.otherTags = {
|
|
||||||
taxonomies: [
|
|
||||||
{
|
|
||||||
name: 'Taxonomy 1',
|
|
||||||
taxonomyId: 123,
|
|
||||||
canTagObject: true,
|
|
||||||
tags: [
|
|
||||||
{
|
|
||||||
value: 'Tag 1',
|
|
||||||
lineage: ['Tag 1'],
|
|
||||||
canDeleteObjecttag: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'Tag 2',
|
|
||||||
lineage: ['Tag 2'],
|
|
||||||
canDeleteObjecttag: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Taxonomy 2',
|
|
||||||
taxonomyId: 1234,
|
|
||||||
canTagObject: false,
|
|
||||||
tags: [
|
|
||||||
{
|
|
||||||
value: 'Tag 3',
|
|
||||||
lineage: ['Tag 3'],
|
|
||||||
canDeleteObjecttag: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'Tag 4',
|
|
||||||
lineage: ['Tag 4'],
|
|
||||||
canDeleteObjecttag: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
mockContentTaxonomyTagsData.languageWithTagsId = 'block-v1:LanguageTagsOrg+STC1+2023_1+type@vertical+block@languageWithTagsId';
|
|
||||||
mockContentTaxonomyTagsData.languageWithTags = {
|
|
||||||
taxonomies: [
|
|
||||||
{
|
|
||||||
name: 'Languages',
|
|
||||||
taxonomyId: 1234,
|
|
||||||
exportId: languageExportId,
|
|
||||||
canTagObject: true,
|
|
||||||
tags: [
|
|
||||||
{
|
|
||||||
value: 'Tag 1',
|
|
||||||
lineage: ['Tag 1'],
|
|
||||||
canDeleteObjecttag: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Taxonomy 1',
|
|
||||||
taxonomyId: 12345,
|
|
||||||
canTagObject: true,
|
|
||||||
tags: [
|
|
||||||
{
|
|
||||||
value: 'Tag 1',
|
|
||||||
lineage: ['Tag 1'],
|
|
||||||
canDeleteObjecttag: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'Tag 2',
|
|
||||||
lineage: ['Tag 2'],
|
|
||||||
canDeleteObjecttag: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
mockContentTaxonomyTagsData.languageWithoutTagsId = 'block-v1:LanguageTagsOrg+STC1+2023_1+type@vertical+block@languageWithoutTagsId';
|
|
||||||
mockContentTaxonomyTagsData.languageWithoutTags = {
|
|
||||||
taxonomies: [
|
|
||||||
{
|
|
||||||
name: 'Languages',
|
|
||||||
taxonomyId: 1234,
|
|
||||||
exportId: languageExportId,
|
|
||||||
canTagObject: true,
|
|
||||||
tags: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Taxonomy 1',
|
|
||||||
taxonomyId: 12345,
|
|
||||||
canTagObject: true,
|
|
||||||
tags: [
|
|
||||||
{
|
|
||||||
value: 'Tag 1',
|
|
||||||
lineage: ['Tag 1'],
|
|
||||||
canDeleteObjecttag: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'Tag 2',
|
|
||||||
lineage: ['Tag 2'],
|
|
||||||
canDeleteObjecttag: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
mockContentTaxonomyTagsData.largeTagsId = 'block-v1:LargeTagsOrg+STC1+2023_1+type@vertical+block@largeTagsId';
|
|
||||||
mockContentTaxonomyTagsData.largeTags = {
|
|
||||||
taxonomies: [
|
|
||||||
{
|
|
||||||
name: 'Taxonomy 1',
|
|
||||||
taxonomyId: 123,
|
|
||||||
canTagObject: true,
|
|
||||||
tags: [
|
|
||||||
{
|
|
||||||
value: 'Tag 1',
|
|
||||||
lineage: ['Tag 1'],
|
|
||||||
canDeleteObjecttag: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'Tag 2',
|
|
||||||
lineage: ['Tag 2'],
|
|
||||||
canDeleteObjecttag: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Taxonomy 2',
|
|
||||||
taxonomyId: 124,
|
|
||||||
canTagObject: true,
|
|
||||||
tags: [
|
|
||||||
{
|
|
||||||
value: 'Tag 1',
|
|
||||||
lineage: ['Tag 1'],
|
|
||||||
canDeleteObjecttag: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Taxonomy 3',
|
|
||||||
taxonomyId: 125,
|
|
||||||
canTagObject: true,
|
|
||||||
tags: [
|
|
||||||
{
|
|
||||||
value: 'Tag 1.1.1',
|
|
||||||
lineage: ['Tag 1', 'Tag 1.1', 'Tag 1.1.1'],
|
|
||||||
canDeleteObjecttag: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: '(B) Taxonomy 4',
|
|
||||||
taxonomyId: 126,
|
|
||||||
canTagObject: true,
|
|
||||||
tags: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: '(A) Taxonomy 5',
|
|
||||||
taxonomyId: 127,
|
|
||||||
canTagObject: true,
|
|
||||||
tags: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
mockContentTaxonomyTagsData.emptyTagsId = 'block-v1:EmptyTagsOrg+STC1+2023_1+type@vertical+block@emptyTagsId';
|
|
||||||
mockContentTaxonomyTagsData.emptyTags = {
|
|
||||||
taxonomies: [],
|
|
||||||
};
|
|
||||||
mockContentTaxonomyTagsData.containerTagsId = 'lct:org:lib:unit:container_tags';
|
|
||||||
mockContentTaxonomyTagsData.applyMock = () => jest.spyOn(api, 'getContentTaxonomyTagsData').mockImplementation(mockContentTaxonomyTagsData);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mock for `getTaxonomyListData()`
|
|
||||||
*/
|
|
||||||
export async function mockTaxonomyListData(org: string): Promise<any> {
|
|
||||||
const thisMock = mockTaxonomyListData;
|
|
||||||
switch (org) {
|
|
||||||
case thisMock.stagedTagsOrg: return thisMock.stagedTags;
|
|
||||||
case thisMock.languageTagsOrg: return thisMock.languageTags;
|
|
||||||
case thisMock.largeTagsOrg: return thisMock.largeTags;
|
|
||||||
case thisMock.emptyTagsOrg: return thisMock.emptyTags;
|
|
||||||
default: throw new Error(`No mock has been set up for org "${org}"`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mockTaxonomyListData.stagedTagsOrg = 'StagedTagsOrg';
|
|
||||||
mockTaxonomyListData.stagedTags = {
|
|
||||||
results: [
|
|
||||||
{
|
|
||||||
id: 123,
|
|
||||||
name: 'Taxonomy 1',
|
|
||||||
description: 'This is a description 1',
|
|
||||||
canTagObject: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
mockTaxonomyListData.languageTagsOrg = 'LanguageTagsOrg';
|
|
||||||
mockTaxonomyListData.languageTags = {
|
|
||||||
results: [
|
|
||||||
{
|
|
||||||
id: 1234,
|
|
||||||
name: 'Languages',
|
|
||||||
description: 'This is a description 1',
|
|
||||||
exportId: languageExportId,
|
|
||||||
canTagObject: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 12345,
|
|
||||||
name: 'Taxonomy 1',
|
|
||||||
description: 'This is a description 2',
|
|
||||||
canTagObject: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
mockTaxonomyListData.largeTagsOrg = 'LargeTagsOrg';
|
|
||||||
mockTaxonomyListData.largeTags = {
|
|
||||||
results: [
|
|
||||||
{
|
|
||||||
id: 123,
|
|
||||||
name: 'Taxonomy 1',
|
|
||||||
description: 'This is a description 1',
|
|
||||||
canTagObject: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 124,
|
|
||||||
name: 'Taxonomy 2',
|
|
||||||
description: 'This is a description 2',
|
|
||||||
canTagObject: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 125,
|
|
||||||
name: 'Taxonomy 3',
|
|
||||||
description: 'This is a description 3',
|
|
||||||
canTagObject: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 127,
|
|
||||||
name: '(A) Taxonomy 5',
|
|
||||||
description: 'This is a description 5',
|
|
||||||
canTagObject: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 126,
|
|
||||||
name: '(B) Taxonomy 4',
|
|
||||||
description: 'This is a description 4',
|
|
||||||
canTagObject: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
mockTaxonomyListData.emptyTagsOrg = 'EmptyTagsOrg';
|
|
||||||
mockTaxonomyListData.emptyTags = {
|
|
||||||
results: [],
|
|
||||||
};
|
|
||||||
mockTaxonomyListData.applyMock = () => jest.spyOn(taxonomyApi, 'getTaxonomyListData').mockImplementation(mockTaxonomyListData);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mock for `getTaxonomyTagsData()`
|
|
||||||
*/
|
|
||||||
export async function mockTaxonomyTagsData(taxonomyId: number): Promise<any> {
|
|
||||||
const thisMock = mockTaxonomyTagsData;
|
|
||||||
switch (taxonomyId) {
|
|
||||||
case thisMock.stagedTagsTaxonomy: return thisMock.stagedTags;
|
|
||||||
case thisMock.languageTagsTaxonomy: return thisMock.languageTags;
|
|
||||||
default: throw new Error(`No mock has been set up for taxonomyId "${taxonomyId}"`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mockTaxonomyTagsData.stagedTagsTaxonomy = 123;
|
|
||||||
mockTaxonomyTagsData.stagedTags = {
|
|
||||||
count: 3,
|
|
||||||
currentPage: 1,
|
|
||||||
next: null,
|
|
||||||
numPages: 1,
|
|
||||||
previous: null,
|
|
||||||
start: 1,
|
|
||||||
results: [
|
|
||||||
{
|
|
||||||
value: 'Tag 1',
|
|
||||||
externalId: null,
|
|
||||||
childCount: 0,
|
|
||||||
depth: 0,
|
|
||||||
parentValue: null,
|
|
||||||
id: 12345,
|
|
||||||
subTagsUrl: null,
|
|
||||||
canChangeTag: false,
|
|
||||||
canDeleteTag: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'Tag 2',
|
|
||||||
externalId: null,
|
|
||||||
childCount: 0,
|
|
||||||
depth: 0,
|
|
||||||
parentValue: null,
|
|
||||||
id: 12346,
|
|
||||||
subTagsUrl: null,
|
|
||||||
canChangeTag: false,
|
|
||||||
canDeleteTag: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'Tag 3',
|
|
||||||
externalId: null,
|
|
||||||
childCount: 0,
|
|
||||||
depth: 0,
|
|
||||||
parentValue: null,
|
|
||||||
id: 12347,
|
|
||||||
subTagsUrl: null,
|
|
||||||
canChangeTag: false,
|
|
||||||
canDeleteTag: false,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
mockTaxonomyTagsData.languageTagsTaxonomy = 1234;
|
|
||||||
mockTaxonomyTagsData.languageTags = {
|
|
||||||
count: 1,
|
|
||||||
currentPage: 1,
|
|
||||||
next: null,
|
|
||||||
numPages: 1,
|
|
||||||
previous: null,
|
|
||||||
start: 1,
|
|
||||||
results: [{
|
|
||||||
value: 'Tag 1',
|
|
||||||
externalId: null,
|
|
||||||
childCount: 0,
|
|
||||||
depth: 0,
|
|
||||||
parentValue: null,
|
|
||||||
id: 12345,
|
|
||||||
subTagsUrl: null,
|
|
||||||
canChangeTag: false,
|
|
||||||
canDeleteTag: false,
|
|
||||||
}],
|
|
||||||
};
|
|
||||||
mockTaxonomyTagsData.applyMock = () => jest.spyOn(api, 'getTaxonomyTagsData').mockImplementation(mockTaxonomyTagsData);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mock for `getContentData()`
|
|
||||||
*/
|
|
||||||
export async function mockContentData(): Promise<any> {
|
|
||||||
return mockContentData.data;
|
|
||||||
}
|
|
||||||
mockContentData.data = {
|
|
||||||
displayName: 'Unit 1',
|
|
||||||
};
|
|
||||||
mockContentData.applyMock = () => jest.spyOn(api, 'getContentData').mockImplementation(mockContentData);
|
|
||||||
@@ -14,11 +14,9 @@ import {
|
|||||||
updateContentTaxonomyTags,
|
updateContentTaxonomyTags,
|
||||||
getContentTaxonomyTagsCount,
|
getContentTaxonomyTagsCount,
|
||||||
} from './api';
|
} from './api';
|
||||||
import { libraryQueryPredicate, xblockQueryKeys } from '../../library-authoring/data/apiHooks';
|
|
||||||
import { getLibraryId } from '../../generic/key-utils';
|
|
||||||
|
|
||||||
/** @typedef {import("../../taxonomy/data/types.js").TagListData} TagListData */
|
/** @typedef {import("../../taxonomy/tag-list/data/types.mjs").TagListData} TagListData */
|
||||||
/** @typedef {import("../../taxonomy/data/types.js").TagData} TagData */
|
/** @typedef {import("../../taxonomy/tag-list/data/types.mjs").TagData} TagData */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the query to get the taxonomy tags
|
* Builds the query to get the taxonomy tags
|
||||||
@@ -112,13 +110,11 @@ export const useContentTaxonomyTagsData = (contentId) => (
|
|||||||
/**
|
/**
|
||||||
* Builds the query to get meta data about the content object
|
* Builds the query to get meta data about the content object
|
||||||
* @param {string} contentId The id of the content object (unit/component)
|
* @param {string} contentId The id of the content object (unit/component)
|
||||||
* @param {boolean} enabled Flag to enable/disable the query
|
|
||||||
*/
|
*/
|
||||||
export const useContentData = (contentId, enabled) => (
|
export const useContentData = (contentId) => (
|
||||||
useQuery({
|
useQuery({
|
||||||
queryKey: ['contentData', contentId],
|
queryKey: ['contentData', contentId],
|
||||||
queryFn: enabled ? () => getContentData(contentId) : undefined,
|
queryFn: () => getContentData(contentId),
|
||||||
enabled,
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -128,7 +124,6 @@ export const useContentData = (contentId, enabled) => (
|
|||||||
*/
|
*/
|
||||||
export const useContentTaxonomyTagsUpdater = (contentId) => {
|
export const useContentTaxonomyTagsUpdater = (contentId) => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const unitIframe = window.frames['xblock-iframe'];
|
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
/**
|
/**
|
||||||
@@ -136,7 +131,7 @@ export const useContentTaxonomyTagsUpdater = (contentId) => {
|
|||||||
* any,
|
* any,
|
||||||
* any,
|
* any,
|
||||||
* {
|
* {
|
||||||
* tagsData: Promise<import("./types.js").UpdateTagsData[]>
|
* tagsData: Promise<import("./types.mjs").UpdateTagsData[]>
|
||||||
* }
|
* }
|
||||||
* >}
|
* >}
|
||||||
*/
|
*/
|
||||||
@@ -151,20 +146,11 @@ export const useContentTaxonomyTagsUpdater = (contentId) => {
|
|||||||
contentPattern = contentId.replace(/\+type@.*$/, '*');
|
contentPattern = contentId.replace(/\+type@.*$/, '*');
|
||||||
}
|
}
|
||||||
queryClient.invalidateQueries({ queryKey: ['contentTagsCount', contentPattern] });
|
queryClient.invalidateQueries({ queryKey: ['contentTagsCount', contentPattern] });
|
||||||
if (contentId.startsWith('lb:') || contentId.startsWith('lib-collection:') || contentId.startsWith('lct:')) {
|
|
||||||
// Obtain library id from contentId
|
|
||||||
const libraryId = getLibraryId(contentId);
|
|
||||||
// Invalidate component metadata to update tags count
|
|
||||||
queryClient.invalidateQueries(xblockQueryKeys.componentMetadata(contentId));
|
|
||||||
// Invalidate content search to update tags count
|
|
||||||
queryClient.invalidateQueries(['content_search'], { predicate: (query) => libraryQueryPredicate(query, libraryId) });
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onSuccess: /* istanbul ignore next */ () => {
|
onSuccess: /* istanbul ignore next */ () => {
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
if (window.top != null) {
|
if (window.top != null) {
|
||||||
// Sends messages to the parent page if the drawer was opened
|
// This send messages to the parent page if the drawer is called from a iframe.
|
||||||
// from an iframe or the unit iframe within the course.
|
|
||||||
// Is used on Studio to update tags data and counts.
|
// Is used on Studio to update tags data and counts.
|
||||||
// In the future, when the Course Outline Page and Unit Page are integrated into this MFE,
|
// In the future, when the Course Outline Page and Unit Page are integrated into this MFE,
|
||||||
// they should just use React Query to load the tag counts, and React Query will automatically
|
// they should just use React Query to load the tag counts, and React Query will automatically
|
||||||
@@ -173,32 +159,26 @@ export const useContentTaxonomyTagsUpdater = (contentId) => {
|
|||||||
|
|
||||||
// Sends content tags.
|
// Sends content tags.
|
||||||
getContentTaxonomyTagsData(contentId).then((data) => {
|
getContentTaxonomyTagsData(contentId).then((data) => {
|
||||||
const contentData = { contentId, ...data };
|
const contentData = {
|
||||||
|
contentId,
|
||||||
const message = {
|
...data,
|
||||||
type: 'authoring.events.tags.updated',
|
|
||||||
data: contentData,
|
|
||||||
};
|
};
|
||||||
|
window.top?.postMessage(
|
||||||
const targetOrigin = getConfig().STUDIO_BASE_URL;
|
{ type: 'authoring.events.tags.updated', data: contentData },
|
||||||
|
getConfig().STUDIO_BASE_URL,
|
||||||
unitIframe?.postMessage(message, targetOrigin);
|
);
|
||||||
window.top?.postMessage(message, targetOrigin);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Sends tags count.
|
// Sends tags count.
|
||||||
getContentTaxonomyTagsCount(contentId).then((count) => {
|
getContentTaxonomyTagsCount(contentId).then((data) => {
|
||||||
const contentData = { contentId, count };
|
const contentData = {
|
||||||
|
contentId,
|
||||||
const message = {
|
count: data,
|
||||||
type: 'authoring.events.tags.count.updated',
|
|
||||||
data: contentData,
|
|
||||||
};
|
};
|
||||||
|
window.top?.postMessage(
|
||||||
const targetOrigin = getConfig().STUDIO_BASE_URL;
|
{ type: 'authoring.events.tags.count.updated', data: contentData },
|
||||||
|
getConfig().STUDIO_BASE_URL,
|
||||||
unitIframe?.postMessage(message, targetOrigin);
|
);
|
||||||
window.top?.postMessage(message, targetOrigin);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useQuery, useMutation, useQueries } from '@tanstack/react-query';
|
import { useQuery, useMutation, useQueries } from '@tanstack/react-query';
|
||||||
import { act, renderHook } from '@testing-library/react';
|
import { act } from '@testing-library/react';
|
||||||
|
import { renderHook } from '@testing-library/react-hooks';
|
||||||
import {
|
import {
|
||||||
useTaxonomyTagsData,
|
useTaxonomyTagsData,
|
||||||
useContentTaxonomyTagsData,
|
useContentTaxonomyTagsData,
|
||||||
|
|||||||
101
src/content-tags-drawer/data/types.mjs
Normal file
101
src/content-tags-drawer/data/types.mjs
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
// @ts-check
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} Tag A tag that has been applied to some content.
|
||||||
|
* @property {string} value The value of the tag, also its ID. e.g. "Biology"
|
||||||
|
* @property {string[]} lineage The values of the tag and its parent(s) in the hierarchy
|
||||||
|
* @property {boolean} canChangeObjecttag
|
||||||
|
* @property {boolean} canDeleteObjecttag
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} ContentTaxonomyTagData A list of the tags from one taxonomy that are applied to a content object.
|
||||||
|
* @property {string} name
|
||||||
|
* @property {number} taxonomyId
|
||||||
|
* @property {boolean} canTagObject
|
||||||
|
* @property {Tag[]} tags
|
||||||
|
* @property {string} exportId
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} ContentTaxonomyTagsData A list of all the tags applied to some content object, grouped by taxonomy.
|
||||||
|
* @property {ContentTaxonomyTagData[]} taxonomies
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} ContentActions
|
||||||
|
* @property {boolean} deleteable
|
||||||
|
* @property {boolean} draggable
|
||||||
|
* @property {boolean} childAddable
|
||||||
|
* @property {boolean} duplicable
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} XBlockData
|
||||||
|
* @property {string} id
|
||||||
|
* @property {string} displayName
|
||||||
|
* @property {string} category
|
||||||
|
* @property {boolean} hasChildren
|
||||||
|
* @property {string} editedOn
|
||||||
|
* @property {boolean} published
|
||||||
|
* @property {string} publishedOn
|
||||||
|
* @property {string} studioUrl
|
||||||
|
* @property {boolean} releasedToStudents
|
||||||
|
* @property {string|null} releaseDate
|
||||||
|
* @property {string} visibilityState
|
||||||
|
* @property {boolean} hasExplicitStaffLock
|
||||||
|
* @property {string} start
|
||||||
|
* @property {boolean} graded
|
||||||
|
* @property {string} dueDate
|
||||||
|
* @property {string} due
|
||||||
|
* @property {string|null} relativeWeeksDue
|
||||||
|
* @property {string|null} format
|
||||||
|
* @property {boolean} hasChanges
|
||||||
|
* @property {ContentActions} actions
|
||||||
|
* @property {string} explanatoryMessage
|
||||||
|
* @property {string} showCorrectness
|
||||||
|
* @property {boolean} discussionEnabled
|
||||||
|
* @property {boolean} ancestorHasStaffLock
|
||||||
|
* @property {boolean} staffOnlyMessage
|
||||||
|
* @property {boolean} hasPartitionGroupComponents
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} TagsInTaxonomy
|
||||||
|
* @property {boolean} allOrgs
|
||||||
|
* @property {boolean} allowFreeText
|
||||||
|
* @property {boolean} allowMultiple
|
||||||
|
* @property {boolean} canChangeTaxonomy
|
||||||
|
* @property {boolean} canDeleteTaxonomy
|
||||||
|
* @property {boolean} canTagObject
|
||||||
|
* @property {Tag[]} contentTags
|
||||||
|
* @property {string} description
|
||||||
|
* @property {boolean} enabled
|
||||||
|
* @property {string} exportId
|
||||||
|
* @property {number} id
|
||||||
|
* @property {string} name
|
||||||
|
* @property {boolean} systemDefined
|
||||||
|
* @property {number} tagsCount
|
||||||
|
* @property {boolean} visibleToAuthors
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} CourseData
|
||||||
|
* @property {string} courseDisplayNameWithDefault
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {XBlockData | CourseData} ContentData
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} UpdateTagsData
|
||||||
|
* @property {number} taxonomy
|
||||||
|
* @property {string[]} tags
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} StagedTagData
|
||||||
|
* @property {string} value
|
||||||
|
* @property {string} label
|
||||||
|
*/
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
import type { TaxonomyData } from '../../taxonomy/data/types';
|
|
||||||
|
|
||||||
/** A tag that has been applied to some content. */
|
|
||||||
export interface Tag {
|
|
||||||
/** The value of the tag, also its ID. e.g. "Biology" */
|
|
||||||
value: string;
|
|
||||||
/** The values of the tag and its parent(s) in the hierarchy */
|
|
||||||
lineage: string[];
|
|
||||||
canChangeObjecttag: boolean;
|
|
||||||
canDeleteObjecttag: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** A list of the tags from one taxonomy that are applied to a content object. */
|
|
||||||
export interface ContentTaxonomyTagData {
|
|
||||||
name: string;
|
|
||||||
taxonomyId: number;
|
|
||||||
canTagObject: boolean;
|
|
||||||
tags: Tag[];
|
|
||||||
exportId: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** A list of all the tags applied to some content object, grouped by taxonomy. */
|
|
||||||
export interface ContentTaxonomyTagsData {
|
|
||||||
taxonomies: ContentTaxonomyTagData[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ContentActions {
|
|
||||||
deleteable: boolean;
|
|
||||||
draggable: boolean;
|
|
||||||
childAddable: boolean;
|
|
||||||
duplicable: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface XBlockData {
|
|
||||||
id: string;
|
|
||||||
displayName: string;
|
|
||||||
category: string;
|
|
||||||
hasChildren: boolean;
|
|
||||||
editedOn: string;
|
|
||||||
published: boolean;
|
|
||||||
publishedOn: string;
|
|
||||||
studioUrl: string;
|
|
||||||
releasedToStudents: boolean;
|
|
||||||
releaseDate: string | null;
|
|
||||||
visibilityState: string;
|
|
||||||
hasExplicitStaffLock: boolean;
|
|
||||||
start: string;
|
|
||||||
graded: boolean;
|
|
||||||
dueDate: string;
|
|
||||||
due: string;
|
|
||||||
relativeWeeksDue: string | null;
|
|
||||||
format: string | null;
|
|
||||||
hasChanges: boolean;
|
|
||||||
actions: ContentActions;
|
|
||||||
explanatoryMessage: string;
|
|
||||||
showCorrectness: string;
|
|
||||||
discussionEnabled: boolean;
|
|
||||||
ancestorHasStaffLock: boolean;
|
|
||||||
staffOnlyMessage: boolean;
|
|
||||||
hasPartitionGroupComponents: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TagsInTaxonomy extends TaxonomyData {
|
|
||||||
contentTags: Tag[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CourseData {
|
|
||||||
courseDisplayNameWithDefault: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ContentData = XBlockData | CourseData;
|
|
||||||
|
|
||||||
export interface UpdateTagsData {
|
|
||||||
taxonomy: number;
|
|
||||||
tags: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StagedTagData {
|
|
||||||
value: string;
|
|
||||||
label: string;
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// eslint-disable-next-line import/prefer-default-export
|
||||||
export { default as ContentTagsDrawer } from './ContentTagsDrawer';
|
export { default as ContentTagsDrawer } from './ContentTagsDrawer';
|
||||||
|
// eslint-disable-next-line import/prefer-default-export
|
||||||
export { default as ContentTagsDrawerSheet } from './ContentTagsDrawerSheet';
|
export { default as ContentTagsDrawerSheet } from './ContentTagsDrawerSheet';
|
||||||
export { useContentTaxonomyTagsData } from './data/apiHooks';
|
|
||||||
@@ -69,7 +69,7 @@ const messages = defineMessages({
|
|||||||
defaultMessage: 'Add a tag',
|
defaultMessage: 'Add a tag',
|
||||||
},
|
},
|
||||||
collapsibleNoTagsAddedText: {
|
collapsibleNoTagsAddedText: {
|
||||||
id: 'course-authoring.content-tags-drawer.content-tags-collapsible.custom-menu.no-tags-added-text',
|
id: 'course-authoring.content-tags-drawer.content-tags-collapsible.custom-menu.placeholder-text',
|
||||||
defaultMessage: 'No tags added yet.',
|
defaultMessage: 'No tags added yet.',
|
||||||
},
|
},
|
||||||
collapsibleAddStagedTagsButtonText: {
|
collapsibleAddStagedTagsButtonText: {
|
||||||
@@ -15,7 +15,7 @@ const TagsSidebarHeader = () => {
|
|||||||
const {
|
const {
|
||||||
data: contentTagsCount,
|
data: contentTagsCount,
|
||||||
isSuccess: isContentTagsCountLoaded,
|
isSuccess: isContentTagsCountLoaded,
|
||||||
} = useContentTagsCount(contentId);
|
} = useContentTagsCount(contentId || '');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
|
|||||||
3
src/content-tags-drawer/utils.js
Normal file
3
src/content-tags-drawer/utils.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
// eslint-disable-next-line import/prefer-default-export
|
||||||
|
export const extractOrgFromContentId = (contentId) => contentId.split('+')[0].split(':')[1];
|
||||||
|
export const languageExportId = 'languages-v1';
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
export const extractOrgFromContentId = (contentId: string): string => contentId.split('+')[0].split(':')[1];
|
|
||||||
export const languageExportId = 'languages-v1';
|
|
||||||
@@ -1,95 +1,70 @@
|
|||||||
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Link } from 'react-router-dom';
|
import { injectIntl, intlShape, FormattedMessage } from '@edx/frontend-platform/i18n';
|
||||||
import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
|
import {
|
||||||
import { ActionRow, Button, Icon } from '@openedx/paragon';
|
ActionRow,
|
||||||
import { useSelector } from 'react-redux';
|
Button,
|
||||||
|
Hyperlink,
|
||||||
|
Icon,
|
||||||
|
} from '@openedx/paragon';
|
||||||
import { CheckCircle, RadioButtonUnchecked } from '@openedx/paragon/icons';
|
import { CheckCircle, RadioButtonUnchecked } from '@openedx/paragon/icons';
|
||||||
import { getConfig } from '@edx/frontend-platform';
|
|
||||||
|
|
||||||
import { getWaffleFlags } from '../../data/selectors';
|
|
||||||
import messages from './messages';
|
import messages from './messages';
|
||||||
|
|
||||||
const getUpdateLinks = (courseId, waffleFlags) => {
|
|
||||||
const baseUrl = getConfig().STUDIO_BASE_URL;
|
|
||||||
const isLegacyGradingUrl = !waffleFlags.useNewGradingPage;
|
|
||||||
const isLegacyCertificateUrl = !waffleFlags.useNewCertificatesPage;
|
|
||||||
const isLegacyCourseDatesUrl = !waffleFlags.useNewScheduleDetailsPage;
|
|
||||||
const isLegacyOutlineUrl = !waffleFlags.useNewCourseOutlinePage;
|
|
||||||
|
|
||||||
return {
|
|
||||||
welcomeMessage: `/course/${courseId}/course_info`,
|
|
||||||
gradingPolicy: isLegacyGradingUrl
|
|
||||||
? `${baseUrl}/settings/grading/${courseId}` : `/course/${courseId}/settings/grading`,
|
|
||||||
certificate: isLegacyCertificateUrl
|
|
||||||
? `${baseUrl}/certificates/${courseId}` : `/course/${courseId}/certificates`,
|
|
||||||
courseDates: isLegacyCourseDatesUrl
|
|
||||||
? `${baseUrl}/settings/details/${courseId}#schedule` : `/course/${courseId}/settings/details/#schedule`,
|
|
||||||
proctoringEmail: `${baseUrl}/pages-and-resources/proctoring/settings`,
|
|
||||||
outline: isLegacyOutlineUrl ? `${baseUrl}/course/${courseId}` : `/course/${courseId}`,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const ChecklistItemBody = ({
|
const ChecklistItemBody = ({
|
||||||
courseId,
|
|
||||||
checkId,
|
checkId,
|
||||||
isCompleted,
|
isCompleted,
|
||||||
}) => {
|
updateLink,
|
||||||
const intl = useIntl();
|
// injected
|
||||||
const waffleFlags = useSelector(getWaffleFlags);
|
intl,
|
||||||
const updateLinks = getUpdateLinks(courseId, waffleFlags);
|
}) => (
|
||||||
|
<ActionRow>
|
||||||
return (
|
<div className="mr-3" id={`icon-${checkId}`} data-testid={`icon-${checkId}`}>
|
||||||
<ActionRow>
|
{isCompleted ? (
|
||||||
<div className="mr-3" id={`icon-${checkId}`} data-testid={`icon-${checkId}`}>
|
<Icon
|
||||||
{isCompleted ? (
|
data-testid="completed-icon"
|
||||||
<Icon
|
src={CheckCircle}
|
||||||
data-testid="completed-icon"
|
className="text-success"
|
||||||
src={CheckCircle}
|
style={{ height: '32px', width: '32px' }}
|
||||||
className="text-success"
|
screenReaderText={intl.formatMessage(messages.completedItemLabel)}
|
||||||
style={{ height: '32px', width: '32px' }}
|
/>
|
||||||
screenReaderText={intl.formatMessage(messages.completedItemLabel)}
|
) : (
|
||||||
/>
|
<Icon
|
||||||
) : (
|
data-testid="uncompleted-icon"
|
||||||
<Icon
|
src={RadioButtonUnchecked}
|
||||||
data-testid="uncompleted-icon"
|
style={{ height: '32px', width: '32px' }}
|
||||||
src={RadioButtonUnchecked}
|
screenReaderText={intl.formatMessage(messages.uncompletedItemLabel)}
|
||||||
style={{ height: '32px', width: '32px' }}
|
/>
|
||||||
screenReaderText={intl.formatMessage(messages.uncompletedItemLabel)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div>
|
|
||||||
<FormattedMessage {...messages[`${checkId}ShortDescription`]} />
|
|
||||||
</div>
|
|
||||||
<div className="small">
|
|
||||||
<FormattedMessage {...messages[`${checkId}LongDescription`]} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<ActionRow.Spacer />
|
|
||||||
{updateLinks?.[checkId] && (
|
|
||||||
<Link
|
|
||||||
to={updateLinks[checkId]}
|
|
||||||
data-testid="update-link"
|
|
||||||
>
|
|
||||||
<Button size="sm">
|
|
||||||
<FormattedMessage {...messages.updateLinkLabel} />
|
|
||||||
</Button>
|
|
||||||
</Link>
|
|
||||||
)}
|
)}
|
||||||
</ActionRow>
|
</div>
|
||||||
);
|
<div>
|
||||||
};
|
<div>
|
||||||
|
<FormattedMessage {...messages[`${checkId}ShortDescription`]} />
|
||||||
|
</div>
|
||||||
|
<div className="small">
|
||||||
|
<FormattedMessage {...messages[`${checkId}LongDescription`]} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<ActionRow.Spacer />
|
||||||
|
{updateLink && (
|
||||||
|
<Hyperlink destination={updateLink} data-testid="update-hyperlink">
|
||||||
|
<Button size="sm">
|
||||||
|
<FormattedMessage {...messages.updateLinkLabel} />
|
||||||
|
</Button>
|
||||||
|
</Hyperlink>
|
||||||
|
)}
|
||||||
|
</ActionRow>
|
||||||
|
);
|
||||||
|
|
||||||
ChecklistItemBody.defaultProps = {
|
ChecklistItemBody.defaultProps = {
|
||||||
updateLink: null,
|
updateLink: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
ChecklistItemBody.propTypes = {
|
ChecklistItemBody.propTypes = {
|
||||||
courseId: PropTypes.string.isRequired,
|
|
||||||
checkId: PropTypes.string.isRequired,
|
checkId: PropTypes.string.isRequired,
|
||||||
isCompleted: PropTypes.bool.isRequired,
|
isCompleted: PropTypes.bool.isRequired,
|
||||||
updateLink: PropTypes.string,
|
updateLink: PropTypes.string,
|
||||||
|
// injected
|
||||||
|
intl: intlShape.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ChecklistItemBody;
|
export default injectIntl(ChecklistItemBody);
|
||||||
|
|||||||
@@ -1,23 +1,15 @@
|
|||||||
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { useSelector } from 'react-redux';
|
|
||||||
import { injectIntl, FormattedMessage, FormattedNumber } from '@edx/frontend-platform/i18n';
|
import { injectIntl, FormattedMessage, FormattedNumber } from '@edx/frontend-platform/i18n';
|
||||||
import { Icon } from '@openedx/paragon';
|
import { Hyperlink, Icon } from '@openedx/paragon';
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
import { ModeComment } from '@openedx/paragon/icons';
|
import { ModeComment } from '@openedx/paragon/icons';
|
||||||
import { getConfig } from '@edx/frontend-platform';
|
|
||||||
import { getWaffleFlags } from '../../data/selectors';
|
|
||||||
import messages from './messages';
|
import messages from './messages';
|
||||||
|
|
||||||
const ChecklistItemComment = ({
|
const ChecklistItemComment = ({
|
||||||
courseId,
|
|
||||||
checkId,
|
checkId,
|
||||||
|
outlineUrl,
|
||||||
data,
|
data,
|
||||||
}) => {
|
}) => {
|
||||||
const waffleFlags = useSelector(getWaffleFlags);
|
|
||||||
|
|
||||||
const getPathToCourseOutlinePage = (assignmentId) => (waffleFlags.useNewCourseOutlinePage
|
|
||||||
? `/course/${courseId}#${assignmentId}` : `${getConfig().STUDIO_BASE_URL}/course/${courseId}#${assignmentId}`);
|
|
||||||
|
|
||||||
const commentWrapper = (comment) => (
|
const commentWrapper = (comment) => (
|
||||||
<div className="row m-0 mt-3 pt-3 border-top align-items-center" data-identifier="comment">
|
<div className="row m-0 mt-3 pt-3 border-top align-items-center" data-identifier="comment">
|
||||||
<div className="mr-4">
|
<div className="mr-4">
|
||||||
@@ -87,9 +79,10 @@ const ChecklistItemComment = ({
|
|||||||
<ul className="assignment-list">
|
<ul className="assignment-list">
|
||||||
{gradedAssignmentsOutsideDateRange.map(assignment => (
|
{gradedAssignmentsOutsideDateRange.map(assignment => (
|
||||||
<li className="assignment-list-item" key={assignment.id}>
|
<li className="assignment-list-item" key={assignment.id}>
|
||||||
<Link to={getPathToCourseOutlinePage(assignment.id)}>
|
<Hyperlink
|
||||||
{assignment.displayName}
|
content={assignment.displayName}
|
||||||
</Link>
|
destination={`${outlineUrl}#${assignment.id}`}
|
||||||
|
/>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -104,7 +97,6 @@ const ChecklistItemComment = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
ChecklistItemComment.propTypes = {
|
ChecklistItemComment.propTypes = {
|
||||||
courseId: PropTypes.string.isRequired,
|
|
||||||
checkId: PropTypes.string.isRequired,
|
checkId: PropTypes.string.isRequired,
|
||||||
outlineUrl: PropTypes.string.isRequired,
|
outlineUrl: PropTypes.string.isRequired,
|
||||||
data: PropTypes.oneOfType([
|
data: PropTypes.oneOfType([
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ import ChecklistItemComment from './ChecklistItemComment';
|
|||||||
import { checklistItems } from './utils/courseChecklistData';
|
import { checklistItems } from './utils/courseChecklistData';
|
||||||
|
|
||||||
const ChecklistSection = ({
|
const ChecklistSection = ({
|
||||||
courseId,
|
|
||||||
dataHeading,
|
dataHeading,
|
||||||
data,
|
data,
|
||||||
idPrefix,
|
idPrefix,
|
||||||
isLoading,
|
isLoading,
|
||||||
|
updateLinks,
|
||||||
}) => {
|
}) => {
|
||||||
const dataList = checklistItems[idPrefix];
|
const dataList = checklistItems[idPrefix];
|
||||||
const getCompletionCountID = () => (`${idPrefix}-completion-count`);
|
const getCompletionCountID = () => (`${idPrefix}-completion-count`);
|
||||||
@@ -37,6 +37,8 @@ const ChecklistSection = ({
|
|||||||
{checks.map(check => {
|
{checks.map(check => {
|
||||||
const checkId = check.id;
|
const checkId = check.id;
|
||||||
const isCompleted = values[checkId];
|
const isCompleted = values[checkId];
|
||||||
|
const updateLink = updateLinks?.[checkId];
|
||||||
|
const outlineUrl = updateLinks.outline;
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`bg-white border py-3 px-4 ${isCompleted && 'checklist-item-complete'}`}
|
className={`bg-white border py-3 px-4 ${isCompleted && 'checklist-item-complete'}`}
|
||||||
@@ -44,9 +46,9 @@ const ChecklistSection = ({
|
|||||||
data-testid={`checklist-item-${checkId}`}
|
data-testid={`checklist-item-${checkId}`}
|
||||||
key={checkId}
|
key={checkId}
|
||||||
>
|
>
|
||||||
<ChecklistItemBody courseId={courseId} {...{ checkId, isCompleted }} />
|
<ChecklistItemBody {...{ checkId, isCompleted, updateLink }} />
|
||||||
<div data-testid={`comment-section-${checkId}`}>
|
<div data-testid={`comment-section-${checkId}`}>
|
||||||
<ChecklistItemComment {...{ courseId, checkId, data }} />
|
<ChecklistItemComment {...{ checkId, outlineUrl, data }} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -59,11 +61,11 @@ const ChecklistSection = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
ChecklistSection.defaultProps = {
|
ChecklistSection.defaultProps = {
|
||||||
|
updateLinks: {},
|
||||||
data: {},
|
data: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
ChecklistSection.propTypes = {
|
ChecklistSection.propTypes = {
|
||||||
courseId: PropTypes.string.isRequired,
|
|
||||||
dataHeading: PropTypes.string.isRequired,
|
dataHeading: PropTypes.string.isRequired,
|
||||||
data: PropTypes.oneOfType([
|
data: PropTypes.oneOfType([
|
||||||
PropTypes.shape({
|
PropTypes.shape({
|
||||||
@@ -127,6 +129,14 @@ ChecklistSection.propTypes = {
|
|||||||
]),
|
]),
|
||||||
idPrefix: PropTypes.string.isRequired,
|
idPrefix: PropTypes.string.isRequired,
|
||||||
isLoading: PropTypes.bool.isRequired,
|
isLoading: PropTypes.bool.isRequired,
|
||||||
|
updateLinks: PropTypes.shape({
|
||||||
|
welcomeMessage: PropTypes.string,
|
||||||
|
gradingPolicy: PropTypes.string,
|
||||||
|
certificate: PropTypes.string,
|
||||||
|
courseDates: PropTypes.string,
|
||||||
|
proctoringEmail: PropTypes.string,
|
||||||
|
outline: PropTypes.string,
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default injectIntl(ChecklistSection);
|
export default injectIntl(ChecklistSection);
|
||||||
|
|||||||
@@ -1,49 +1,59 @@
|
|||||||
import { camelCaseObject } from '@edx/frontend-platform';
|
/* eslint-disable */
|
||||||
|
|
||||||
import {
|
import {
|
||||||
initializeMocks, render, screen, within,
|
render,
|
||||||
} from '../../testUtils';
|
within,
|
||||||
import { getApiWaffleFlagsUrl } from '../../data/api';
|
screen,
|
||||||
import { fetchWaffleFlags } from '../../data/thunks';
|
} from '@testing-library/react';
|
||||||
import { generateCourseLaunchData } from '../factories/mockApiResponses';
|
import '@testing-library/jest-dom';
|
||||||
import { executeThunk } from '../../utils';
|
import { camelCaseObject, initializeMockApp } from '@edx/frontend-platform';
|
||||||
import { checklistItems } from './utils/courseChecklistData';
|
import { AppProvider } from '@edx/frontend-platform/react';
|
||||||
import messages from './messages';
|
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||||
|
|
||||||
import ChecklistSection from '.';
|
import initializeStore from '../../store';
|
||||||
|
import { initialState,generateCourseLaunchData } from '../factories/mockApiResponses';
|
||||||
|
import messages from './messages';
|
||||||
|
import ChecklistSection from './index';
|
||||||
|
import { checklistItems } from './utils/courseChecklistData';
|
||||||
|
import getUpdateLinks from '../utils';
|
||||||
|
|
||||||
const testData = camelCaseObject(generateCourseLaunchData());
|
const testData = camelCaseObject(generateCourseLaunchData());
|
||||||
|
|
||||||
const courseId = '123';
|
|
||||||
|
|
||||||
const defaultProps = {
|
const defaultProps = {
|
||||||
courseId,
|
|
||||||
data: testData,
|
data: testData,
|
||||||
dataHeading: 'Test checklist',
|
dataHeading: 'Test checklist',
|
||||||
idPrefix: 'launchChecklist',
|
idPrefix: 'launchChecklist',
|
||||||
|
updateLinks: getUpdateLinks('courseId'),
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const testChecklistData = checklistItems[defaultProps.idPrefix];
|
const testChecklistData = checklistItems[defaultProps.idPrefix];
|
||||||
|
|
||||||
const completedItemIds = ['welcomeMessage', 'courseDates'];
|
const completedItemIds = ['welcomeMessage', 'courseDates']
|
||||||
|
|
||||||
const renderComponent = (props) => {
|
const renderComponent = (props) => {
|
||||||
render(<ChecklistSection {...props} />);
|
render(
|
||||||
|
<IntlProvider locale="en">
|
||||||
|
<AppProvider store={store}>
|
||||||
|
<ChecklistSection {...props} />
|
||||||
|
</AppProvider>
|
||||||
|
</IntlProvider>,
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let store;
|
||||||
|
|
||||||
describe('ChecklistSection', () => {
|
describe('ChecklistSection', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(() => {
|
||||||
const { axiosMock, reduxStore } = initializeMocks();
|
initializeMockApp({
|
||||||
axiosMock
|
authenticatedUser: {
|
||||||
.onGet(getApiWaffleFlagsUrl(courseId))
|
userId: 3,
|
||||||
.reply(200, {
|
username: 'abc123',
|
||||||
useNewGradingPage: true,
|
administrator: false,
|
||||||
useNewCertificatesPage: true,
|
roles: [],
|
||||||
useNewScheduleDetailsPage: true,
|
},
|
||||||
useNewCourseOutlinePage: true,
|
});
|
||||||
});
|
store = initializeStore(initialState);
|
||||||
await executeThunk(fetchWaffleFlags(courseId), reduxStore.dispatch);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('a heading using the dataHeading prop', () => {
|
it('a heading using the dataHeading prop', () => {
|
||||||
@@ -54,7 +64,6 @@ describe('ChecklistSection', () => {
|
|||||||
|
|
||||||
it('completion count text', () => {
|
it('completion count text', () => {
|
||||||
renderComponent(defaultProps);
|
renderComponent(defaultProps);
|
||||||
|
|
||||||
const completionText = `${completedItemIds.length}/6 completed`;
|
const completionText = `${completedItemIds.length}/6 completed`;
|
||||||
expect(screen.getByTestId('completion-subheader').textContent).toEqual(completionText);
|
expect(screen.getByTestId('completion-subheader').textContent).toEqual(completionText);
|
||||||
});
|
});
|
||||||
@@ -113,7 +122,7 @@ describe('ChecklistSection', () => {
|
|||||||
grades: {
|
grades: {
|
||||||
...defaultProps.data.grades,
|
...defaultProps.data.grades,
|
||||||
sumOfWeights: 1,
|
sumOfWeights: 1,
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
renderComponent(props);
|
renderComponent(props);
|
||||||
@@ -145,7 +154,7 @@ describe('ChecklistSection', () => {
|
|||||||
...defaultProps.data.assignments,
|
...defaultProps.data.assignments,
|
||||||
assignmentsWithDatesAfterEnd: [],
|
assignmentsWithDatesAfterEnd: [],
|
||||||
assignmentsWithOraDatesBeforeStart: [],
|
assignmentsWithOraDatesBeforeStart: [],
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
renderComponent(props);
|
renderComponent(props);
|
||||||
@@ -174,52 +183,73 @@ describe('ChecklistSection', () => {
|
|||||||
expect(assigmentLinks[1].textContent).toEqual('ORA subsection');
|
expect(assigmentLinks[1].textContent).toEqual('ORA subsection');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Checklist Component', () => {
|
testChecklistData.forEach((check) => {
|
||||||
let checklistData;
|
describe(`check with id '${check.id}'`, () => {
|
||||||
let updateLinks;
|
let checkItem;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
initializeMockApp({
|
||||||
|
authenticatedUser: {
|
||||||
|
userId: 3,
|
||||||
|
username: 'abc123',
|
||||||
|
administrator: false,
|
||||||
|
roles: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
store = initializeStore(initialState);
|
||||||
renderComponent(defaultProps);
|
renderComponent(defaultProps);
|
||||||
|
checkItem = screen.getAllByTestId(`checklist-item-${check.id}`);
|
||||||
checklistData = testChecklistData.map((item) => ({
|
|
||||||
itemId: item.id,
|
|
||||||
checklistItem: screen.getAllByTestId(`checklist-item-${item.id}`),
|
|
||||||
icon: screen.getAllByTestId(`icon-${item.id}`),
|
|
||||||
shortDescription: messages[`${item.id}ShortDescription`].defaultMessage,
|
|
||||||
longDescription: messages[`${item.id}LongDescription`].defaultMessage,
|
|
||||||
}));
|
|
||||||
|
|
||||||
updateLinks = screen.getAllByTestId('update-link');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display the correct icons based on completion status', () => {
|
it('renders', () => {
|
||||||
checklistData.forEach(({ itemId, icon }) => {
|
expect(checkItem).toHaveLength(1);
|
||||||
const { queryByTestId } = within(icon[0]);
|
|
||||||
|
|
||||||
if (completedItemIds.includes(itemId)) {
|
|
||||||
expect(queryByTestId('completed-icon')).not.toBeNull();
|
|
||||||
} else {
|
|
||||||
expect(queryByTestId('uncompleted-icon')).not.toBeNull();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display short and long descriptions for each checklist item', () => {
|
it('has correct icon', () => {
|
||||||
checklistData.forEach(({ checklistItem, shortDescription, longDescription }) => {
|
const icon = screen.getAllByTestId(`icon-${check.id}`)
|
||||||
const { getByText } = within(checklistItem[0]);
|
|
||||||
|
|
||||||
expect(getByText(shortDescription)).toBeVisible();
|
expect(icon).toHaveLength(1);
|
||||||
expect(getByText(longDescription)).toBeVisible();
|
|
||||||
});
|
const { queryByTestId } = within(icon[0]);
|
||||||
|
if (completedItemIds.includes(check.id)) {
|
||||||
|
expect(queryByTestId('completed-icon')).not.toBeNull();
|
||||||
|
} else {
|
||||||
|
expect(queryByTestId('uncompleted-icon')).not.toBeNull();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have valid update links for each checklist item', () => {
|
it('has correct short description', () => {
|
||||||
checklistData.forEach(({ itemId }) => {
|
const { getByText } = within(checkItem[0]);
|
||||||
updateLinks.forEach((link) => {
|
const shortDescription = messages[`${check.id}ShortDescription`].defaultMessage;
|
||||||
expect(link).toHaveAttribute('href', updateLinks[itemId]);
|
expect(getByText(shortDescription)).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('has correct long description', () => {
|
||||||
|
const { getByText } = within(checkItem[0]);
|
||||||
|
const longDescription = messages[`${check.id}LongDescription`].defaultMessage;
|
||||||
|
expect(getByText(longDescription)).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('has correct link', () => {
|
||||||
|
const links = getUpdateLinks('courseId')
|
||||||
|
const shouldShowLink = Object.keys(links).includes(check.id);
|
||||||
|
|
||||||
|
if (shouldShowLink) {
|
||||||
|
it('with a Hyperlink', () => {
|
||||||
|
const { getByRole, getByText } = within(checkItem[0]);
|
||||||
|
|
||||||
|
expect(getByText('Update')).toBeVisible();
|
||||||
|
|
||||||
|
expect(getByRole('link').href).toMatch(links[check.id]);
|
||||||
});
|
});
|
||||||
});
|
} else {
|
||||||
|
it('without a Hyperlink', () => {
|
||||||
|
const { queryByText } = within(checkItem[0]);
|
||||||
|
|
||||||
|
expect(queryByText('Update')).toBeNull();
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,30 +2,30 @@ import * as healthValidators from './courseChecklistValidators';
|
|||||||
|
|
||||||
const getValidatedValue = (data, id) => {
|
const getValidatedValue = (data, id) => {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case 'welcomeMessage':
|
case 'welcomeMessage':
|
||||||
return healthValidators.hasWelcomeMessage(data.updates);
|
return healthValidators.hasWelcomeMessage(data.updates);
|
||||||
case 'gradingPolicy':
|
case 'gradingPolicy':
|
||||||
return healthValidators.hasGradingPolicy(data.grades);
|
return healthValidators.hasGradingPolicy(data.grades);
|
||||||
case 'certificate':
|
case 'certificate':
|
||||||
return healthValidators.hasCertificate(data.certificates);
|
return healthValidators.hasCertificate(data.certificates);
|
||||||
case 'courseDates':
|
case 'courseDates':
|
||||||
return healthValidators.hasDates(data.dates);
|
return healthValidators.hasDates(data.dates);
|
||||||
case 'assignmentDeadlines':
|
case 'assignmentDeadlines':
|
||||||
return healthValidators.hasAssignmentDeadlines(data.assignments, data.dates);
|
return healthValidators.hasAssignmentDeadlines(data.assignments, data.dates);
|
||||||
case 'videoDuration':
|
case 'videoDuration':
|
||||||
return healthValidators.hasShortVideoDuration(data.videos);
|
return healthValidators.hasShortVideoDuration(data.videos);
|
||||||
case 'mobileFriendlyVideo':
|
case 'mobileFriendlyVideo':
|
||||||
return healthValidators.hasMobileFriendlyVideos(data.videos);
|
return healthValidators.hasMobileFriendlyVideos(data.videos);
|
||||||
case 'diverseSequences':
|
case 'diverseSequences':
|
||||||
return healthValidators.hasDiverseSequences(data.subsections);
|
return healthValidators.hasDiverseSequences(data.subsections);
|
||||||
case 'weeklyHighlights':
|
case 'weeklyHighlights':
|
||||||
return healthValidators.hasWeeklyHighlights(data.sections);
|
return healthValidators.hasWeeklyHighlights(data.sections);
|
||||||
case 'unitDepth':
|
case 'unitDepth':
|
||||||
return healthValidators.hasShortUnitDepth(data.units);
|
return healthValidators.hasShortUnitDepth(data.units);
|
||||||
case 'proctoringEmail':
|
case 'proctoringEmail':
|
||||||
return healthValidators.hasProctoringEscalationEmail(data.proctoring);
|
return healthValidators.hasProctoringEscalationEmail(data.proctoring);
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unknown validator ${id}.`);
|
throw new Error(`Unknown validator ${id}.`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import AriaLiveRegion from './AriaLiveRegion';
|
|||||||
import { RequestStatus } from '../data/constants';
|
import { RequestStatus } from '../data/constants';
|
||||||
import ChecklistSection from './ChecklistSection';
|
import ChecklistSection from './ChecklistSection';
|
||||||
import { fetchCourseLaunchQuery, fetchCourseBestPracticesQuery } from './data/thunks';
|
import { fetchCourseLaunchQuery, fetchCourseBestPracticesQuery } from './data/thunks';
|
||||||
import ConnectionErrorAlert from '../generic/ConnectionErrorAlert';
|
import getUpdateLinks from './utils';
|
||||||
|
|
||||||
const CourseChecklist = ({
|
const CourseChecklist = ({
|
||||||
courseId,
|
courseId,
|
||||||
@@ -23,6 +23,7 @@ const CourseChecklist = ({
|
|||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const courseDetails = useModel('courseDetails', courseId);
|
const courseDetails = useModel('courseDetails', courseId);
|
||||||
const enableQuality = getConfig().ENABLE_CHECKLIST_QUALITY === 'true';
|
const enableQuality = getConfig().ENABLE_CHECKLIST_QUALITY === 'true';
|
||||||
|
const updateLinks = getUpdateLinks(courseId);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(fetchCourseLaunchQuery({ courseId }));
|
dispatch(fetchCourseLaunchQuery({ courseId }));
|
||||||
@@ -35,19 +36,10 @@ const CourseChecklist = ({
|
|||||||
bestPracticeData,
|
bestPracticeData,
|
||||||
} = useSelector(state => state.courseChecklist);
|
} = useSelector(state => state.courseChecklist);
|
||||||
|
|
||||||
const { bestPracticeChecklistLoadingStatus, launchChecklistLoadingStatus, launchChecklistStatus } = loadingStatus;
|
const { bestPracticeChecklistLoadingStatus, launchChecklistLoadingStatus } = loadingStatus;
|
||||||
|
|
||||||
const isCourseLaunchChecklistLoading = bestPracticeChecklistLoadingStatus === RequestStatus.IN_PROGRESS;
|
const isCourseLaunchChecklistLoading = bestPracticeChecklistLoadingStatus === RequestStatus.IN_PROGRESS;
|
||||||
const isCourseBestPracticeChecklistLoading = launchChecklistLoadingStatus === RequestStatus.IN_PROGRESS;
|
const isCourseBestPracticeChecklistLoading = launchChecklistLoadingStatus === RequestStatus.IN_PROGRESS;
|
||||||
const isLoadingDenied = launchChecklistStatus === RequestStatus.DENIED;
|
|
||||||
|
|
||||||
if (isLoadingDenied) {
|
|
||||||
return (
|
|
||||||
<Container size="xl" className="course-unit px-4 mt-4">
|
|
||||||
<ConnectionErrorAlert />
|
|
||||||
</Container>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -74,19 +66,19 @@ const CourseChecklist = ({
|
|||||||
/>
|
/>
|
||||||
<Stack gap={4}>
|
<Stack gap={4}>
|
||||||
<ChecklistSection
|
<ChecklistSection
|
||||||
courseId={courseId}
|
|
||||||
dataHeading={intl.formatMessage(messages.launchChecklistLabel)}
|
dataHeading={intl.formatMessage(messages.launchChecklistLabel)}
|
||||||
data={launchData}
|
data={launchData}
|
||||||
idPrefix="launchChecklist"
|
idPrefix="launchChecklist"
|
||||||
isLoading={isCourseLaunchChecklistLoading}
|
isLoading={isCourseLaunchChecklistLoading}
|
||||||
|
updateLinks={updateLinks}
|
||||||
/>
|
/>
|
||||||
{enableQuality && (
|
{enableQuality && (
|
||||||
<ChecklistSection
|
<ChecklistSection
|
||||||
courseId={courseId}
|
|
||||||
dataHeading={intl.formatMessage(messages.bestPracticesChecklistLabel)}
|
dataHeading={intl.formatMessage(messages.bestPracticesChecklistLabel)}
|
||||||
data={bestPracticeData}
|
data={bestPracticeData}
|
||||||
idPrefix="bestPracticesChecklist"
|
idPrefix="bestPracticesChecklist"
|
||||||
isLoading={isCourseBestPracticeChecklistLoading}
|
isLoading={isCourseBestPracticeChecklistLoading}
|
||||||
|
updateLinks={updateLinks}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|||||||
@@ -149,20 +149,5 @@ describe('CourseChecklistPage', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('displays an alert and sets status to DENIED when API responds with 403', async () => {
|
|
||||||
const courseLaunchApiUrl = getCourseLaunchApiUrl({
|
|
||||||
courseId, gradedOnly: true, validateOras: true, all: true,
|
|
||||||
});
|
|
||||||
axiosMock.onGet(courseLaunchApiUrl).reply(403);
|
|
||||||
|
|
||||||
renderComponent();
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
const { launchChecklistStatus } = store.getState().courseChecklist.loadingStatus;
|
|
||||||
expect(launchChecklistStatus).toEqual(RequestStatus.DENIED);
|
|
||||||
expect(screen.getByRole('alert')).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,11 +24,7 @@ export function fetchCourseLaunchQuery({
|
|||||||
dispatch(fetchLaunchChecklistSuccess({ data }));
|
dispatch(fetchLaunchChecklistSuccess({ data }));
|
||||||
dispatch(updateLaunchChecklistStatus({ status: RequestStatus.SUCCESSFUL }));
|
dispatch(updateLaunchChecklistStatus({ status: RequestStatus.SUCCESSFUL }));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response && error.response.status === 403) {
|
dispatch(updateLaunchChecklistStatus({ status: RequestStatus.FAILED }));
|
||||||
dispatch(updateLaunchChecklistStatus({ status: RequestStatus.DENIED }));
|
|
||||||
} else {
|
|
||||||
dispatch(updateLaunchChecklistStatus({ status: RequestStatus.FAILED }));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
12
src/course-checklist/utils.js
Normal file
12
src/course-checklist/utils.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { getConfig } from '@edx/frontend-platform';
|
||||||
|
|
||||||
|
const getUpdateLinks = (courseId) => ({
|
||||||
|
welcomeMessage: `${getConfig().STUDIO_BASE_URL}/course_info/${courseId}`,
|
||||||
|
gradingPolicy: `${getConfig().STUDIO_BASE_URL}/settings/grading/${courseId}`,
|
||||||
|
certificate: `${getConfig().STUDIO_BASE_URL}/certificates/${courseId}`,
|
||||||
|
courseDates: `${getConfig().STUDIO_BASE_URL}/settings/details/${courseId}#schedule`,
|
||||||
|
proctoringEmail: 'pages-and-resources/proctoring/settings',
|
||||||
|
outline: `${getConfig().STUDIO_BASE_URL}/course/${courseId}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default getUpdateLinks;
|
||||||
@@ -1,244 +0,0 @@
|
|||||||
import fetchMock from 'fetch-mock-jest';
|
|
||||||
|
|
||||||
import userEvent from '@testing-library/user-event';
|
|
||||||
import MockAdapter from 'axios-mock-adapter/types';
|
|
||||||
import { QueryClient } from '@tanstack/react-query';
|
|
||||||
import {
|
|
||||||
initializeMocks,
|
|
||||||
render,
|
|
||||||
screen,
|
|
||||||
waitFor,
|
|
||||||
within,
|
|
||||||
} from '../testUtils';
|
|
||||||
import { mockContentSearchConfig } from '../search-manager/data/api.mock';
|
|
||||||
import { CourseLibraries } from './CourseLibraries';
|
|
||||||
import {
|
|
||||||
mockGetEntityLinks,
|
|
||||||
mockGetEntityLinksSummaryByDownstreamContext,
|
|
||||||
mockFetchIndexDocuments,
|
|
||||||
mockUseLibBlockMetadata,
|
|
||||||
} from './data/api.mocks';
|
|
||||||
import { libraryBlockChangesUrl } from '../course-unit/data/api';
|
|
||||||
import { type ToastActionData } from '../generic/toast-context';
|
|
||||||
|
|
||||||
mockContentSearchConfig.applyMock();
|
|
||||||
mockGetEntityLinks.applyMock();
|
|
||||||
mockGetEntityLinksSummaryByDownstreamContext.applyMock();
|
|
||||||
mockUseLibBlockMetadata.applyMock();
|
|
||||||
|
|
||||||
const searchParamsGetMock = jest.fn();
|
|
||||||
let axiosMock: MockAdapter;
|
|
||||||
let mockShowToast: (message: string, action?: ToastActionData | undefined) => void;
|
|
||||||
let queryClient: QueryClient;
|
|
||||||
|
|
||||||
jest.mock('../studio-home/hooks', () => ({
|
|
||||||
useStudioHome: () => ({
|
|
||||||
isLoadingPage: false,
|
|
||||||
isFailedLoadingPage: false,
|
|
||||||
librariesV2Enabled: true,
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.mock('react-router-dom', () => ({
|
|
||||||
...jest.requireActual('react-router-dom'), // use actual for all non-hook parts
|
|
||||||
useSearchParams: () => [{
|
|
||||||
get: searchParamsGetMock,
|
|
||||||
getAll: () => [],
|
|
||||||
}],
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe('<CourseLibraries />', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
initializeMocks();
|
|
||||||
fetchMock.mockReset();
|
|
||||||
mockFetchIndexDocuments.applyMock();
|
|
||||||
localStorage.clear();
|
|
||||||
searchParamsGetMock.mockReturnValue('all');
|
|
||||||
});
|
|
||||||
|
|
||||||
const renderCourseLibrariesPage = async (courseKey?: string) => {
|
|
||||||
const courseId = courseKey || mockGetEntityLinks.courseKey;
|
|
||||||
render(<CourseLibraries courseId={courseId} />);
|
|
||||||
};
|
|
||||||
|
|
||||||
it('shows the spinner before the query is complete', async () => {
|
|
||||||
// This mock will never return data (it loads forever):
|
|
||||||
await renderCourseLibrariesPage(mockGetEntityLinksSummaryByDownstreamContext.courseKeyLoading);
|
|
||||||
const spinner = await screen.findByRole('status');
|
|
||||||
expect(spinner.textContent).toEqual('Loading...');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('shows empty state when no links are present', async () => {
|
|
||||||
await renderCourseLibrariesPage(mockGetEntityLinks.courseKeyEmpty);
|
|
||||||
const emptyMsg = await screen.findByText('This course does not use any content from libraries.');
|
|
||||||
expect(emptyMsg).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('shows alert when out of sync components are present', async () => {
|
|
||||||
await renderCourseLibrariesPage(mockGetEntityLinks.courseKey);
|
|
||||||
const allTab = await screen.findByRole('tab', { name: 'Libraries' });
|
|
||||||
const reviewTab = await screen.findByRole('tab', { name: 'Review Content Updates 5' });
|
|
||||||
// review tab should be open by default as outOfSyncCount is greater than 0
|
|
||||||
expect(reviewTab).toHaveAttribute('aria-selected', 'true');
|
|
||||||
|
|
||||||
userEvent.click(allTab);
|
|
||||||
const alert = await screen.findByRole('alert');
|
|
||||||
expect(await within(alert).findByText(
|
|
||||||
'5 library components are out of sync. Review updates to accept or ignore changes',
|
|
||||||
)).toBeInTheDocument();
|
|
||||||
expect(allTab).toHaveAttribute('aria-selected', 'true');
|
|
||||||
|
|
||||||
const reviewBtn = await screen.findByRole('button', { name: 'Review' });
|
|
||||||
userEvent.click(reviewBtn);
|
|
||||||
|
|
||||||
expect(allTab).toHaveAttribute('aria-selected', 'false');
|
|
||||||
expect(await screen.findByRole('tab', { name: 'Review Content Updates 5' })).toHaveAttribute('aria-selected', 'true');
|
|
||||||
expect(alert).not.toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('hide alert on dismiss', async () => {
|
|
||||||
await renderCourseLibrariesPage(mockGetEntityLinks.courseKey);
|
|
||||||
const reviewTab = await screen.findByRole('tab', { name: 'Review Content Updates 5' });
|
|
||||||
// review tab should be open by default as outOfSyncCount is greater than 0
|
|
||||||
expect(reviewTab).toHaveAttribute('aria-selected', 'true');
|
|
||||||
const allTab = await screen.findByRole('tab', { name: 'Libraries' });
|
|
||||||
userEvent.click(allTab);
|
|
||||||
expect(allTab).toHaveAttribute('aria-selected', 'true');
|
|
||||||
|
|
||||||
const alert = await screen.findByRole('alert');
|
|
||||||
expect(await within(alert).findByText(
|
|
||||||
'5 library components are out of sync. Review updates to accept or ignore changes',
|
|
||||||
)).toBeInTheDocument();
|
|
||||||
const dismissBtn = await screen.findByRole('button', { name: 'Dismiss' });
|
|
||||||
userEvent.click(dismissBtn);
|
|
||||||
expect(allTab).toHaveAttribute('aria-selected', 'true');
|
|
||||||
waitFor(() => expect(alert).not.toBeInTheDocument());
|
|
||||||
// review updates button
|
|
||||||
const reviewActionBtn = await screen.findByRole('button', { name: 'Review Updates' });
|
|
||||||
userEvent.click(reviewActionBtn);
|
|
||||||
expect(await screen.findByRole('tab', { name: 'Review Content Updates 5' })).toHaveAttribute('aria-selected', 'true');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('<CourseLibraries ReviewTab />', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
const mocks = initializeMocks();
|
|
||||||
axiosMock = mocks.axiosMock;
|
|
||||||
mockShowToast = mocks.mockShowToast;
|
|
||||||
fetchMock.mockReset();
|
|
||||||
mockFetchIndexDocuments.applyMock();
|
|
||||||
localStorage.clear();
|
|
||||||
searchParamsGetMock.mockReturnValue('review');
|
|
||||||
queryClient = mocks.queryClient;
|
|
||||||
});
|
|
||||||
|
|
||||||
const renderCourseLibrariesReviewPage = async (courseKey?: string) => {
|
|
||||||
const courseId = courseKey || mockGetEntityLinks.courseKey;
|
|
||||||
render(<CourseLibraries courseId={courseId} />);
|
|
||||||
};
|
|
||||||
|
|
||||||
it('shows the spinner before the query is complete', async () => {
|
|
||||||
// This mock will never return data (it loads forever):
|
|
||||||
await renderCourseLibrariesReviewPage(mockGetEntityLinks.courseKeyLoading);
|
|
||||||
const spinner = await screen.findByRole('status');
|
|
||||||
expect(spinner.textContent).toEqual('Loading...');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('shows empty state when no readyToSync links are present', async () => {
|
|
||||||
await renderCourseLibrariesReviewPage(mockGetEntityLinksSummaryByDownstreamContext.courseKeyUpToDate);
|
|
||||||
const emptyMsg = await screen.findByText('All components are up to date');
|
|
||||||
expect(emptyMsg).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('shows all readyToSync links', async () => {
|
|
||||||
await renderCourseLibrariesReviewPage(mockGetEntityLinksSummaryByDownstreamContext.courseKey);
|
|
||||||
const updateBtns = await screen.findAllByRole('button', { name: 'Update' });
|
|
||||||
expect(updateBtns.length).toEqual(5);
|
|
||||||
const ignoreBtns = await screen.findAllByRole('button', { name: 'Ignore' });
|
|
||||||
expect(ignoreBtns.length).toEqual(5);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('update changes works', async () => {
|
|
||||||
const mockInvalidateQueries = jest.spyOn(queryClient, 'invalidateQueries');
|
|
||||||
const usageKey = mockGetEntityLinks.response.results[0].downstreamUsageKey;
|
|
||||||
axiosMock.onPost(libraryBlockChangesUrl(usageKey)).reply(200, {});
|
|
||||||
await renderCourseLibrariesReviewPage(mockGetEntityLinksSummaryByDownstreamContext.courseKey);
|
|
||||||
const updateBtns = await screen.findAllByRole('button', { name: 'Update' });
|
|
||||||
expect(updateBtns.length).toEqual(5);
|
|
||||||
userEvent.click(updateBtns[0]);
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(axiosMock.history.post.length).toEqual(1);
|
|
||||||
});
|
|
||||||
expect(axiosMock.history.post[0].url).toEqual(libraryBlockChangesUrl(usageKey));
|
|
||||||
expect(mockShowToast).toHaveBeenCalledWith('Success! "Dropdown" is updated');
|
|
||||||
expect(mockInvalidateQueries).toHaveBeenCalledWith(['courseLibraries', 'course-v1:OpenEdx+DemoX+CourseX']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('update changes works in preview modal', async () => {
|
|
||||||
const mockInvalidateQueries = jest.spyOn(queryClient, 'invalidateQueries');
|
|
||||||
const usageKey = mockGetEntityLinks.response.results[0].downstreamUsageKey;
|
|
||||||
axiosMock.onPost(libraryBlockChangesUrl(usageKey)).reply(200, {});
|
|
||||||
await renderCourseLibrariesReviewPage(mockGetEntityLinksSummaryByDownstreamContext.courseKey);
|
|
||||||
const previewBtns = await screen.findAllByRole('button', { name: 'Review Updates' });
|
|
||||||
expect(previewBtns.length).toEqual(5);
|
|
||||||
userEvent.click(previewBtns[0]);
|
|
||||||
const dialog = await screen.findByRole('dialog');
|
|
||||||
const confirmBtn = await within(dialog).findByRole('button', { name: 'Accept changes' });
|
|
||||||
userEvent.click(confirmBtn);
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(axiosMock.history.post.length).toEqual(1);
|
|
||||||
});
|
|
||||||
expect(axiosMock.history.post[0].url).toEqual(libraryBlockChangesUrl(usageKey));
|
|
||||||
expect(mockShowToast).toHaveBeenCalledWith('Success! "Dropdown" is updated');
|
|
||||||
expect(mockInvalidateQueries).toHaveBeenCalledWith(['courseLibraries', 'course-v1:OpenEdx+DemoX+CourseX']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('ignore change works', async () => {
|
|
||||||
const mockInvalidateQueries = jest.spyOn(queryClient, 'invalidateQueries');
|
|
||||||
const usageKey = mockGetEntityLinks.response.results[0].downstreamUsageKey;
|
|
||||||
axiosMock.onDelete(libraryBlockChangesUrl(usageKey)).reply(204, {});
|
|
||||||
await renderCourseLibrariesReviewPage(mockGetEntityLinksSummaryByDownstreamContext.courseKey);
|
|
||||||
const ignoreBtns = await screen.findAllByRole('button', { name: 'Ignore' });
|
|
||||||
expect(ignoreBtns.length).toEqual(5);
|
|
||||||
// Show confirmation modal on clicking ignore.
|
|
||||||
userEvent.click(ignoreBtns[0]);
|
|
||||||
const dialog = await screen.findByRole('dialog', { name: 'Ignore these changes?' });
|
|
||||||
expect(dialog).toBeInTheDocument();
|
|
||||||
const confirmBtn = await within(dialog).findByRole('button', { name: 'Ignore' });
|
|
||||||
userEvent.click(confirmBtn);
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(axiosMock.history.delete.length).toEqual(1);
|
|
||||||
});
|
|
||||||
expect(axiosMock.history.delete[0].url).toEqual(libraryBlockChangesUrl(usageKey));
|
|
||||||
expect(mockShowToast).toHaveBeenCalledWith(
|
|
||||||
'"Dropdown" will remain out of sync with library content. You will be notified when this component is updated again.',
|
|
||||||
);
|
|
||||||
expect(mockInvalidateQueries).toHaveBeenCalledWith(['courseLibraries', 'course-v1:OpenEdx+DemoX+CourseX']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('ignore change works in preview', async () => {
|
|
||||||
const mockInvalidateQueries = jest.spyOn(queryClient, 'invalidateQueries');
|
|
||||||
const usageKey = mockGetEntityLinks.response.results[0].downstreamUsageKey;
|
|
||||||
axiosMock.onDelete(libraryBlockChangesUrl(usageKey)).reply(204, {});
|
|
||||||
await renderCourseLibrariesReviewPage(mockGetEntityLinksSummaryByDownstreamContext.courseKey);
|
|
||||||
const previewBtns = await screen.findAllByRole('button', { name: 'Review Updates' });
|
|
||||||
expect(previewBtns.length).toEqual(5);
|
|
||||||
userEvent.click(previewBtns[0]);
|
|
||||||
const previewDialog = await screen.findByRole('dialog');
|
|
||||||
const ignoreBtn = await within(previewDialog).findByRole('button', { name: 'Ignore changes' });
|
|
||||||
userEvent.click(ignoreBtn);
|
|
||||||
// Show confirmation modal on clicking ignore.
|
|
||||||
const dialog = await screen.findByRole('dialog', { name: 'Ignore these changes?' });
|
|
||||||
expect(dialog).toBeInTheDocument();
|
|
||||||
const confirmBtn = await within(dialog).findByRole('button', { name: 'Ignore' });
|
|
||||||
userEvent.click(confirmBtn);
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(axiosMock.history.delete.length).toEqual(1);
|
|
||||||
});
|
|
||||||
expect(axiosMock.history.delete[0].url).toEqual(libraryBlockChangesUrl(usageKey));
|
|
||||||
expect(mockShowToast).toHaveBeenCalledWith(
|
|
||||||
'"Dropdown" will remain out of sync with library content. You will be notified when this component is updated again.',
|
|
||||||
);
|
|
||||||
expect(mockInvalidateQueries).toHaveBeenCalledWith(['courseLibraries', 'course-v1:OpenEdx+DemoX+CourseX']);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user