Compare commits
6 Commits
master
...
open-relea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54c6c57b42 | ||
|
|
6722dbdce5 | ||
|
|
fed06641df | ||
|
|
689b8b48f0 | ||
|
|
258f4377d8 | ||
|
|
dcdc96778c |
3
.env
3
.env
@@ -32,6 +32,3 @@ ENTERPRISE_MARKETING_UTM_CAMPAIGN=''
|
|||||||
ENTERPRISE_MARKETING_FOOTER_UTM_MEDIUM=''
|
ENTERPRISE_MARKETING_FOOTER_UTM_MEDIUM=''
|
||||||
APP_ID=''
|
APP_ID=''
|
||||||
MFE_CONFIG_API_URL=''
|
MFE_CONFIG_API_URL=''
|
||||||
ACCOUNT_SETTINGS_URL=''
|
|
||||||
# Fallback in local style files
|
|
||||||
PARAGON_THEME_URLS={}
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ LOGOUT_URL='http://localhost:18000/logout'
|
|||||||
LOGO_URL=https://edx-cdn.org/v3/default/logo.svg
|
LOGO_URL=https://edx-cdn.org/v3/default/logo.svg
|
||||||
LOGO_TRADEMARK_URL=https://edx-cdn.org/v3/default/logo-trademark.svg
|
LOGO_TRADEMARK_URL=https://edx-cdn.org/v3/default/logo-trademark.svg
|
||||||
LOGO_WHITE_URL=https://edx-cdn.org/v3/default/logo-white.svg
|
LOGO_WHITE_URL=https://edx-cdn.org/v3/default/logo-white.svg
|
||||||
|
LOGO_POWERED_BY_OPEN_EDX_URL_SVG=https://edx-cdn.org/v3/stage/open-edx-tag.svg
|
||||||
FAVICON_URL=https://edx-cdn.org/v3/default/favicon.ico
|
FAVICON_URL=https://edx-cdn.org/v3/default/favicon.ico
|
||||||
CSRF_TOKEN_API_PATH='/csrf/api/v1/token'
|
CSRF_TOKEN_API_PATH='/csrf/api/v1/token'
|
||||||
REFRESH_ACCESS_TOKEN_ENDPOINT='http://localhost:18000/login_refresh'
|
REFRESH_ACCESS_TOKEN_ENDPOINT='http://localhost:18000/login_refresh'
|
||||||
@@ -37,6 +38,3 @@ ENTERPRISE_MARKETING_UTM_CAMPAIGN='example.com Referral'
|
|||||||
ENTERPRISE_MARKETING_FOOTER_UTM_MEDIUM='Footer'
|
ENTERPRISE_MARKETING_FOOTER_UTM_MEDIUM='Footer'
|
||||||
APP_ID=''
|
APP_ID=''
|
||||||
MFE_CONFIG_API_URL=''
|
MFE_CONFIG_API_URL=''
|
||||||
ACCOUNT_SETTINGS_URL=http://localhost:1997
|
|
||||||
# Fallback in local style files
|
|
||||||
PARAGON_THEME_URLS={}
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ LOGOUT_URL='http://localhost:18000/logout'
|
|||||||
LOGO_URL=https://edx-cdn.org/v3/default/logo.svg
|
LOGO_URL=https://edx-cdn.org/v3/default/logo.svg
|
||||||
LOGO_TRADEMARK_URL=https://edx-cdn.org/v3/default/logo-trademark.svg
|
LOGO_TRADEMARK_URL=https://edx-cdn.org/v3/default/logo-trademark.svg
|
||||||
LOGO_WHITE_URL=https://edx-cdn.org/v3/default/logo-white.svg
|
LOGO_WHITE_URL=https://edx-cdn.org/v3/default/logo-white.svg
|
||||||
|
LOGO_POWERED_BY_OPEN_EDX_URL_SVG=https://edx-cdn.org/v3/stage/open-edx-tag.svg
|
||||||
FAVICON_URL=https://edx-cdn.org/v3/default/favicon.ico
|
FAVICON_URL=https://edx-cdn.org/v3/default/favicon.ico
|
||||||
CSRF_TOKEN_API_PATH='/csrf/api/v1/token'
|
CSRF_TOKEN_API_PATH='/csrf/api/v1/token'
|
||||||
REFRESH_ACCESS_TOKEN_ENDPOINT='http://localhost:18000/login_refresh'
|
REFRESH_ACCESS_TOKEN_ENDPOINT='http://localhost:18000/login_refresh'
|
||||||
@@ -35,5 +36,3 @@ ENTERPRISE_MARKETING_URL='http://example.com'
|
|||||||
ENTERPRISE_MARKETING_UTM_SOURCE='example.com'
|
ENTERPRISE_MARKETING_UTM_SOURCE='example.com'
|
||||||
ENTERPRISE_MARKETING_UTM_CAMPAIGN='example.com Referral'
|
ENTERPRISE_MARKETING_UTM_CAMPAIGN='example.com Referral'
|
||||||
ENTERPRISE_MARKETING_FOOTER_UTM_MEDIUM='Footer'
|
ENTERPRISE_MARKETING_FOOTER_UTM_MEDIUM='Footer'
|
||||||
ACCOUNT_SETTINGS_URL=http://localhost:1997
|
|
||||||
PARAGON_THEME_URLS={}
|
|
||||||
|
|||||||
22
.eslintrc.js
22
.eslintrc.js
@@ -1,5 +1,4 @@
|
|||||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
const { createConfig } = require('@edx/frontend-build');
|
||||||
const { createConfig } = require('@openedx/frontend-build');
|
|
||||||
|
|
||||||
const config = createConfig('eslint', {
|
const config = createConfig('eslint', {
|
||||||
rules: {
|
rules: {
|
||||||
@@ -7,28 +6,19 @@ const config = createConfig('eslint', {
|
|||||||
'import/no-named-as-default-member': 'off',
|
'import/no-named-as-default-member': 'off',
|
||||||
'import/no-import-module-exports': 'off',
|
'import/no-import-module-exports': 'off',
|
||||||
'import/no-self-import': 'off',
|
'import/no-self-import': 'off',
|
||||||
'spaced-comment': ['error', 'always', { block: { exceptions: ['*'] } }],
|
'spaced-comment': ['error', 'always', { 'block': { 'exceptions': ['*'] } }],
|
||||||
'react-hooks/rules-of-hooks': 'off',
|
'react-hooks/rules-of-hooks': 'off',
|
||||||
'react/forbid-prop-types': ['error', { forbid: ['any', 'array'] }], // arguable object proptype is use when I do not care about the shape of the object
|
"react/forbid-prop-types": ["error", { "forbid": ["any", "array"] }], // arguable object proptype is use when I do not care about the shape of the object
|
||||||
'no-import-assign': 'off',
|
'no-import-assign': 'off',
|
||||||
'no-promise-executor-return': 'off',
|
'no-promise-executor-return': 'off',
|
||||||
'import/no-cycle': 'off',
|
|
||||||
},
|
},
|
||||||
overrides: [
|
|
||||||
{
|
|
||||||
files: ['**/*.test.{js,jsx,ts,tsx}'],
|
|
||||||
rules: {
|
|
||||||
'react/prop-types': 'off',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
config.settings = {
|
config.settings = {
|
||||||
'import/resolver': {
|
"import/resolver": {
|
||||||
node: {
|
node: {
|
||||||
paths: ['src', 'node_modules'],
|
paths: ["src", "node_modules"],
|
||||||
extensions: ['.js', '.jsx'],
|
extensions: [".js", ".jsx"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
6
.github/CODEOWNERS
vendored
Normal file
6
.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# Code owners for frontend-app-ora-grading
|
||||||
|
|
||||||
|
# These owners will be the default owners for everything in
|
||||||
|
# the repo. Unless a later match takes precedence, they will
|
||||||
|
# be requested for review when someone opens a pull request.
|
||||||
|
* @edx/content-aurora
|
||||||
12
.github/workflows/ci.yml
vendored
12
.github/workflows/ci.yml
vendored
@@ -10,18 +10,17 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
tests:
|
tests:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: Setup Nodejs Env
|
- name: Setup Nodejs Env
|
||||||
run: echo "NODE_VER=`cat .nvmrc`" >> $GITHUB_ENV
|
run: echo "NODE_VER=`cat .nvmrc`" >> $GITHUB_ENV
|
||||||
- name: Setup Nodejs
|
- name: Setup Nodejs
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v3
|
||||||
# Because of node 18 bug (https://github.com/nodejs/node/issues/47563), Pinning node version 18.15 until the next release of node
|
# Because of node 18 bug (https://github.com/nodejs/node/issues/47563), Pinning node version 18.15 until the next release of node
|
||||||
with:
|
with:
|
||||||
node-version-file: '.nvmrc'
|
node-version: 18.15
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
@@ -39,10 +38,7 @@ jobs:
|
|||||||
run: npm run build
|
run: npm run build
|
||||||
|
|
||||||
- name: Run Coverage
|
- name: Run Coverage
|
||||||
uses: codecov/codecov-action@v4
|
uses: codecov/codecov-action@v3
|
||||||
with:
|
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
|
||||||
fail_ci_if_error: true
|
|
||||||
|
|
||||||
- name: Send failure notification
|
- name: Send failure notification
|
||||||
if: ${{ failure() }}
|
if: ${{ failure() }}
|
||||||
|
|||||||
2
.github/workflows/lockfileversion-check.yml
vendored
2
.github/workflows/lockfileversion-check.yml
vendored
@@ -10,4 +10,4 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
version-check:
|
version-check:
|
||||||
uses: openedx/.github/.github/workflows/lockfileversion-check-v3.yml@master
|
uses: openedx/.github/.github/workflows/lockfileversion-check.yml@master
|
||||||
|
|||||||
32
.github/workflows/npm-publish.yml
vendored
Normal file
32
.github/workflows/npm-publish.yml
vendored
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
name: Release CI
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
name: Release
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 12
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Create Build
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
|
- name: Release Package
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GITHUB_TOKEN }}
|
||||||
|
NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }}
|
||||||
|
run: npm semantic-release
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -25,5 +25,3 @@ module.config.js
|
|||||||
### transifex ###
|
### transifex ###
|
||||||
src/i18n/transifex_input.json
|
src/i18n/transifex_input.json
|
||||||
temp
|
temp
|
||||||
|
|
||||||
src/i18n/messages
|
|
||||||
4
.husky/pre-push
Executable file
4
.husky/pre-push
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
. "$(dirname "$0")/_/husky.sh"
|
||||||
|
|
||||||
|
npm run lint
|
||||||
27
.releaserc
Normal file
27
.releaserc
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"branch": "master",
|
||||||
|
"tagFormat": "v${version}",
|
||||||
|
"verifyConditions": [
|
||||||
|
"@semantic-release/npm",
|
||||||
|
{
|
||||||
|
"path": "@semantic-release/github",
|
||||||
|
"assets": {
|
||||||
|
"path": "dist/*"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"analyzeCommits": "@semantic-release/commit-analyzer",
|
||||||
|
"generateNotes": "@semantic-release/release-notes-generator",
|
||||||
|
"prepare": "@semantic-release/npm",
|
||||||
|
"publish": [
|
||||||
|
"@semantic-release/npm",
|
||||||
|
{
|
||||||
|
"path": "@semantic-release/github",
|
||||||
|
"assets": {
|
||||||
|
"path": "dist/*"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"success": [],
|
||||||
|
"fail": []
|
||||||
|
}
|
||||||
9
.tx/config
Normal file
9
.tx/config
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[main]
|
||||||
|
host = https://www.transifex.com
|
||||||
|
|
||||||
|
[o:open-edx:p:edx-platform:r:frontend-app-ora-grading]
|
||||||
|
file_filter = src/i18n/messages/<lang>.json
|
||||||
|
source_file = src/i18n/transifex_input.json
|
||||||
|
source_lang = en
|
||||||
|
type = KEYVALUEJSON
|
||||||
|
|
||||||
30
Makefile
30
Makefile
@@ -2,13 +2,15 @@ npm-install-%: ## install specified % npm package
|
|||||||
npm install $* --save-dev
|
npm install $* --save-dev
|
||||||
git add package.json
|
git add package.json
|
||||||
|
|
||||||
intl_imports = ./node_modules/.bin/intl-imports.js
|
transifex_resource = frontend-app-ora-grading
|
||||||
|
transifex_langs = "ar,fr,es_419,zh_CN,fr_CA,it_IT,pt_PT,de_DE,uk,ru,hi"
|
||||||
|
|
||||||
transifex_utils = ./node_modules/.bin/transifex-utils.js
|
transifex_utils = ./node_modules/.bin/transifex-utils.js
|
||||||
i18n = ./src/i18n
|
i18n = ./src/i18n
|
||||||
transifex_input = $(i18n)/transifex_input.json
|
transifex_input = $(i18n)/transifex_input.json
|
||||||
|
|
||||||
# This directory must match .babelrc .
|
# This directory must match .babelrc .
|
||||||
transifex_temp = ./temp/babel-plugin-formatjs
|
transifex_temp = ./temp/babel-plugin-react-intl
|
||||||
|
|
||||||
NPM_TESTS=build i18n_extract lint test
|
NPM_TESTS=build i18n_extract lint test
|
||||||
|
|
||||||
@@ -40,18 +42,20 @@ detect_changed_source_translations:
|
|||||||
# Checking for changed translations...
|
# Checking for changed translations...
|
||||||
git diff --exit-code $(i18n)
|
git diff --exit-code $(i18n)
|
||||||
|
|
||||||
pull_translations:
|
# Pushes translations to Transifex. You must run make extract_translations first.
|
||||||
rm -rf src/i18n/messages
|
push_translations:
|
||||||
mkdir src/i18n/messages
|
# Pushing strings to Transifex...
|
||||||
cd src/i18n/messages \
|
tx push -s
|
||||||
&& atlas pull $(ATLAS_OPTIONS) \
|
# Fetching hashes from Transifex...
|
||||||
translations/frontend-component-footer/src/i18n/messages:frontend-component-footer \
|
./node_modules/@edx/reactifex/bash_scripts/get_hashed_strings_v3.sh
|
||||||
translations/frontend-component-header/src/i18n/messages:frontend-component-header \
|
# Writing out comments to file...
|
||||||
translations/frontend-platform/src/i18n/messages:frontend-platform \
|
$(transifex_utils) $(transifex_temp) --comments --v3-scripts-path
|
||||||
translations/paragon/src/i18n/messages:paragon \
|
# Pushing comments to Transifex...
|
||||||
translations/frontend-app-ora-grading/src/i18n/messages:frontend-app-ora-grading
|
./node_modules/@edx/reactifex/bash_scripts/put_comments_v3.sh
|
||||||
|
|
||||||
$(intl_imports) frontend-component-footer frontend-component-header frontend-platform paragon frontend-app-ora-grading
|
# Pulls translations from Transifex.
|
||||||
|
pull_translations:
|
||||||
|
tx pull -t -f --mode reviewed --languages=$(transifex_langs)
|
||||||
|
|
||||||
# This target is used by CI.
|
# This target is used by CI.
|
||||||
validate-no-uncommitted-package-lock-changes:
|
validate-no-uncommitted-package-lock-changes:
|
||||||
|
|||||||
21
README.md
Normal file
21
README.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# frontend-app-ora-grading
|
||||||
|
|
||||||
|
The ORA Staff Grading App is a microfrontend (MFE) staff grading experience for Open Response Assessments (ORAs). This experience was designed to streamline the grading process and enable richer previews of submission content.
|
||||||
|
|
||||||
|
When enabled, ORAs with a staff grading step will link to this new MFE when clicking "Grade Available Responses" from the ORA or link in the instructor dashboard.
|
||||||
|
|
||||||
|
## Quickstart
|
||||||
|
|
||||||
|
To start the MFE and enable the feature in LMS:
|
||||||
|
|
||||||
|
1. Start the MFE with `npm run start`. Take a note of the path/port (defaults to `http://localhost:1993`).
|
||||||
|
|
||||||
|
2. Add the route root to `edx-platform` settings: In `edx-platform/lms/envs/private.py` or similar, add `ORA_GRADING_MICROFRONTEND_URL = 'http://localhost:1993'`
|
||||||
|
|
||||||
|
3. Enable the feature: In Django Admin go to django-waffle > Flags and add/enable a new flag called `openresponseassessment.enhanced_staff_grader`.
|
||||||
|
|
||||||
|
From there, visit the new experience by going to the Instructor Dashboard > Open Responses or an ORA with a Staff Graded Step and click a link to begin grading.
|
||||||
|
|
||||||
|
## Resources
|
||||||
|
|
||||||
|
See the [ORA Staff Grading](https://edx.readthedocs.io/projects/edx-partner-course-staff/en/latest/exercises_tools/open_response_assessments/ORA_Staff_Grading.html#ora-staff-grading) section on ReadTheDocs for usage information.
|
||||||
235
README.rst
235
README.rst
@@ -1,235 +0,0 @@
|
|||||||
frontend-app-ora-grading
|
|
||||||
#############################
|
|
||||||
|
|
||||||
|license-badge| |status-badge| |ci-badge| |codecov-badge|
|
|
||||||
|
|
||||||
|
|
||||||
Purpose
|
|
||||||
*******
|
|
||||||
|
|
||||||
The ORA Staff Grading App is a micro-frontend (MFE) staff grading experience
|
|
||||||
for Open Response Assessments (ORAs). This experience was designed to
|
|
||||||
streamline the grading process and enable richer previews of submission content
|
|
||||||
and, eventually, replace on-platform grading workflows for ORA.
|
|
||||||
|
|
||||||
When enabled, ORAs with a staff grading step will link to this new MFE when
|
|
||||||
clicking "Grade Available Responses" from the ORA or link in the instructor
|
|
||||||
dashboard.
|
|
||||||
|
|
||||||
The ORA Staff Grader depends on the `lms/djangoapps/ora_staff_grader
|
|
||||||
<https://github.com/openedx/edx-platform/tree/master/lms/djangoapps/ora_staff_grader>`_
|
|
||||||
app in ``edx-platform``.
|
|
||||||
|
|
||||||
Getting Started
|
|
||||||
***************
|
|
||||||
|
|
||||||
Prerequisites
|
|
||||||
=============
|
|
||||||
|
|
||||||
`Tutor`_ is currently recommended as a development environment for your
|
|
||||||
new MFE. Please refer
|
|
||||||
to the `relevant tutor-mfe documentation`_ to get started using it.
|
|
||||||
|
|
||||||
.. _Tutor: https://github.com/overhangio/tutor
|
|
||||||
|
|
||||||
.. _relevant tutor-mfe documentation: https://github.com/overhangio/tutor-mfe?tab=readme-ov-file#mfe-development
|
|
||||||
|
|
||||||
|
|
||||||
Plugins
|
|
||||||
=======
|
|
||||||
This MFE can be customized using `Frontend Plugin Framework <https://github.com/openedx/frontend-plugin-framework>`_.
|
|
||||||
|
|
||||||
The parts of this MFE that can be customized in that manner are documented `here </src/plugin-slots>`_.
|
|
||||||
|
|
||||||
Developing
|
|
||||||
==========
|
|
||||||
|
|
||||||
Cloning and Startup
|
|
||||||
--------------
|
|
||||||
|
|
||||||
First, clone the repo, install code prerequisites, and start the app.
|
|
||||||
|
|
||||||
.. code-block::
|
|
||||||
|
|
||||||
|
|
||||||
1. Clone your new repo:
|
|
||||||
|
|
||||||
``git clone git@github.com:openedx/frontend-app-ora-grading.git``
|
|
||||||
|
|
||||||
2. Use the version of Node specified in the ``.nvmrc`` file.
|
|
||||||
|
|
||||||
The current version of the micro-frontend build scripts supports the version of Node found in ``.nvmrc``.
|
|
||||||
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. Install npm dependencies:
|
|
||||||
|
|
||||||
``cd frontend-app-ora-grading && npm install``
|
|
||||||
|
|
||||||
4. Update the application port to use for local development:
|
|
||||||
|
|
||||||
Default port is 1993. If this does not work for you, update the line
|
|
||||||
`PORT=1993` to your port in all .env.* files
|
|
||||||
|
|
||||||
5. Start the dev server:
|
|
||||||
|
|
||||||
``npm start``
|
|
||||||
|
|
||||||
The app will, by default, run on `http://localhost:1993` unless otherwise
|
|
||||||
specified in ``.env.development:PORT`` and ``.env.development:BASE_URL``.
|
|
||||||
|
|
||||||
Next, enable the ORA Grading micro-frontend in `edx-platform`
|
|
||||||
|
|
||||||
#. Add the path to the ORA Grading app in `edx-platform`:
|
|
||||||
|
|
||||||
#. Go to your environment settings (e.g. `edx-platform/lms/envs/private.py`)
|
|
||||||
|
|
||||||
#. Add the environment variable, ``ORA_GRADING_MICROFRONTEND_URL`` pointing
|
|
||||||
to the ORA Grading app location (e.g. ``http://localhost:1993``).
|
|
||||||
|
|
||||||
#. Start / restart the ``edx-platform`` ``lms``.
|
|
||||||
|
|
||||||
#. Enable the ORA Grading feature in Django Admin.
|
|
||||||
|
|
||||||
#. Go to Django Admin (`{lms-root}/admin`)
|
|
||||||
|
|
||||||
#. Navigate to ``django-waffle`` > ``Flags`` and click ``add/enable a new
|
|
||||||
flag``.
|
|
||||||
|
|
||||||
#. Add a new flag called ``openresponseassessment.enhanced_staff_grader``
|
|
||||||
and enable it.
|
|
||||||
|
|
||||||
From there, visit an Open Response Assessment with a Staff Graded Step and
|
|
||||||
click the "View and grade responses" button to begin grading in the ORA Staff
|
|
||||||
Grader experience.
|
|
||||||
|
|
||||||
|
|
||||||
Making Changes
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Get / install the latest code:
|
|
||||||
|
|
||||||
.. code-block::
|
|
||||||
|
|
||||||
# Grab the latest code
|
|
||||||
git checkout master
|
|
||||||
git pull
|
|
||||||
|
|
||||||
# Install/update the dev requirements
|
|
||||||
npm install
|
|
||||||
|
|
||||||
|
|
||||||
Before committing:
|
|
||||||
|
|
||||||
.. code-block::
|
|
||||||
|
|
||||||
# Make a new branch for your changes
|
|
||||||
git checkout -b <your_github_username>/<short_description>
|
|
||||||
|
|
||||||
# Using your favorite editor, edit the code to make your change.
|
|
||||||
|
|
||||||
# Run your new tests
|
|
||||||
npm test
|
|
||||||
|
|
||||||
# Commit all your changes
|
|
||||||
git commit ...
|
|
||||||
git push
|
|
||||||
|
|
||||||
# Open a PR and ask for review.
|
|
||||||
|
|
||||||
Deploying
|
|
||||||
=========
|
|
||||||
|
|
||||||
This component follows the standard deploy process for MFEs. For details, see
|
|
||||||
the `MFE production deployment guide`_
|
|
||||||
|
|
||||||
.. _MFE production deployment guide: https://openedx.github.io/frontend-platform/#production-deployment-strategy
|
|
||||||
|
|
||||||
Internationalization
|
|
||||||
====================
|
|
||||||
|
|
||||||
Please see refer to the `frontend-platform i18n howto`_ for documentation on
|
|
||||||
internationalization.
|
|
||||||
|
|
||||||
.. _frontend-platform i18n howto: https://github.com/openedx/frontend-platform/blob/master/docs/how_tos/i18n.rst
|
|
||||||
|
|
||||||
Getting Help
|
|
||||||
************
|
|
||||||
|
|
||||||
If you're having trouble, we have discussion forums at
|
|
||||||
https://discuss.openedx.org where you can connect with others in the community.
|
|
||||||
|
|
||||||
Our real-time conversations are on Slack. You can request a `Slack
|
|
||||||
invitation`_, then join our `community Slack workspace`_. Because this is a
|
|
||||||
frontend repository, the best place to discuss it would be in the `#wg-frontend
|
|
||||||
channel`_.
|
|
||||||
|
|
||||||
For anything non-trivial, the best path is to open an issue in this repository
|
|
||||||
with as many details about the issue you are facing as you can provide.
|
|
||||||
|
|
||||||
https://github.com/openedx/frontend-app-ora-grading/issues
|
|
||||||
|
|
||||||
For more information about these options, see the `Getting Help`_ page.
|
|
||||||
|
|
||||||
.. _Slack invitation: https://openedx.org/slack
|
|
||||||
.. _community Slack workspace: https://openedx.slack.com/
|
|
||||||
.. _#wg-frontend channel: https://openedx.slack.com/archives/C04BM6YC7A6
|
|
||||||
.. _Getting Help: https://openedx.org/community/connect
|
|
||||||
|
|
||||||
License
|
|
||||||
*******
|
|
||||||
|
|
||||||
The code in this repository is licensed under the AGPLv3 unless otherwise
|
|
||||||
noted.
|
|
||||||
|
|
||||||
Please see `LICENSE <LICENSE>`_ for details.
|
|
||||||
|
|
||||||
Contributing
|
|
||||||
************
|
|
||||||
|
|
||||||
Contributions are very welcome. Please read `How To Contribute`_ for details.
|
|
||||||
|
|
||||||
.. _How To Contribute: https://openedx.org/r/how-to-contribute
|
|
||||||
|
|
||||||
This project is currently accepting all types of contributions, bug fixes,
|
|
||||||
security fixes, maintenance work, or new features. However, please make sure
|
|
||||||
to have a discussion about your new feature idea with the maintainers prior to
|
|
||||||
beginning development to maximize the chances of your change being accepted.
|
|
||||||
You can start a conversation by creating a new issue on this repo summarizing
|
|
||||||
your idea.
|
|
||||||
|
|
||||||
The Open edX Code of Conduct
|
|
||||||
****************************
|
|
||||||
|
|
||||||
All community members are expected to follow the `Open edX Code of Conduct`_.
|
|
||||||
|
|
||||||
.. _Open edX Code of Conduct: https://openedx.org/code-of-conduct/
|
|
||||||
|
|
||||||
People
|
|
||||||
******
|
|
||||||
|
|
||||||
The assigned maintainers for this component and other project details may be
|
|
||||||
found in `Backstage`_. Backstage pulls this data from the ``catalog-info.yaml``
|
|
||||||
file in this repo.
|
|
||||||
|
|
||||||
.. _Backstage: https://open-edx-backstage.herokuapp.com/catalog/default/component/frontend-app-ora-grading
|
|
||||||
|
|
||||||
Reporting Security Issues
|
|
||||||
*************************
|
|
||||||
|
|
||||||
Please do not report security issues in public, and email security@openedx.org instead.
|
|
||||||
|
|
||||||
.. |license-badge| image:: https://img.shields.io/github/license/openedx/frontend-app-ora-grading.svg
|
|
||||||
:target: https://github.com/openedx/frontend-app-ora-grading/blob/master/LICENSE
|
|
||||||
:alt: License
|
|
||||||
|
|
||||||
.. |status-badge| image:: https://img.shields.io/badge/Status-Maintained-brightgreen
|
|
||||||
|
|
||||||
.. |ci-badge| image:: https://github.com/openedx/frontend-app-ora-grading/actions/workflows/ci.yml/badge.svg
|
|
||||||
:target: https://github.com/openedx/frontend-app-ora-grading/actions/workflows/ci.yml
|
|
||||||
:alt: Continuous Integration
|
|
||||||
|
|
||||||
.. |codecov-badge| image:: https://codecov.io/github/openedx/frontend-app-ora-grading/coverage.svg?branch=master
|
|
||||||
:target: https://codecov.io/github/openedx/frontend-app-ora-grading?branch=master
|
|
||||||
:alt: Codecov
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
# This file records information about this repo. Its use is described in OEP-55:
|
|
||||||
# https://open-edx-proposals.readthedocs.io/en/latest/processes/oep-0055-proc-project-maintainers.html
|
|
||||||
|
|
||||||
apiVersion: backstage.io/v1alpha1
|
|
||||||
kind: Component
|
|
||||||
metadata:
|
|
||||||
name: 'frontend-app-ora-grading'
|
|
||||||
description: "Frontend grading experience for Open Response Assessments (ORAs)"
|
|
||||||
links:
|
|
||||||
- url: "https://ora-grading.edx.org"
|
|
||||||
title: "Production Site"
|
|
||||||
icon: "Web"
|
|
||||||
- url: "https://ora-grading.stage.edx.org"
|
|
||||||
title: "Stage Site"
|
|
||||||
icon: "Web"
|
|
||||||
annotations:
|
|
||||||
openedx.org/release: "master"
|
|
||||||
spec:
|
|
||||||
owner: "user:codewithemad"
|
|
||||||
type: 'website'
|
|
||||||
lifecycle: 'production'
|
|
||||||
@@ -26,3 +26,4 @@ There are only two requirements for a good `make target` name
|
|||||||
What `make validate-no-uncommitted-package-lock-changes` does is `git diff`s for any `package-lock.json` file changes in your project.
|
What `make validate-no-uncommitted-package-lock-changes` does is `git diff`s for any `package-lock.json` file changes in your project.
|
||||||
|
|
||||||
This is important because `npm` uses the pinned dependencies in your `package-lock.json` file to build the `node_modules` directory. However, the dependencies defined within the `package.json` file can be modified manually, for example, to become misaligned with the dependencies defined within the `package-lock.json`. So when `npm install` executes, the `package-lock.json` file will be updated to mirror the modified `package.json` changes.
|
This is important because `npm` uses the pinned dependencies in your `package-lock.json` file to build the `node_modules` directory. However, the dependencies defined within the `package.json` file can be modified manually, for example, to become misaligned with the dependencies defined within the `package-lock.json`. So when `npm install` executes, the `package-lock.json` file will be updated to mirror the modified `package.json` changes.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const { createConfig } = require('@openedx/frontend-build');
|
const { createConfig } = require('@edx/frontend-build');
|
||||||
|
|
||||||
module.exports = createConfig('jest', {
|
module.exports = createConfig('jest', {
|
||||||
setupFilesAfterEnv: [
|
setupFilesAfterEnv: [
|
||||||
@@ -6,6 +6,9 @@ module.exports = createConfig('jest', {
|
|||||||
'<rootDir>/src/setupTest.js',
|
'<rootDir>/src/setupTest.js',
|
||||||
],
|
],
|
||||||
modulePaths: ['<rootDir>/src/'],
|
modulePaths: ['<rootDir>/src/'],
|
||||||
|
snapshotSerializers: [
|
||||||
|
'enzyme-to-json/serializer',
|
||||||
|
],
|
||||||
coveragePathIgnorePatterns: [
|
coveragePathIgnorePatterns: [
|
||||||
'src/segment.js',
|
'src/segment.js',
|
||||||
'src/postcss.config.js',
|
'src/postcss.config.js',
|
||||||
|
|||||||
9
openedx.yaml
Normal file
9
openedx.yaml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
tags:
|
||||||
|
- frontend-app
|
||||||
|
- masters
|
||||||
|
oeps:
|
||||||
|
oep-2: true # Repository metadata
|
||||||
|
openedx-release: {ref: master}
|
||||||
58053
package-lock.json
generated
58053
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
77
package.json
77
package.json
@@ -6,19 +6,16 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/edx/frontend-app-ora-grading.git"
|
"url": "git+https://github.com/edx/frontend-app-ora-grading.git"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
|
||||||
"extends @edx/browserslist-config"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "fedx-scripts webpack",
|
"build": "fedx-scripts webpack",
|
||||||
"i18n_extract": "fedx-scripts formatjs extract",
|
"i18n_extract": "BABEL_ENV=i18n fedx-scripts babel src --quiet > /dev/null",
|
||||||
"lint": "fedx-scripts eslint --ext .jsx,.js src/",
|
"lint": "fedx-scripts eslint --ext .jsx,.js src/",
|
||||||
"lint-fix": "fedx-scripts eslint --fix --ext .jsx,.js src/",
|
"lint-fix": "fedx-scripts eslint --fix --ext .jsx,.js src/",
|
||||||
"semantic-release": "semantic-release",
|
"semantic-release": "semantic-release",
|
||||||
"start": "fedx-scripts webpack-dev-server --progress",
|
"start": "fedx-scripts webpack-dev-server --progress",
|
||||||
"dev": "PUBLIC_PATH=/ora-grading/ MFE_CONFIG_API_URL='http://localhost:8000/api/mfe_config/v1' fedx-scripts webpack-dev-server --progress --host apps.local.openedx.io",
|
|
||||||
"test": "TZ=GMT fedx-scripts jest --coverage --passWithNoTests",
|
"test": "TZ=GMT fedx-scripts jest --coverage --passWithNoTests",
|
||||||
"watch-tests": "jest --watch"
|
"watch-tests": "jest --watch",
|
||||||
|
"prepare": "husky install"
|
||||||
},
|
},
|
||||||
"author": "edX",
|
"author": "edX",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
@@ -27,66 +24,70 @@
|
|||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@edx/brand": "npm:@openedx/brand-openedx@^1.2.2",
|
"@edx/brand": "npm:@edx/brand-edx.org@^2.0.3",
|
||||||
"@edx/frontend-component-footer": "^14.6.0",
|
"@edx/frontend-component-footer": "^11.1.1",
|
||||||
"@edx/frontend-component-header": "^8.0.0",
|
"@edx/frontend-component-header": "^3.1.1",
|
||||||
"@edx/frontend-platform": "^8.3.1",
|
"@edx/frontend-platform": "^2.5.1",
|
||||||
"@edx/openedx-atlas": "^0.6.0",
|
"@edx/paragon": "^19.9.0",
|
||||||
"@fortawesome/fontawesome-svg-core": "^1.2.36",
|
"@fortawesome/fontawesome-svg-core": "^1.2.36",
|
||||||
"@fortawesome/free-brands-svg-icons": "^5.15.4",
|
"@fortawesome/free-brands-svg-icons": "^5.15.4",
|
||||||
"@fortawesome/free-solid-svg-icons": "^5.15.4",
|
"@fortawesome/free-solid-svg-icons": "^5.15.4",
|
||||||
"@fortawesome/react-fontawesome": "^0.2.0",
|
"@fortawesome/react-fontawesome": "^0.1.15",
|
||||||
"@openedx/paragon": "^23.4.5",
|
|
||||||
"@redux-beacon/segment": "^1.1.0",
|
"@redux-beacon/segment": "^1.1.0",
|
||||||
"@redux-devtools/extension": "3.0.0",
|
|
||||||
"@reduxjs/toolkit": "^1.6.1",
|
"@reduxjs/toolkit": "^1.6.1",
|
||||||
"@testing-library/user-event": "^14.0.0",
|
"@testing-library/user-event": "^13.5.0",
|
||||||
"@zip.js/zip.js": "^2.4.6",
|
"@zip.js/zip.js": "^2.4.6",
|
||||||
"axios": "^0.28.0",
|
"axios": "^0.21.4",
|
||||||
"classnames": "^2.3.1",
|
"classnames": "^2.3.1",
|
||||||
"core-js": "3.35.1",
|
"core-js": "3.16.2",
|
||||||
"dompurify": "^2.3.1",
|
"dompurify": "^2.3.1",
|
||||||
"email-prop-type": "^3.0.1",
|
"email-prop-type": "^3.0.1",
|
||||||
|
"enzyme": "^3.11.0",
|
||||||
|
"enzyme-to-json": "^3.6.2",
|
||||||
"file-saver": "^2.0.5",
|
"file-saver": "^2.0.5",
|
||||||
"filesize": "^8.0.6",
|
"filesize": "^8.0.6",
|
||||||
"font-awesome": "4.7.0",
|
"font-awesome": "4.7.0",
|
||||||
"history": "5.3.0",
|
"history": "5.0.1",
|
||||||
"html-react-parser": "^1.3.0",
|
"html-react-parser": "^1.3.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"moment": "^2.29.3",
|
"moment": "^2.29.3",
|
||||||
"prop-types": "15.8.1",
|
"prop-types": "15.7.2",
|
||||||
"query-string": "7.1.3",
|
"query-string": "7.0.1",
|
||||||
"react": "^18.3.1",
|
"react": "^16.14.0",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^16.14.0",
|
||||||
"react-helmet": "^6.1.0",
|
"react-helmet": "^6.1.0",
|
||||||
"react-intl": "6.4.7",
|
"react-intl": "^5.20.9",
|
||||||
"react-pdf": "^7.0.0",
|
"react-pdf": "^5.5.0",
|
||||||
"react-redux": "^7.2.9",
|
"react-redux": "^7.2.4",
|
||||||
"react-router": "6.21.3",
|
"react-router": "5.2.0",
|
||||||
"react-router-dom": "6.21.3",
|
"react-router-dom": "5.2.0",
|
||||||
"react-router-redux": "^5.0.0-alpha.9",
|
"react-router-redux": "^5.0.0-alpha.9",
|
||||||
"redux": "4.2.1",
|
"redux": "4.1.1",
|
||||||
"redux-beacon": "^2.1.0",
|
"redux-beacon": "^2.1.0",
|
||||||
|
"redux-devtools-extension": "2.13.9",
|
||||||
"redux-logger": "3.0.6",
|
"redux-logger": "3.0.6",
|
||||||
"redux-thunk": "2.4.2",
|
"redux-thunk": "2.3.0",
|
||||||
"regenerator-runtime": "^0.14.0",
|
"regenerator-runtime": "^0.13.9",
|
||||||
"reselect": "^4.0.0",
|
"reselect": "^4.0.0",
|
||||||
"util": "^0.12.4",
|
"util": "^0.12.4",
|
||||||
"whatwg-fetch": "^3.6.2"
|
"whatwg-fetch": "^3.6.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@edx/browserslist-config": "^1.3.0",
|
"@edx/frontend-build": "12.4",
|
||||||
"@openedx/frontend-build": "^14.6.2",
|
"@edx/reactifex": "^2.1.1",
|
||||||
"@testing-library/jest-dom": "^6.6.3",
|
"@testing-library/jest-dom": "^5.14.1",
|
||||||
"@testing-library/react": "^16.2.0",
|
"@testing-library/react": "^12.1.0",
|
||||||
"axios-mock-adapter": "^1.20.0",
|
"axios-mock-adapter": "^1.20.0",
|
||||||
|
"enzyme-adapter-react-16": "^1.15.6",
|
||||||
"fetch-mock": "^9.11.0",
|
"fetch-mock": "^9.11.0",
|
||||||
|
"husky": "^7.0.0",
|
||||||
"identity-obj-proxy": "^3.0.0",
|
"identity-obj-proxy": "^3.0.0",
|
||||||
"jest": "29.7.0",
|
"jest": "27.0.6",
|
||||||
"jest-environment-jsdom": "^29.7.0",
|
|
||||||
"jest-expect-message": "^1.0.2",
|
"jest-expect-message": "^1.0.2",
|
||||||
"react-dev-utils": "^12.0.1",
|
"react-dev-utils": "^12.0.1",
|
||||||
"react-test-renderer": "^18.3.1",
|
"react-test-renderer": "^16.14.0",
|
||||||
"redux-mock-store": "^1.5.5"
|
"reactifex": "1.1.1",
|
||||||
|
"redux-mock-store": "^1.5.4",
|
||||||
|
"semantic-release": "^19.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": [
|
|
||||||
"config:base",
|
|
||||||
"schedule:weekly",
|
|
||||||
":automergeLinters",
|
|
||||||
":automergeMinor",
|
|
||||||
":automergeTesters",
|
|
||||||
":enableVulnerabilityAlerts",
|
|
||||||
":rebaseStalePrs",
|
|
||||||
":semanticCommits",
|
|
||||||
":updateNotScheduled"
|
|
||||||
],
|
|
||||||
"packageRules": [
|
|
||||||
{
|
|
||||||
"matchDepTypes": [
|
|
||||||
"devDependencies"
|
|
||||||
],
|
|
||||||
"matchUpdateTypes": [
|
|
||||||
"lockFileMaintenance",
|
|
||||||
"minor",
|
|
||||||
"patch",
|
|
||||||
"pin"
|
|
||||||
],
|
|
||||||
"automerge": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"matchPackagePatterns": ["@edx", "@openedx"],
|
|
||||||
"matchUpdateTypes": ["minor", "patch"],
|
|
||||||
"automerge": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"timezone": "America/New_York",
|
|
||||||
"schedule": ["before 11pm"]
|
|
||||||
}
|
|
||||||
@@ -3,12 +3,13 @@ import PropTypes from 'prop-types';
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { BrowserRouter as Router } from 'react-router-dom';
|
import { BrowserRouter as Router } from 'react-router-dom';
|
||||||
|
|
||||||
import { FooterSlot } from '@edx/frontend-component-footer';
|
import Footer from '@edx/frontend-component-footer';
|
||||||
import { LearningHeader as Header } from '@edx/frontend-component-header';
|
import { LearningHeader as Header } from '@edx/frontend-component-header';
|
||||||
|
|
||||||
import { selectors } from 'data/redux';
|
import { selectors } from 'data/redux';
|
||||||
|
|
||||||
import DemoWarning from 'containers/DemoWarning';
|
import DemoWarning from 'containers/DemoWarning';
|
||||||
|
import CTA from 'containers/CTA';
|
||||||
import ListView from 'containers/ListView';
|
import ListView from 'containers/ListView';
|
||||||
|
|
||||||
import './App.scss';
|
import './App.scss';
|
||||||
@@ -22,13 +23,13 @@ export const App = ({ courseMetadata, isEnabled }) => (
|
|||||||
courseTitle={courseMetadata.title}
|
courseTitle={courseMetadata.title}
|
||||||
courseNumber={courseMetadata.number}
|
courseNumber={courseMetadata.number}
|
||||||
courseOrg={courseMetadata.org}
|
courseOrg={courseMetadata.org}
|
||||||
data-testid="header"
|
|
||||||
/>
|
/>
|
||||||
{!isEnabled && <DemoWarning />}
|
{!isEnabled && <DemoWarning />}
|
||||||
<main data-testid="main">
|
<CTA />
|
||||||
|
<main>
|
||||||
<ListView />
|
<ListView />
|
||||||
</main>
|
</main>
|
||||||
<FooterSlot />
|
<Footer logo={process.env.LOGO_POWERED_BY_OPEN_EDX_URL_SVG} />
|
||||||
</div>
|
</div>
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
|
|||||||
23
src/App.scss
23
src/App.scss
@@ -1,13 +1,15 @@
|
|||||||
// frontend-app-*/src/index.scss
|
// frontend-app-*/src/index.scss
|
||||||
@use "@openedx/paragon/styles/css/core/custom-media-breakpoints" as paragonCustomMediaBreakpoints;
|
@import "~@edx/brand/paragon/fonts";
|
||||||
|
@import "~@edx/brand/paragon/variables";
|
||||||
|
@import "~@edx/paragon/scss/core/core";
|
||||||
|
@import "~@edx/brand/paragon/overrides";
|
||||||
|
|
||||||
$fa-font-path: "~font-awesome/fonts";
|
$fa-font-path: "~font-awesome/fonts";
|
||||||
@import "~font-awesome/scss/font-awesome";
|
@import "~font-awesome/scss/font-awesome";
|
||||||
|
|
||||||
$input-focus-box-shadow: var(--pgn-elevation-form-input-base); // hack to get upgrade to paragon 4.0.0 to work
|
$input-focus-box-shadow: $input-box-shadow; // hack to get upgrade to paragon 4.0.0 to work
|
||||||
|
|
||||||
@import "~@edx/frontend-component-footer/dist/_footer";
|
@import "~@edx/frontend-component-footer/dist/_footer";
|
||||||
@import "~@edx/frontend-component-header/dist/index";
|
|
||||||
|
|
||||||
#root {
|
#root {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -46,22 +48,7 @@ $input-focus-box-shadow: var(--pgn-elevation-form-input-base); // hack to get up
|
|||||||
right: 1rem !important;
|
right: 1rem !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.confirm-modal .pgn__modal-body {
|
.confirm-modal .pgn__modal-body {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pgn__modal-body-content {
|
|
||||||
& img {
|
|
||||||
object-fit: contain;
|
|
||||||
max-width: 100%;
|
|
||||||
height: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
& blockquote > p {
|
|
||||||
border-left: 2px solid var(--pgn-color-gray-200);
|
|
||||||
margin-left: 1.5rem;
|
|
||||||
padding-left: 1rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
140
src/App.test.jsx
140
src/App.test.jsx
@@ -1,101 +1,77 @@
|
|||||||
import { screen } from '@testing-library/react';
|
import React from 'react';
|
||||||
import { selectors } from 'data/redux';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import { renderWithIntl } from './testUtils';
|
import Footer from '@edx/frontend-component-footer';
|
||||||
import { App, mapStateToProps } from './App';
|
import { LearningHeader as Header } from '@edx/frontend-component-header';
|
||||||
|
|
||||||
// we want to scope these tests to the App component, so we mock some child components to reduce complexity
|
import ListView from 'containers/ListView';
|
||||||
|
|
||||||
jest.mock('@edx/frontend-platform/auth', () => ({
|
import { App } from './App';
|
||||||
getAuthenticatedHttpClient: jest.fn(),
|
|
||||||
getLoginRedirectUrl: jest.fn(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.mock('@edx/frontend-component-footer', () => ({
|
|
||||||
FooterSlot: () => <div data-testid="footer">Footer</div>,
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.mock('containers/ListView', () => function ListView() {
|
|
||||||
return <div data-testid="list-view">List View</div>;
|
|
||||||
});
|
|
||||||
|
|
||||||
jest.mock('containers/DemoWarning', () => function DemoWarning() {
|
|
||||||
return <div role="alert" data-testid="demo-warning">Demo Warning</div>;
|
|
||||||
});
|
|
||||||
|
|
||||||
jest.mock('@edx/frontend-component-header', () => ({
|
|
||||||
LearningHeader: ({ courseTitle, courseNumber, courseOrg }) => (
|
|
||||||
<div data-testid="header">
|
|
||||||
Header - {courseTitle} {courseNumber} {courseOrg}
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.mock('data/redux', () => ({
|
jest.mock('data/redux', () => ({
|
||||||
selectors: {
|
app: {
|
||||||
app: {
|
selectors: {
|
||||||
courseMetadata: jest.fn((state) => state.courseMetadata || {
|
courseMetadata: (state) => ({ courseMetadata: state }),
|
||||||
org: 'test-org',
|
isEnabled: (state) => ({ isEnabled: state }),
|
||||||
number: 'test-101',
|
|
||||||
title: 'Test Course',
|
|
||||||
}),
|
|
||||||
isEnabled: jest.fn((state) => (state.isEnabled !== undefined ? state.isEnabled : true)),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('App component', () => {
|
jest.mock('@edx/frontend-component-header', () => ({
|
||||||
const defaultProps = {
|
LearningHeader: 'Header',
|
||||||
|
}));
|
||||||
|
jest.mock('@edx/frontend-component-footer', () => 'Footer');
|
||||||
|
|
||||||
|
jest.mock('containers/DemoWarning', () => 'DemoWarning');
|
||||||
|
jest.mock('containers/CTA', () => 'CTA');
|
||||||
|
jest.mock('containers/ListView', () => 'ListView');
|
||||||
|
jest.mock('components/Head', () => 'Head');
|
||||||
|
|
||||||
|
const logo = 'fakeLogo.png';
|
||||||
|
let el;
|
||||||
|
let router;
|
||||||
|
|
||||||
|
describe('App router component', () => {
|
||||||
|
const props = {
|
||||||
courseMetadata: {
|
courseMetadata: {
|
||||||
org: 'test-org',
|
org: 'course-org',
|
||||||
number: 'test-101',
|
number: 'course-number',
|
||||||
title: 'Test Course',
|
title: 'course-title',
|
||||||
},
|
},
|
||||||
isEnabled: true,
|
isEnabled: true,
|
||||||
};
|
};
|
||||||
|
test('snapshot: enabled', () => {
|
||||||
beforeEach(() => {
|
expect(shallow(<App {...props} />)).toMatchSnapshot();
|
||||||
jest.clearAllMocks();
|
|
||||||
});
|
});
|
||||||
|
test('snapshot: disabled (show demo warning)', () => {
|
||||||
it('renders header with course metadata', () => {
|
expect(shallow(<App {...props} isEnabled={false} />)).toMatchSnapshot();
|
||||||
renderWithIntl(<App {...defaultProps} />);
|
|
||||||
const org = screen.getByText((text) => text.includes('test-org'));
|
|
||||||
expect(org).toBeInTheDocument();
|
|
||||||
const title = screen.getByText((content) => content.includes('Test Course'));
|
|
||||||
expect(title).toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
|
describe('component', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
process.env.LOGO_POWERED_BY_OPEN_EDX_URL_SVG = logo;
|
||||||
|
el = shallow(<App {...props} />);
|
||||||
|
router = el.childAt(0);
|
||||||
|
});
|
||||||
|
describe('Router', () => {
|
||||||
|
test('Routing - ListView is only route', () => {
|
||||||
|
expect(router.find('main')).toEqual(shallow(
|
||||||
|
<main><ListView /></main>,
|
||||||
|
));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
test('Footer logo drawn from env variable', () => {
|
||||||
|
expect(router.find(Footer).props().logo).toEqual(logo);
|
||||||
|
});
|
||||||
|
|
||||||
it('renders main content', () => {
|
test('Header to use courseMetadata props', () => {
|
||||||
renderWithIntl(<App {...defaultProps} />);
|
const {
|
||||||
|
courseTitle,
|
||||||
const main = screen.getByTestId('main');
|
courseNumber,
|
||||||
expect(main).toBeInTheDocument();
|
courseOrg,
|
||||||
});
|
} = router.find(Header).props();
|
||||||
|
expect(courseTitle).toEqual(props.courseMetadata.title);
|
||||||
it('does not render demo warning when enabled', () => {
|
expect(courseNumber).toEqual(props.courseMetadata.number);
|
||||||
renderWithIntl(<App {...defaultProps} />);
|
expect(courseOrg).toEqual(props.courseMetadata.org);
|
||||||
|
|
||||||
const demoWarning = screen.queryByRole('alert');
|
|
||||||
expect(demoWarning).not.toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders demo warning when disabled', () => {
|
|
||||||
renderWithIntl(<App {...defaultProps} isEnabled={false} />);
|
|
||||||
|
|
||||||
const demoWarning = screen.getByRole('alert');
|
|
||||||
expect(demoWarning).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('mapStateToProps', () => {
|
|
||||||
it('maps state properties correctly', () => {
|
|
||||||
const testState = { arbitraryState: 'some data' };
|
|
||||||
const mapped = mapStateToProps(testState);
|
|
||||||
|
|
||||||
expect(selectors.app.courseMetadata).toHaveBeenCalledWith(testState);
|
|
||||||
expect(selectors.app.isEnabled).toHaveBeenCalledWith(testState);
|
|
||||||
expect(mapped.courseMetadata).toEqual(selectors.app.courseMetadata(testState));
|
|
||||||
expect(mapped.isEnabled).toEqual(selectors.app.isEnabled(testState));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
42
src/__snapshots__/App.test.jsx.snap
Normal file
42
src/__snapshots__/App.test.jsx.snap
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`App router component snapshot: disabled (show demo warning) 1`] = `
|
||||||
|
<BrowserRouter>
|
||||||
|
<div>
|
||||||
|
<Head />
|
||||||
|
<Header
|
||||||
|
courseNumber="course-number"
|
||||||
|
courseOrg="course-org"
|
||||||
|
courseTitle="course-title"
|
||||||
|
/>
|
||||||
|
<DemoWarning />
|
||||||
|
<CTA />
|
||||||
|
<main>
|
||||||
|
<ListView />
|
||||||
|
</main>
|
||||||
|
<Footer
|
||||||
|
logo="https://edx-cdn.org/v3/stage/open-edx-tag.svg"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</BrowserRouter>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`App router component snapshot: enabled 1`] = `
|
||||||
|
<BrowserRouter>
|
||||||
|
<div>
|
||||||
|
<Head />
|
||||||
|
<Header
|
||||||
|
courseNumber="course-number"
|
||||||
|
courseOrg="course-org"
|
||||||
|
courseTitle="course-title"
|
||||||
|
/>
|
||||||
|
<CTA />
|
||||||
|
<main>
|
||||||
|
<ListView />
|
||||||
|
</main>
|
||||||
|
<Footer
|
||||||
|
logo="https://edx-cdn.org/v3/stage/open-edx-tag.svg"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</BrowserRouter>
|
||||||
|
`;
|
||||||
35
src/__snapshots__/index.test.jsx.snap
Normal file
35
src/__snapshots__/index.test.jsx.snap
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`app registry subscribe: APP_INIT_ERROR. snapshot: displays an ErrorPage to root element 1`] = `
|
||||||
|
<ErrorPage
|
||||||
|
message="test-error-message"
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`app registry subscribe: APP_READY. links App to root element 1`] = `
|
||||||
|
<IntlProvider
|
||||||
|
defaultFormats={Object {}}
|
||||||
|
defaultLocale="en"
|
||||||
|
fallbackOnEmptyString={true}
|
||||||
|
formats={Object {}}
|
||||||
|
locale="en"
|
||||||
|
messages={Object {}}
|
||||||
|
onError={[Function]}
|
||||||
|
onWarn={[Function]}
|
||||||
|
textComponent={Symbol(react.fragment)}
|
||||||
|
>
|
||||||
|
<AppProvider
|
||||||
|
store={
|
||||||
|
Object {
|
||||||
|
"dispatch": [Function],
|
||||||
|
"getState": [Function],
|
||||||
|
"replaceReducer": [Function],
|
||||||
|
"subscribe": [Function],
|
||||||
|
Symbol(Symbol.observable): [Function],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<App />
|
||||||
|
</AppProvider>
|
||||||
|
</IntlProvider>
|
||||||
|
`;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import { AlertModal, ActionRow, Button } from '@openedx/paragon';
|
import { AlertModal, ActionRow, Button } from '@edx/paragon';
|
||||||
import { nullMethod } from 'hooks';
|
import { nullMethod } from 'hooks';
|
||||||
|
|
||||||
export const ConfirmModal = ({
|
export const ConfirmModal = ({
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
import { shallow } from 'enzyme';
|
||||||
import userEvent from '@testing-library/user-event';
|
|
||||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
|
||||||
import { ConfirmModal } from './ConfirmModal';
|
import { ConfirmModal } from './ConfirmModal';
|
||||||
|
|
||||||
describe('ConfirmModal', () => {
|
describe('ConfirmModal', () => {
|
||||||
@@ -13,48 +12,10 @@ describe('ConfirmModal', () => {
|
|||||||
onCancel: jest.fn().mockName('this.props.onCancel'),
|
onCancel: jest.fn().mockName('this.props.onCancel'),
|
||||||
onConfirm: jest.fn().mockName('this.props.onConfirm'),
|
onConfirm: jest.fn().mockName('this.props.onConfirm'),
|
||||||
};
|
};
|
||||||
|
test('snapshot: closed', () => {
|
||||||
beforeEach(() => {
|
expect(shallow(<ConfirmModal {...props} />)).toMatchSnapshot();
|
||||||
jest.clearAllMocks();
|
|
||||||
});
|
});
|
||||||
|
test('snapshot: open', () => {
|
||||||
it('should not render content when modal is closed', () => {
|
expect(shallow(<ConfirmModal {...props} isOpen />)).toMatchSnapshot();
|
||||||
render(
|
|
||||||
<IntlProvider locale="en">
|
|
||||||
<ConfirmModal {...props} />
|
|
||||||
</IntlProvider>,
|
|
||||||
);
|
|
||||||
expect(screen.queryByText(props.content)).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should display content when modal is open', () => {
|
|
||||||
render(
|
|
||||||
<IntlProvider locale="en">
|
|
||||||
<ConfirmModal {...props} isOpen />
|
|
||||||
</IntlProvider>,
|
|
||||||
);
|
|
||||||
expect(screen.getByText(props.content)).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call onCancel when cancel button is clicked', async () => {
|
|
||||||
render(
|
|
||||||
<IntlProvider locale="en">
|
|
||||||
<ConfirmModal {...props} isOpen />
|
|
||||||
</IntlProvider>,
|
|
||||||
);
|
|
||||||
const user = userEvent.setup();
|
|
||||||
await user.click(screen.getByText(props.cancelText));
|
|
||||||
expect(props.onCancel).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call onConfirm when confirm button is clicked', async () => {
|
|
||||||
render(
|
|
||||||
<IntlProvider locale="en">
|
|
||||||
<ConfirmModal {...props} isOpen />
|
|
||||||
</IntlProvider>,
|
|
||||||
);
|
|
||||||
const user = userEvent.setup();
|
|
||||||
await user.click(screen.getByText(props.confirmText));
|
|
||||||
expect(props.onConfirm).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
23
src/components/DemoAlert/__snapshots__/index.test.jsx.snap
Normal file
23
src/components/DemoAlert/__snapshots__/index.test.jsx.snap
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`DemoAlert component snapshot 1`] = `
|
||||||
|
<AlertModal
|
||||||
|
footerNode={
|
||||||
|
<ActionRow>
|
||||||
|
<Button
|
||||||
|
onClick={[MockFunction props.onClose]}
|
||||||
|
variant="primary"
|
||||||
|
>
|
||||||
|
Confirm
|
||||||
|
</Button>
|
||||||
|
</ActionRow>
|
||||||
|
}
|
||||||
|
isOpen={true}
|
||||||
|
onClose={[MockFunction props.onClose]}
|
||||||
|
title="Demo submit prevented"
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
Grade submission is disabled in the Demo mode of the new ORA Staff Grader.
|
||||||
|
</p>
|
||||||
|
</AlertModal>
|
||||||
|
`;
|
||||||
@@ -1,40 +1,39 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||||
import {
|
import {
|
||||||
ActionRow,
|
ActionRow,
|
||||||
AlertModal,
|
AlertModal,
|
||||||
Button,
|
Button,
|
||||||
} from '@openedx/paragon';
|
} from '@edx/paragon';
|
||||||
|
|
||||||
import messages from './messages';
|
import messages from './messages';
|
||||||
|
|
||||||
export const DemoAlert = ({
|
export const DemoAlert = ({
|
||||||
|
intl: { formatMessage },
|
||||||
isOpen,
|
isOpen,
|
||||||
onClose,
|
onClose,
|
||||||
}) => {
|
}) => (
|
||||||
const { formatMessage } = useIntl();
|
<AlertModal
|
||||||
return (
|
title={formatMessage(messages.title)}
|
||||||
<AlertModal
|
isOpen={isOpen}
|
||||||
title={formatMessage(messages.title)}
|
onClose={onClose}
|
||||||
isOpen={isOpen}
|
footerNode={(
|
||||||
onClose={onClose}
|
<ActionRow>
|
||||||
footerNode={(
|
<Button variant="primary" onClick={onClose}>
|
||||||
<ActionRow>
|
{formatMessage(messages.confirm)}
|
||||||
<Button variant="primary" onClick={onClose}>
|
</Button>
|
||||||
{formatMessage(messages.confirm)}
|
</ActionRow>
|
||||||
</Button>
|
|
||||||
</ActionRow>
|
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<p>{formatMessage(messages.warningMessage)}</p>
|
<p>{formatMessage(messages.warningMessage)}</p>
|
||||||
</AlertModal>
|
</AlertModal>
|
||||||
);
|
);
|
||||||
};
|
|
||||||
DemoAlert.propTypes = {
|
DemoAlert.propTypes = {
|
||||||
|
intl: intlShape.isRequired,
|
||||||
isOpen: PropTypes.bool.isRequired,
|
isOpen: PropTypes.bool.isRequired,
|
||||||
onClose: PropTypes.func.isRequired,
|
onClose: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default DemoAlert;
|
export default injectIntl(DemoAlert);
|
||||||
|
|||||||
@@ -1,32 +1,16 @@
|
|||||||
import { screen } from '@testing-library/react';
|
import React from 'react';
|
||||||
import userEvent from '@testing-library/user-event';
|
import { shallow } from 'enzyme';
|
||||||
import { renderWithIntl } from '../../testUtils';
|
|
||||||
|
|
||||||
import messages from './messages';
|
import { formatMessage } from 'testUtils';
|
||||||
import { DemoAlert } from '.';
|
import { DemoAlert } from '.';
|
||||||
|
|
||||||
describe('DemoAlert component', () => {
|
describe('DemoAlert component', () => {
|
||||||
const props = {
|
test('snapshot', () => {
|
||||||
isOpen: true,
|
const props = {
|
||||||
onClose: jest.fn().mockName('props.onClose'),
|
intl: { formatMessage },
|
||||||
};
|
isOpen: true,
|
||||||
|
onClose: jest.fn().mockName('props.onClose'),
|
||||||
it('does not render when isOpen is false', () => {
|
};
|
||||||
renderWithIntl(<DemoAlert {...props} isOpen={false} />);
|
expect(shallow(<DemoAlert {...props} />)).toMatchSnapshot();
|
||||||
expect(screen.queryByText(messages.title.defaultMessage)).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders with correct title and message when isOpen is true', () => {
|
|
||||||
renderWithIntl(<DemoAlert {...props} />);
|
|
||||||
expect(screen.getByText(messages.title.defaultMessage)).toBeInTheDocument();
|
|
||||||
expect(screen.getByText(messages.warningMessage.defaultMessage)).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calls onClose when confirmation button is clicked', async () => {
|
|
||||||
renderWithIntl(<DemoAlert {...props} />);
|
|
||||||
const user = userEvent.setup();
|
|
||||||
const confirmButton = screen.getByText(messages.confirm.defaultMessage);
|
|
||||||
await user.click(confirmButton);
|
|
||||||
expect(props.onClose).toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`FilePopoverContent component snapshot default 1`] = `
|
||||||
|
<Fragment>
|
||||||
|
<div
|
||||||
|
className="help-popover-option"
|
||||||
|
>
|
||||||
|
<strong>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="File Name"
|
||||||
|
description="Popover title for file name"
|
||||||
|
id="ora-grading.FilePopoverContent.filePopoverNameTitle"
|
||||||
|
/>
|
||||||
|
</strong>
|
||||||
|
<br />
|
||||||
|
some file name
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="help-popover-option"
|
||||||
|
>
|
||||||
|
<strong>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="File Description"
|
||||||
|
description="Popover title for file description"
|
||||||
|
id="ora-grading.FilePopoverCellContent.filePopoverDescriptionTitle"
|
||||||
|
/>
|
||||||
|
</strong>
|
||||||
|
<br />
|
||||||
|
long descriptive text...
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="help-popover-option"
|
||||||
|
>
|
||||||
|
<strong>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="File Size"
|
||||||
|
description="Popover title for file size"
|
||||||
|
id="ora-grading.FilePopoverCellContent.fileSizeTitle"
|
||||||
|
/>
|
||||||
|
</strong>
|
||||||
|
<br />
|
||||||
|
filesize(6000)
|
||||||
|
</div>
|
||||||
|
</Fragment>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`FilePopoverContent component snapshot invalid size 1`] = `
|
||||||
|
<Fragment>
|
||||||
|
<div
|
||||||
|
className="help-popover-option"
|
||||||
|
>
|
||||||
|
<strong>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="File Name"
|
||||||
|
description="Popover title for file name"
|
||||||
|
id="ora-grading.FilePopoverContent.filePopoverNameTitle"
|
||||||
|
/>
|
||||||
|
</strong>
|
||||||
|
<br />
|
||||||
|
some file name
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="help-popover-option"
|
||||||
|
>
|
||||||
|
<strong>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="File Description"
|
||||||
|
description="Popover title for file description"
|
||||||
|
id="ora-grading.FilePopoverCellContent.filePopoverDescriptionTitle"
|
||||||
|
/>
|
||||||
|
</strong>
|
||||||
|
<br />
|
||||||
|
long descriptive text...
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="help-popover-option"
|
||||||
|
>
|
||||||
|
<strong>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="File Size"
|
||||||
|
description="Popover title for file size"
|
||||||
|
id="ora-grading.FilePopoverCellContent.fileSizeTitle"
|
||||||
|
/>
|
||||||
|
</strong>
|
||||||
|
<br />
|
||||||
|
Unknown
|
||||||
|
</div>
|
||||||
|
</Fragment>
|
||||||
|
`;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { screen } from '@testing-library/react';
|
import React from 'react';
|
||||||
import filesize from 'filesize';
|
import { shallow } from 'enzyme';
|
||||||
import { renderWithIntl } from '../../testUtils';
|
|
||||||
|
|
||||||
|
import filesize from 'filesize';
|
||||||
import FilePopoverContent from '.';
|
import FilePopoverContent from '.';
|
||||||
|
|
||||||
jest.mock('filesize', () => (size) => `filesize(${size})`);
|
jest.mock('filesize', () => (size) => `filesize(${size})`);
|
||||||
@@ -14,26 +14,25 @@ describe('FilePopoverContent', () => {
|
|||||||
downloadURL: 'this-url-is.working',
|
downloadURL: 'this-url-is.working',
|
||||||
size: 6000,
|
size: 6000,
|
||||||
};
|
};
|
||||||
|
let el;
|
||||||
|
beforeEach(() => {
|
||||||
|
el = shallow(<FilePopoverContent {...props} />);
|
||||||
|
});
|
||||||
|
describe('snapshot', () => {
|
||||||
|
test('default', () => expect(el).toMatchSnapshot());
|
||||||
|
test('invalid size', () => {
|
||||||
|
el.setProps({
|
||||||
|
size: null,
|
||||||
|
});
|
||||||
|
expect(el).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('behavior', () => {
|
describe('behavior', () => {
|
||||||
it('renders file name correctly', () => {
|
test('content', () => {
|
||||||
renderWithIntl(<FilePopoverContent {...props} />);
|
expect(el.text()).toContain(props.name);
|
||||||
expect(screen.getByText(props.name)).toBeInTheDocument();
|
expect(el.text()).toContain(props.description);
|
||||||
});
|
expect(el.text()).toContain(filesize(props.size));
|
||||||
|
|
||||||
it('renders file description correctly', () => {
|
|
||||||
renderWithIntl(<FilePopoverContent {...props} />);
|
|
||||||
expect(screen.getByText(props.description)).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders file size correctly', () => {
|
|
||||||
renderWithIntl(<FilePopoverContent {...props} />);
|
|
||||||
expect(screen.getByText(filesize(props.size))).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders "Unknown" when size is null', () => {
|
|
||||||
renderWithIntl(<FilePopoverContent {...props} size={null} />);
|
|
||||||
expect(screen.getByText('Unknown')).toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import { Alert, Button } from '@openedx/paragon';
|
import { Alert, Button } from '@edx/paragon';
|
||||||
import { Info } from '@openedx/paragon/icons';
|
import { Info } from '@edx/paragon/icons';
|
||||||
import { FormattedMessage } from '@edx/frontend-platform/i18n';
|
import { FormattedMessage } from '@edx/frontend-platform/i18n';
|
||||||
|
|
||||||
const messageShape = PropTypes.shape({
|
const messageShape = PropTypes.shape({
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { screen } from '@testing-library/react';
|
import React from 'react';
|
||||||
import { renderWithIntl } from '../../../testUtils';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import ErrorBanner from './ErrorBanner';
|
import ErrorBanner from './ErrorBanner';
|
||||||
|
|
||||||
import messages from '../messages';
|
import messages from '../messages';
|
||||||
|
|
||||||
describe('Error Banner component', () => {
|
describe('Error Banner component', () => {
|
||||||
@@ -23,29 +25,35 @@ describe('Error Banner component', () => {
|
|||||||
children,
|
children,
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('behavior', () => {
|
let el;
|
||||||
it('renders children content', () => {
|
beforeEach(() => {
|
||||||
renderWithIntl(<ErrorBanner {...props} />);
|
el = shallow(<ErrorBanner {...props} />);
|
||||||
const childText = screen.getByText('Abitary Child');
|
});
|
||||||
expect(childText).toBeInTheDocument();
|
|
||||||
|
test('snapshot', () => {
|
||||||
|
expect(el).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('component', () => {
|
||||||
|
test('children node', () => {
|
||||||
|
expect(el.containsMatchingElement(children)).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders the correct number of action buttons', () => {
|
test('verify actions', () => {
|
||||||
renderWithIntl(<ErrorBanner {...props} />);
|
const actions = el.find('Alert').prop('actions');
|
||||||
const buttons = screen.getAllByText(messages.retryButton.defaultMessage);
|
expect(actions).toHaveLength(props.actions.length);
|
||||||
expect(buttons).toHaveLength(2);
|
|
||||||
|
actions.forEach((action, index) => {
|
||||||
|
expect(action.type).toEqual('Button');
|
||||||
|
expect(action.props.onClick).toEqual(props.actions[index].onClick);
|
||||||
|
// action message
|
||||||
|
expect(action.props.children.props).toEqual(props.actions[index].message);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders error heading with correct message', () => {
|
test('verify heading', () => {
|
||||||
renderWithIntl(<ErrorBanner {...props} />);
|
const heading = el.find('FormattedMessage');
|
||||||
const heading = screen.getAllByText(messages.unknownError.defaultMessage)[0];
|
expect(heading.props()).toEqual(props.headingMessage);
|
||||||
expect(heading).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders with danger variant', () => {
|
|
||||||
renderWithIntl(<ErrorBanner {...props} />);
|
|
||||||
const alert = screen.getByRole('alert');
|
|
||||||
expect(alert).toHaveClass('alert-danger');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { Alert, Spinner } from '@openedx/paragon';
|
import { Alert, Spinner } from '@edx/paragon';
|
||||||
|
|
||||||
export const LoadingBanner = () => (
|
export const LoadingBanner = () => (
|
||||||
<Alert variant="info">
|
<Alert variant="info">
|
||||||
|
|||||||
@@ -1,19 +1,11 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
import React from 'react';
|
||||||
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import LoadingBanner from './LoadingBanner';
|
import LoadingBanner from './LoadingBanner';
|
||||||
|
|
||||||
describe('Loading Banner component', () => {
|
describe('Loading Banner component', () => {
|
||||||
describe('behavior', () => {
|
test('snapshot', () => {
|
||||||
it('renders an info alert', () => {
|
const el = shallow(<LoadingBanner />);
|
||||||
render(<LoadingBanner />);
|
expect(el).toMatchSnapshot();
|
||||||
const alert = screen.getByRole('alert');
|
|
||||||
expect(alert).toHaveClass('alert-info');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders a spinner', () => {
|
|
||||||
const { container } = render(<LoadingBanner />);
|
|
||||||
const spinner = container.querySelector('.pgn__spinner');
|
|
||||||
expect(spinner).toBeInTheDocument();
|
|
||||||
expect(spinner).toHaveClass('spinner-border');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`Error Banner component snapshot 1`] = `
|
||||||
|
<Alert
|
||||||
|
actions={
|
||||||
|
Array [
|
||||||
|
<Button
|
||||||
|
onClick={[MockFunction action1.onClick]}
|
||||||
|
variant="outline-primary"
|
||||||
|
>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="Retry"
|
||||||
|
description="Retry button for error in file renderer"
|
||||||
|
id="ora-grading.ResponseDisplay.FileRenderer.retryButton"
|
||||||
|
/>
|
||||||
|
</Button>,
|
||||||
|
<Button
|
||||||
|
onClick={[MockFunction action2.onClick]}
|
||||||
|
variant="outline-primary"
|
||||||
|
>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="Retry"
|
||||||
|
description="Retry button for error in file renderer"
|
||||||
|
id="ora-grading.ResponseDisplay.FileRenderer.retryButton"
|
||||||
|
/>
|
||||||
|
</Button>,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
variant="danger"
|
||||||
|
>
|
||||||
|
<Alert.Heading>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="Unknown errors"
|
||||||
|
description="Unknown errors message"
|
||||||
|
id="ora-grading.ResponseDisplay.FileRenderer.unknownError"
|
||||||
|
/>
|
||||||
|
</Alert.Heading>
|
||||||
|
<p>
|
||||||
|
Abitary Child
|
||||||
|
</p>
|
||||||
|
</Alert>
|
||||||
|
`;
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`Loading Banner component snapshot 1`] = `
|
||||||
|
<Alert
|
||||||
|
variant="info"
|
||||||
|
>
|
||||||
|
<Spinner
|
||||||
|
animation="border"
|
||||||
|
className="d-flex m-auto"
|
||||||
|
/>
|
||||||
|
</Alert>
|
||||||
|
`;
|
||||||
@@ -1,40 +1,21 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render, screen } from '@testing-library/react';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import ImageRenderer from './ImageRenderer';
|
import ImageRenderer from './ImageRenderer';
|
||||||
|
|
||||||
describe('Image Renderer Component', () => {
|
describe('Image Renderer Component', () => {
|
||||||
const props = {
|
const props = {
|
||||||
url: 'some_url.jpg',
|
url: 'some_url.jpg',
|
||||||
fileName: 'test-image.jpg',
|
|
||||||
onError: jest.fn().mockName('this.props.onError'),
|
|
||||||
onSuccess: jest.fn().mockName('this.props.onSuccess'),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
it('renders an image with the correct src and alt attributes', () => {
|
props.onError = jest.fn().mockName('this.props.onError');
|
||||||
render(<ImageRenderer {...props} />);
|
props.onSuccess = jest.fn().mockName('this.props.onSuccess');
|
||||||
const imgElement = screen.getByRole('img');
|
|
||||||
expect(imgElement).toBeInTheDocument();
|
let el;
|
||||||
expect(imgElement).toHaveAttribute('src', props.url);
|
beforeEach(() => {
|
||||||
expect(imgElement).toHaveAttribute('alt', props.fileName);
|
el = shallow(<ImageRenderer {...props} />);
|
||||||
expect(imgElement).toHaveClass('image-renderer');
|
|
||||||
});
|
});
|
||||||
|
test('snapshot', () => {
|
||||||
it('calls onSuccess when image loads successfully', () => {
|
expect(el).toMatchSnapshot();
|
||||||
render(<ImageRenderer {...props} />);
|
|
||||||
|
|
||||||
const imgElement = screen.getByRole('img');
|
|
||||||
imgElement.dispatchEvent(new Event('load'));
|
|
||||||
|
|
||||||
expect(props.onSuccess).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calls onError when image fails to load', () => {
|
|
||||||
render(<ImageRenderer {...props} />);
|
|
||||||
|
|
||||||
const imgElement = screen.getByRole('img');
|
|
||||||
imgElement.dispatchEvent(new Event('error'));
|
|
||||||
|
|
||||||
expect(props.onError).toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Document, Page, pdfjs } from 'react-pdf';
|
|
||||||
|
import { pdfjs, Document, Page } from 'react-pdf';
|
||||||
import {
|
import {
|
||||||
Icon, Form, ActionRow, IconButton,
|
Icon, Form, ActionRow, IconButton,
|
||||||
} from '@openedx/paragon';
|
} from '@edx/paragon';
|
||||||
import { ChevronLeft, ChevronRight } from '@openedx/paragon/icons';
|
import { ChevronLeft, ChevronRight } from '@edx/paragon/icons';
|
||||||
|
import pdfjsWorker from 'react-pdf/dist/esm/pdf.worker.entry';
|
||||||
|
|
||||||
import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
|
import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
|
||||||
import { rendererHooks } from './pdfHooks';
|
import { rendererHooks } from './pdfHooks';
|
||||||
|
|
||||||
pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.js`;
|
pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <PDFRenderer />
|
* <PDFRenderer />
|
||||||
|
|||||||
@@ -1,22 +1,16 @@
|
|||||||
import { Document, Page } from 'react-pdf';
|
import React from 'react';
|
||||||
import { render } from '@testing-library/react';
|
import { shallow } from 'enzyme';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import PDFRenderer from './PDFRenderer';
|
import PDFRenderer from './PDFRenderer';
|
||||||
|
|
||||||
import * as hooks from './pdfHooks';
|
import * as hooks from './pdfHooks';
|
||||||
|
|
||||||
jest.mock('react-pdf', () => ({
|
jest.mock('react-pdf', () => ({
|
||||||
pdfjs: { GlobalWorkerOptions: {} },
|
pdfjs: { GlobalWorkerOptions: {} },
|
||||||
Document: jest.fn(),
|
Document: () => 'Document',
|
||||||
Page: jest.fn(),
|
Page: () => 'Page',
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Document.mockImplementation((props) => <div data-testid="pdf-document">{props.children}</div>);
|
|
||||||
Document.propTypes = {
|
|
||||||
children: PropTypes.node,
|
|
||||||
};
|
|
||||||
|
|
||||||
Page.mockImplementation(() => <div data-testid="pdf-page">Page Content</div>);
|
|
||||||
|
|
||||||
jest.mock('./pdfHooks', () => ({
|
jest.mock('./pdfHooks', () => ({
|
||||||
rendererHooks: jest.fn(),
|
rendererHooks: jest.fn(),
|
||||||
}));
|
}));
|
||||||
@@ -39,45 +33,25 @@ describe('PDF Renderer Component', () => {
|
|||||||
onNextPageButtonClick: jest.fn().mockName('hooks.onNextPageButtonClick'),
|
onNextPageButtonClick: jest.fn().mockName('hooks.onNextPageButtonClick'),
|
||||||
onPrevPageButtonClick: jest.fn().mockName('hooks.onPrevPageButtonClick'),
|
onPrevPageButtonClick: jest.fn().mockName('hooks.onPrevPageButtonClick'),
|
||||||
hasNext: true,
|
hasNext: true,
|
||||||
hasPrev: false,
|
hasPref: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
describe('snapshots', () => {
|
||||||
describe('rendering', () => {
|
test('first page, prev is disabled', () => {
|
||||||
it('should render the PDF document with navigation controls', () => {
|
|
||||||
hooks.rendererHooks.mockReturnValue(hookProps);
|
hooks.rendererHooks.mockReturnValue(hookProps);
|
||||||
const { getByTestId, getAllByText, container } = render(<PDFRenderer {...props} />);
|
expect(shallow(<PDFRenderer {...props} />)).toMatchSnapshot();
|
||||||
expect(getByTestId('pdf-document')).toBeInTheDocument();
|
|
||||||
expect(getByTestId('pdf-page')).toBeInTheDocument();
|
|
||||||
expect(container.querySelector('input[type="number"]')).toBeInTheDocument();
|
|
||||||
expect(getAllByText(/Page/).length).toBeGreaterThan(0);
|
|
||||||
expect(getAllByText(`of ${hookProps.numPages}`).length).toBeGreaterThan(0);
|
|
||||||
});
|
});
|
||||||
|
test('on last page, next is disabled', () => {
|
||||||
it('should have disabled previous button when on the first page', () => {
|
|
||||||
hooks.rendererHooks.mockReturnValue({
|
|
||||||
...hookProps,
|
|
||||||
hasPrev: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { container } = render(<PDFRenderer {...props} />);
|
|
||||||
const prevButton = container.querySelector('button[aria-label="previous pdf page"]');
|
|
||||||
expect(prevButton).toBeDisabled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should have disabled next button when on the last page', () => {
|
|
||||||
hooks.rendererHooks.mockReturnValue({
|
hooks.rendererHooks.mockReturnValue({
|
||||||
...hookProps,
|
...hookProps,
|
||||||
|
pageNumber: hookProps.numPages,
|
||||||
hasNext: false,
|
hasNext: false,
|
||||||
hasPrev: true,
|
hasPrev: true,
|
||||||
});
|
});
|
||||||
|
expect(shallow(<PDFRenderer {...props} />)).toMatchSnapshot();
|
||||||
const { container } = render(<PDFRenderer {...props} />);
|
|
||||||
const nextButton = container.querySelector('button[aria-label="next pdf page"]');
|
|
||||||
expect(nextButton).toBeDisabled();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,38 +1,23 @@
|
|||||||
import { render } from '@testing-library/react';
|
import React from 'react';
|
||||||
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import TXTRenderer from './TXTRenderer';
|
import TXTRenderer from './TXTRenderer';
|
||||||
|
|
||||||
jest.mock('./textHooks', () => {
|
jest.mock('./textHooks', () => {
|
||||||
const mockRendererHooks = jest.fn().mockReturnValue({ content: 'test-content' });
|
const content = 'test-content';
|
||||||
return {
|
return {
|
||||||
rendererHooks: mockRendererHooks,
|
content,
|
||||||
|
rendererHooks: (args) => ({ content, rendererHooks: args }),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const textHooks = require('./textHooks');
|
|
||||||
|
|
||||||
describe('TXT Renderer Component', () => {
|
describe('TXT Renderer Component', () => {
|
||||||
const props = {
|
const props = {
|
||||||
url: 'some_url.txt',
|
url: 'some_url.txt',
|
||||||
onError: jest.fn().mockName('this.props.onError'),
|
onError: jest.fn().mockName('this.props.onError'),
|
||||||
onSuccess: jest.fn().mockName('this.props.onSuccess'),
|
onSuccess: jest.fn().mockName('this.props.onSuccess'),
|
||||||
};
|
};
|
||||||
|
test('snapshot', () => {
|
||||||
beforeEach(() => {
|
expect(shallow(<TXTRenderer {...props} />)).toMatchSnapshot();
|
||||||
textHooks.rendererHooks.mockClear();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders the text content in a pre element', () => {
|
|
||||||
const { getByText, container } = render(<TXTRenderer {...props} />);
|
|
||||||
expect(getByText('test-content')).toBeInTheDocument();
|
|
||||||
expect(container.querySelector('pre')).toHaveClass('txt-renderer');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('passes the correct props to rendererHooks', () => {
|
|
||||||
render(<TXTRenderer {...props} />);
|
|
||||||
expect(textHooks.rendererHooks).toHaveBeenCalledWith({
|
|
||||||
url: props.url,
|
|
||||||
onError: props.onError,
|
|
||||||
onSuccess: props.onSuccess,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`Image Renderer Component snapshot 1`] = `
|
||||||
|
<img
|
||||||
|
alt=""
|
||||||
|
className="image-renderer"
|
||||||
|
onError={[MockFunction this.props.onError]}
|
||||||
|
onLoad={[MockFunction this.props.onSuccess]}
|
||||||
|
src="some_url.jpg"
|
||||||
|
/>
|
||||||
|
`;
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`PDF Renderer Component snapshots first page, prev is disabled 1`] = `
|
||||||
|
<div
|
||||||
|
className="pdf-renderer"
|
||||||
|
>
|
||||||
|
<Document
|
||||||
|
file="some_url.pdf"
|
||||||
|
onLoadError={[MockFunction hooks.onDocumentLoadError]}
|
||||||
|
onLoadSuccess={[MockFunction hooks.onDocumentLoadSuccess]}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="page-wrapper"
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": 200,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Page
|
||||||
|
onLoadSuccess={[MockFunction hooks.onLoadPageSuccess]}
|
||||||
|
pageNumber={1}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Document>
|
||||||
|
<ActionRow
|
||||||
|
className="d-flex justify-content-center m-0"
|
||||||
|
>
|
||||||
|
<IconButton
|
||||||
|
alt="previous pdf page"
|
||||||
|
disabled={true}
|
||||||
|
iconAs="Icon"
|
||||||
|
onClick={[MockFunction hooks.onPrevPageButtonClick]}
|
||||||
|
size="inline"
|
||||||
|
src={[MockFunction icons.ChevronLeft]}
|
||||||
|
/>
|
||||||
|
<Form.Group
|
||||||
|
className="d-flex align-items-center m-0"
|
||||||
|
>
|
||||||
|
<Form.Label
|
||||||
|
isInline={true}
|
||||||
|
>
|
||||||
|
Page
|
||||||
|
</Form.Label>
|
||||||
|
<Form.Control
|
||||||
|
max={10}
|
||||||
|
min={0}
|
||||||
|
onChange={[MockFunction hooks.onInputPageChange]}
|
||||||
|
type="number"
|
||||||
|
value={1}
|
||||||
|
/>
|
||||||
|
<Form.Label
|
||||||
|
isInline={true}
|
||||||
|
>
|
||||||
|
of
|
||||||
|
10
|
||||||
|
</Form.Label>
|
||||||
|
</Form.Group>
|
||||||
|
<IconButton
|
||||||
|
alt="next pdf page"
|
||||||
|
disabled={false}
|
||||||
|
iconAs="Icon"
|
||||||
|
onClick={[MockFunction hooks.onNextPageButtonClick]}
|
||||||
|
size="inline"
|
||||||
|
src={[MockFunction icons.ChevronRight]}
|
||||||
|
/>
|
||||||
|
</ActionRow>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`PDF Renderer Component snapshots on last page, next is disabled 1`] = `
|
||||||
|
<div
|
||||||
|
className="pdf-renderer"
|
||||||
|
>
|
||||||
|
<Document
|
||||||
|
file="some_url.pdf"
|
||||||
|
onLoadError={[MockFunction hooks.onDocumentLoadError]}
|
||||||
|
onLoadSuccess={[MockFunction hooks.onDocumentLoadSuccess]}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="page-wrapper"
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": 200,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Page
|
||||||
|
onLoadSuccess={[MockFunction hooks.onLoadPageSuccess]}
|
||||||
|
pageNumber={10}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Document>
|
||||||
|
<ActionRow
|
||||||
|
className="d-flex justify-content-center m-0"
|
||||||
|
>
|
||||||
|
<IconButton
|
||||||
|
alt="previous pdf page"
|
||||||
|
disabled={false}
|
||||||
|
iconAs="Icon"
|
||||||
|
onClick={[MockFunction hooks.onPrevPageButtonClick]}
|
||||||
|
size="inline"
|
||||||
|
src={[MockFunction icons.ChevronLeft]}
|
||||||
|
/>
|
||||||
|
<Form.Group
|
||||||
|
className="d-flex align-items-center m-0"
|
||||||
|
>
|
||||||
|
<Form.Label
|
||||||
|
isInline={true}
|
||||||
|
>
|
||||||
|
Page
|
||||||
|
</Form.Label>
|
||||||
|
<Form.Control
|
||||||
|
max={10}
|
||||||
|
min={0}
|
||||||
|
onChange={[MockFunction hooks.onInputPageChange]}
|
||||||
|
type="number"
|
||||||
|
value={10}
|
||||||
|
/>
|
||||||
|
<Form.Label
|
||||||
|
isInline={true}
|
||||||
|
>
|
||||||
|
of
|
||||||
|
10
|
||||||
|
</Form.Label>
|
||||||
|
</Form.Group>
|
||||||
|
<IconButton
|
||||||
|
alt="next pdf page"
|
||||||
|
disabled={true}
|
||||||
|
iconAs="Icon"
|
||||||
|
onClick={[MockFunction hooks.onNextPageButtonClick]}
|
||||||
|
size="inline"
|
||||||
|
src={[MockFunction icons.ChevronRight]}
|
||||||
|
/>
|
||||||
|
</ActionRow>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`TXT Renderer Component snapshot 1`] = `
|
||||||
|
<pre
|
||||||
|
className="txt-renderer"
|
||||||
|
>
|
||||||
|
test-content
|
||||||
|
</pre>
|
||||||
|
`;
|
||||||
@@ -1,11 +1,16 @@
|
|||||||
import { useState, useRef } from 'react';
|
import { useState, useRef } from 'react';
|
||||||
|
|
||||||
|
import { pdfjs } from 'react-pdf';
|
||||||
|
import pdfjsWorker from 'react-pdf/dist/esm/pdf.worker.entry';
|
||||||
|
|
||||||
import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
|
import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
|
||||||
|
|
||||||
import { ErrorStatuses } from 'data/constants/requests';
|
import { ErrorStatuses } from 'data/constants/requests';
|
||||||
import { StrictDict } from 'utils';
|
import { StrictDict } from 'utils';
|
||||||
import * as module from './pdfHooks';
|
import * as module from './pdfHooks';
|
||||||
|
|
||||||
|
pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;
|
||||||
|
|
||||||
export const errors = StrictDict({
|
export const errors = StrictDict({
|
||||||
missingPDF: 'MissingPDFException',
|
missingPDF: 'MissingPDFException',
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,11 +12,6 @@ jest.mock('react-pdf', () => ({
|
|||||||
Page: () => 'Page',
|
Page: () => 'Page',
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('react', () => ({
|
|
||||||
...jest.requireActual('react'),
|
|
||||||
useRef: jest.fn((val) => ({ current: val, useRef: true })),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const state = new MockUseState(hooks);
|
const state = new MockUseState(hooks);
|
||||||
const hookKeys = keyStore(hooks);
|
const hookKeys = keyStore(hooks);
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export const fetchFile = async ({
|
|||||||
onSuccess();
|
onSuccess();
|
||||||
setContent(data);
|
setContent(data);
|
||||||
})
|
})
|
||||||
.catch((e) => onError(e.response?.status));
|
.catch((e) => onError(e.response.status));
|
||||||
|
|
||||||
export const rendererHooks = ({ url, onError, onSuccess }) => {
|
export const rendererHooks = ({ url, onError, onSuccess }) => {
|
||||||
const [content, setContent] = module.state.content('');
|
const [content, setContent] = module.state.content('');
|
||||||
|
|||||||
@@ -10,11 +10,6 @@ jest.mock('axios', () => ({
|
|||||||
get: jest.fn(),
|
get: jest.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('react', () => ({
|
|
||||||
...jest.requireActual('react'),
|
|
||||||
useEffect: jest.fn((cb, prereqs) => ({ useEffect: { cb, prereqs } })),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const hookKeys = keyStore(hooks);
|
const hookKeys = keyStore(hooks);
|
||||||
const state = new MockUseState(hooks);
|
const state = new MockUseState(hooks);
|
||||||
|
|
||||||
@@ -86,12 +81,13 @@ describe('Text file preview hooks', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('onError', () => {
|
describe('onError', () => {
|
||||||
it('calls get on the passed url when it changes', async () => {
|
it('calls get on the passed url when it changes', async (done) => {
|
||||||
axios.get.mockReturnValueOnce(Promise.reject(
|
axios.get.mockReturnValueOnce(Promise.reject(
|
||||||
{ response: { status: testValue } },
|
{ response: { status: testValue } },
|
||||||
));
|
));
|
||||||
await hooks.fetchFile({ ...props, setContent: state.setState.content });
|
await hooks.fetchFile({ ...props, setContent: state.setState.content });
|
||||||
expect(props.onError).toHaveBeenCalledWith(testValue);
|
expect(props.onError).toHaveBeenCalledWith(testValue);
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import { Card, Collapsible } from '@openedx/paragon';
|
import { Card, Collapsible } from '@edx/paragon';
|
||||||
import FilePopoverContent from 'components/FilePopoverContent';
|
import FilePopoverContent from 'components/FilePopoverContent';
|
||||||
import FileInfo from './FileInfo';
|
import FileInfo from './FileInfo';
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ export const FileCard = ({ file, children }) => (
|
|||||||
defaultOpen
|
defaultOpen
|
||||||
title={<h3 className="file-card-title">{file.name}</h3>}
|
title={<h3 className="file-card-title">{file.name}</h3>}
|
||||||
>
|
>
|
||||||
<div className="preview-panel" data-testid="preview-panel">
|
<div className="preview-panel">
|
||||||
<FileInfo><FilePopoverContent {...file} /></FileInfo>
|
<FileInfo><FilePopoverContent {...file} /></FileInfo>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
@import "@edx/paragon/scss/core/core";
|
||||||
|
|
||||||
.file-card {
|
.file-card {
|
||||||
margin: var(--pgn-spacing-spacer-1) 0;
|
margin: map-get($spacers, 1) 0;
|
||||||
|
|
||||||
.file-card-title {
|
.file-card-title {
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
@@ -24,8 +26,8 @@
|
|||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (--pgn-size-breakpoint-max-width-sm) {
|
@include media-breakpoint-down(sm) {
|
||||||
.file-card-title {
|
.file-card-title {
|
||||||
width: calc(var(--pgn-size-container-max-width-sm)/2);
|
width: map-get($container-max-widths, "sm")/2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,10 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
import React from 'react';
|
||||||
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
|
import { Collapsible } from '@edx/paragon';
|
||||||
|
|
||||||
|
import FilePopoverContent from 'components/FilePopoverContent';
|
||||||
|
import FileInfo from './FileInfo';
|
||||||
import FileCard from './FileCard';
|
import FileCard from './FileCard';
|
||||||
|
|
||||||
jest.mock('components/FilePopoverContent', () => 'FilePopoverContent');
|
jest.mock('components/FilePopoverContent', () => 'FilePopoverContent');
|
||||||
@@ -13,27 +19,24 @@ describe('File Preview Card component', () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
const children = (<h1>some children</h1>);
|
const children = (<h1>some children</h1>);
|
||||||
|
let el;
|
||||||
|
beforeEach(() => {
|
||||||
|
el = shallow(<FileCard {...props}>{children}</FileCard>);
|
||||||
|
});
|
||||||
|
test('snapshot', () => {
|
||||||
|
expect(el).toMatchSnapshot();
|
||||||
|
});
|
||||||
describe('Component', () => {
|
describe('Component', () => {
|
||||||
it('renders with the file name in the title', () => {
|
test('collapsible title is name header', () => {
|
||||||
render(<FileCard {...props}>{children}</FileCard>);
|
const title = el.find(Collapsible).prop('title');
|
||||||
expect(screen.getByText(props.file.name)).toBeInTheDocument();
|
expect(title).toEqual(<h3 className="file-card-title">{props.file.name}</h3>);
|
||||||
expect(screen.getByText(props.file.name)).toHaveClass('file-card-title');
|
|
||||||
});
|
});
|
||||||
|
test('forwards children into preview-panel', () => {
|
||||||
it('renders the preview panel with file info', () => {
|
const previewPanelChildren = el.find('.preview-panel').children();
|
||||||
render(<FileCard {...props}>{children}</FileCard>);
|
expect(previewPanelChildren.at(0).equals(
|
||||||
const previewPanel = screen.getByTestId('preview-panel');
|
<FileInfo><FilePopoverContent file={props.file} /></FileInfo>,
|
||||||
expect(previewPanel).toBeInTheDocument();
|
));
|
||||||
expect(document.querySelector('FileInfo')).toBeInTheDocument();
|
expect(previewPanelChildren.at(1).equals(children)).toEqual(true);
|
||||||
expect(document.querySelector('FilePopoverContent')).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders children in the preview panel', () => {
|
|
||||||
render(<FileCard {...props}>{children}</FileCard>);
|
|
||||||
const previewPanel = screen.getByTestId('preview-panel');
|
|
||||||
expect(previewPanel).toBeInTheDocument();
|
|
||||||
expect(screen.getByText('some children')).toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
OverlayTrigger,
|
OverlayTrigger,
|
||||||
Popover,
|
Popover,
|
||||||
} from '@openedx/paragon';
|
} from '@edx/paragon';
|
||||||
import { InfoOutline } from '@openedx/paragon/icons';
|
import { InfoOutline } from '@edx/paragon/icons';
|
||||||
import { FormattedMessage } from '@edx/frontend-platform/i18n';
|
import { FormattedMessage } from '@edx/frontend-platform/i18n';
|
||||||
import { nullMethod } from 'hooks';
|
import { nullMethod } from 'hooks';
|
||||||
import messages from './messages';
|
import messages from './messages';
|
||||||
@@ -26,7 +26,7 @@ export const FileInfo = ({ onClick, children }) => (
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="small"
|
||||||
variant="tertiary"
|
variant="tertiary"
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
iconAfter={InfoOutline}
|
iconAfter={InfoOutline}
|
||||||
|
|||||||
@@ -1,29 +1,25 @@
|
|||||||
import { screen } from '@testing-library/react';
|
import React from 'react';
|
||||||
import userEvent from '@testing-library/user-event';
|
import { shallow } from 'enzyme';
|
||||||
import { renderWithIntl } from '../../testUtils';
|
|
||||||
|
import { Popover } from '@edx/paragon';
|
||||||
|
|
||||||
import FileInfo from './FileInfo';
|
import FileInfo from './FileInfo';
|
||||||
import messages from './messages';
|
|
||||||
|
|
||||||
describe('FileInfo component', () => {
|
describe('File Preview Card component', () => {
|
||||||
const children = (<h1>some Children</h1>);
|
const children = (<h1>some Children</h1>);
|
||||||
const props = { onClick: jest.fn().mockName('this.props.onClick') };
|
const props = { onClick: jest.fn().mockName('this.props.onClick') };
|
||||||
|
let el;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
el = shallow(<FileInfo {...props}>{children}</FileInfo>);
|
||||||
});
|
});
|
||||||
|
test('snapshot', () => {
|
||||||
describe('Component rendering', () => {
|
expect(el).toMatchSnapshot();
|
||||||
it('renders the FileInfo button with correct text', () => {
|
});
|
||||||
renderWithIntl(<FileInfo {...props}>{children}</FileInfo>);
|
describe('Component', () => {
|
||||||
expect(screen.getByText(messages.fileInfo.defaultMessage)).toBeInTheDocument();
|
test('overlay with passed children', () => {
|
||||||
});
|
const { overlay } = el.at(0).props();
|
||||||
|
expect(overlay.type).toEqual(Popover);
|
||||||
it('calls onClick when button is clicked', async () => {
|
expect(overlay.props.children).toEqual(<Popover.Content>{children}</Popover.Content>);
|
||||||
renderWithIntl(<FileInfo {...props}>{children}</FileInfo>);
|
|
||||||
const user = userEvent.setup();
|
|
||||||
await user.click(screen.getByText(messages.fileInfo.defaultMessage));
|
|
||||||
expect(props.onClick).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||||
|
|
||||||
import FileCard from './FileCard';
|
import FileCard from './FileCard';
|
||||||
import { ErrorBanner, LoadingBanner } from './Banners';
|
import { ErrorBanner, LoadingBanner } from './Banners';
|
||||||
@@ -12,8 +12,8 @@ import { renderHooks } from './hooks';
|
|||||||
*/
|
*/
|
||||||
export const FileRenderer = ({
|
export const FileRenderer = ({
|
||||||
file,
|
file,
|
||||||
|
intl,
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
|
||||||
const {
|
const {
|
||||||
Renderer,
|
Renderer,
|
||||||
isLoading,
|
isLoading,
|
||||||
@@ -39,6 +39,8 @@ FileRenderer.propTypes = {
|
|||||||
name: PropTypes.string,
|
name: PropTypes.string,
|
||||||
downloadUrl: PropTypes.string,
|
downloadUrl: PropTypes.string,
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
|
// injected
|
||||||
|
intl: intlShape.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default FileRenderer;
|
export default injectIntl(FileRenderer);
|
||||||
|
|||||||
@@ -1,79 +1,53 @@
|
|||||||
import { screen } from '@testing-library/react';
|
import React from 'react';
|
||||||
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
|
import { formatMessage } from 'testUtils';
|
||||||
import { keyStore } from 'utils';
|
import { keyStore } from 'utils';
|
||||||
import { ErrorStatuses } from 'data/constants/requests';
|
import { ErrorStatuses } from 'data/constants/requests';
|
||||||
import { renderWithIntl } from '../../testUtils';
|
|
||||||
import { FileRenderer } from './FileRenderer';
|
import { FileRenderer } from './FileRenderer';
|
||||||
import * as hooks from './hooks';
|
import * as hooks from './hooks';
|
||||||
|
|
||||||
|
jest.mock('./FileCard', () => 'FileCard');
|
||||||
|
jest.mock('./Banners', () => ({
|
||||||
|
ErrorBanner: () => 'ErrorBanner',
|
||||||
|
LoadingBanner: () => 'LoadingBanner',
|
||||||
|
}));
|
||||||
|
|
||||||
const hookKeys = keyStore(hooks);
|
const hookKeys = keyStore(hooks);
|
||||||
|
|
||||||
const props = {
|
const props = {
|
||||||
file: {
|
file: {
|
||||||
downloadUrl: 'file download url',
|
downloadUrl: 'file download url',
|
||||||
name: 'filename.txt',
|
name: 'filename.txt',
|
||||||
description: 'A text file',
|
|
||||||
},
|
},
|
||||||
|
intl: { formatMessage },
|
||||||
};
|
};
|
||||||
describe('FileRenderer', () => {
|
describe('FileRenderer', () => {
|
||||||
describe('component', () => {
|
describe('component', () => {
|
||||||
it('renders loading banner when isLoading is true', () => {
|
describe('snapshot', () => {
|
||||||
const hookProps = {
|
test('isLoading, no Error', () => {
|
||||||
Renderer: () => <div data-testid="mock-renderer">Renderer Component</div>,
|
const hookProps = {
|
||||||
isLoading: true,
|
Renderer: () => 'Renderer',
|
||||||
errorStatus: null,
|
isloading: true,
|
||||||
error: null,
|
errorStatus: null,
|
||||||
rendererProps: { prop: 'hooks.rendererProps' },
|
error: null,
|
||||||
};
|
rendererProps: { prop: 'hooks.rendererProps' },
|
||||||
jest.spyOn(hooks, hookKeys.renderHooks).mockReturnValueOnce(hookProps);
|
};
|
||||||
renderWithIntl(<FileRenderer {...props} />);
|
jest.spyOn(hooks, hookKeys.renderHooks).mockReturnValueOnce(hookProps);
|
||||||
|
expect(shallow(<FileRenderer {...props} />)).toMatchSnapshot();
|
||||||
expect(screen.getByText('filename.txt')).toBeInTheDocument();
|
});
|
||||||
expect(screen.getByTestId('mock-renderer')).toBeInTheDocument();
|
test('is not loading, with error', () => {
|
||||||
const spinner = document.querySelector('.spinner-border');
|
const hookProps = {
|
||||||
expect(spinner).toBeInTheDocument();
|
Renderer: () => 'Renderer',
|
||||||
});
|
isloading: false,
|
||||||
it('renders error banner when there is an error status', () => {
|
errorStatus: ErrorStatuses.serverError,
|
||||||
const errorProps = {
|
error: { prop: 'hooks.errorProps' },
|
||||||
headingMessage: { id: 'error.heading', defaultMessage: 'Error Heading' },
|
rendererProps: { prop: 'hooks.rendererProps' },
|
||||||
children: 'Error Message',
|
};
|
||||||
actions: [{ id: 'retry', onClick: jest.fn(), message: { id: 'retry', defaultMessage: 'Retry' } }],
|
jest.spyOn(hooks, hookKeys.renderHooks).mockReturnValueOnce(hookProps);
|
||||||
};
|
expect(shallow(<FileRenderer {...props} />)).toMatchSnapshot();
|
||||||
|
});
|
||||||
const hookProps = {
|
|
||||||
Renderer: () => <div data-testid="mock-renderer">Renderer Component</div>,
|
|
||||||
isLoading: false,
|
|
||||||
errorStatus: ErrorStatuses.serverError,
|
|
||||||
error: errorProps,
|
|
||||||
rendererProps: { prop: 'hooks.rendererProps' },
|
|
||||||
};
|
|
||||||
jest.spyOn(hooks, hookKeys.renderHooks).mockReturnValueOnce(hookProps);
|
|
||||||
|
|
||||||
renderWithIntl(<FileRenderer {...props} />);
|
|
||||||
|
|
||||||
expect(screen.getByText('filename.txt')).toBeInTheDocument();
|
|
||||||
expect(screen.getByText('Error Message')).toBeInTheDocument();
|
|
||||||
expect(document.querySelector('.alert-heading')).toBeInTheDocument();
|
|
||||||
expect(document.querySelector('.btn.btn-outline-primary')).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders renderer component when not loading and no error', () => {
|
|
||||||
const hookProps = {
|
|
||||||
Renderer: () => <div data-testid="mock-renderer">Renderer Component</div>,
|
|
||||||
isLoading: false,
|
|
||||||
errorStatus: null,
|
|
||||||
error: null,
|
|
||||||
rendererProps: { prop: 'hooks.rendererProps' },
|
|
||||||
};
|
|
||||||
jest.spyOn(hooks, hookKeys.renderHooks).mockReturnValueOnce(hookProps);
|
|
||||||
|
|
||||||
renderWithIntl(<FileRenderer {...props} />);
|
|
||||||
|
|
||||||
expect(screen.getByText('filename.txt')).toBeInTheDocument();
|
|
||||||
expect(screen.getByTestId('mock-renderer')).toBeInTheDocument();
|
|
||||||
expect(screen.getByText('Renderer Component')).toBeInTheDocument();
|
|
||||||
|
|
||||||
const spinner = document.querySelector('.spinner-border');
|
|
||||||
expect(spinner).not.toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`File Preview Card component snapshot 1`] = `
|
||||||
|
<Card
|
||||||
|
className="file-card"
|
||||||
|
key="test-file-name.pdf"
|
||||||
|
>
|
||||||
|
<Collapsible
|
||||||
|
className="file-collapsible"
|
||||||
|
defaultOpen={true}
|
||||||
|
title={
|
||||||
|
<h3
|
||||||
|
className="file-card-title"
|
||||||
|
>
|
||||||
|
test-file-name.pdf
|
||||||
|
</h3>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="preview-panel"
|
||||||
|
>
|
||||||
|
<FileInfo>
|
||||||
|
<FilePopoverContent
|
||||||
|
description="test-file description"
|
||||||
|
downloadUrl="destination/test-file-name.pdf"
|
||||||
|
name="test-file-name.pdf"
|
||||||
|
/>
|
||||||
|
</FileInfo>
|
||||||
|
<h1>
|
||||||
|
some children
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
</Collapsible>
|
||||||
|
</Card>
|
||||||
|
`;
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`File Preview Card component snapshot 1`] = `
|
||||||
|
<OverlayTrigger
|
||||||
|
flip={true}
|
||||||
|
overlay={
|
||||||
|
<Popover
|
||||||
|
className="overlay-help-popover"
|
||||||
|
id="file-popover"
|
||||||
|
>
|
||||||
|
<Popover.Content>
|
||||||
|
<h1>
|
||||||
|
some Children
|
||||||
|
</h1>
|
||||||
|
</Popover.Content>
|
||||||
|
</Popover>
|
||||||
|
}
|
||||||
|
placement="right-end"
|
||||||
|
trigger="focus"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
iconAfter={[MockFunction icons.InfoOutline]}
|
||||||
|
onClick={[MockFunction this.props.onClick]}
|
||||||
|
size="small"
|
||||||
|
variant="tertiary"
|
||||||
|
>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="File info"
|
||||||
|
description="Popover trigger button text for file preview card"
|
||||||
|
id="ora-grading.InfoPopover.fileInfo"
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
</OverlayTrigger>
|
||||||
|
`;
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`FileRenderer component snapshot is not loading, with error 1`] = `
|
||||||
|
<FileCard
|
||||||
|
file={
|
||||||
|
Object {
|
||||||
|
"downloadUrl": "file download url",
|
||||||
|
"name": "filename.txt",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
key="file download url"
|
||||||
|
>
|
||||||
|
<ErrorBanner
|
||||||
|
prop="hooks.errorProps"
|
||||||
|
/>
|
||||||
|
</FileCard>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`FileRenderer component snapshot isLoading, no Error 1`] = `
|
||||||
|
<FileCard
|
||||||
|
file={
|
||||||
|
Object {
|
||||||
|
"downloadUrl": "file download url",
|
||||||
|
"name": "filename.txt",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
key="file download url"
|
||||||
|
>
|
||||||
|
<Renderer
|
||||||
|
prop="hooks.rendererProps"
|
||||||
|
/>
|
||||||
|
</FileCard>
|
||||||
|
`;
|
||||||
@@ -79,7 +79,7 @@ export const renderHooks = ({
|
|||||||
message: messages.retryButton,
|
message: messages.retryButton,
|
||||||
};
|
};
|
||||||
const error = {
|
const error = {
|
||||||
headingMessage: errorMessage,
|
headerMessage: errorMessage,
|
||||||
children: intl.formatMessage(errorMessage),
|
children: intl.formatMessage(errorMessage),
|
||||||
actions: [errorAction],
|
actions: [errorAction],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ describe('FilePreview hooks', () => {
|
|||||||
});
|
});
|
||||||
describe('error', () => {
|
describe('error', () => {
|
||||||
it('loads message from current error status, if valid, else from serverError', () => {
|
it('loads message from current error status, if valid, else from serverError', () => {
|
||||||
expect(hook.error.headingMessage).toEqual(
|
expect(hook.error.headerMessage).toEqual(
|
||||||
hooks.ERROR_STATUSES[ErrorStatuses.serverError],
|
hooks.ERROR_STATUSES[ErrorStatuses.serverError],
|
||||||
);
|
);
|
||||||
expect(hook.error.children).toEqual(
|
expect(hook.error.children).toEqual(
|
||||||
@@ -63,7 +63,7 @@ describe('FilePreview hooks', () => {
|
|||||||
);
|
);
|
||||||
state.mockVal(state.keys.errorStatus, ErrorStatuses.notFound);
|
state.mockVal(state.keys.errorStatus, ErrorStatuses.notFound);
|
||||||
hook = hooks.renderHooks({ intl: { formatMessage }, file });
|
hook = hooks.renderHooks({ intl: { formatMessage }, file });
|
||||||
expect(hook.error.headingMessage).toEqual(
|
expect(hook.error.headerMessage).toEqual(
|
||||||
hooks.ERROR_STATUSES[ErrorStatuses.notFound],
|
hooks.ERROR_STATUSES[ErrorStatuses.notFound],
|
||||||
);
|
);
|
||||||
expect(hook.error.children).toEqual(
|
expect(hook.error.children).toEqual(
|
||||||
|
|||||||
14
src/components/Head/__snapshots__/index.test.jsx.snap
Normal file
14
src/components/Head/__snapshots__/index.test.jsx.snap
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`Head snapshot 1`] = `
|
||||||
|
<Helmet>
|
||||||
|
<title>
|
||||||
|
ORA staff grading | site-name
|
||||||
|
</title>
|
||||||
|
<link
|
||||||
|
href="favicon-url"
|
||||||
|
rel="shortcut icon"
|
||||||
|
type="image/x-icon"
|
||||||
|
/>
|
||||||
|
</Helmet>
|
||||||
|
`;
|
||||||
@@ -1,45 +1,25 @@
|
|||||||
import { render } from '@testing-library/react';
|
import React from 'react';
|
||||||
import { Helmet } from 'react-helmet';
|
import { getConfig } from '@edx/frontend-platform';
|
||||||
|
import { shallow } from 'enzyme';
|
||||||
import Head from '.';
|
import Head from '.';
|
||||||
|
|
||||||
jest.mock('@edx/frontend-platform/i18n', () => ({
|
|
||||||
useIntl: () => ({
|
|
||||||
formatMessage: (message, values) => {
|
|
||||||
if (message.defaultMessage && values) {
|
|
||||||
return message.defaultMessage.replace('{siteName}', values.siteName);
|
|
||||||
}
|
|
||||||
return message.defaultMessage || message.id;
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
defineMessages: (messages) => messages,
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.mock('react-helmet', () => ({
|
jest.mock('react-helmet', () => ({
|
||||||
Helmet: jest.fn(),
|
Helmet: 'Helmet',
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Helmet.mockImplementation(({ children }) => <div data-testid="helmet-mock">{children}</div>);
|
|
||||||
|
|
||||||
jest.mock('@edx/frontend-platform', () => ({
|
jest.mock('@edx/frontend-platform', () => ({
|
||||||
getConfig: jest.fn().mockReturnValue({
|
getConfig: () => ({
|
||||||
SITE_NAME: 'site-name',
|
SITE_NAME: 'site-name',
|
||||||
FAVICON_URL: 'favicon-url',
|
FAVICON_URL: 'favicon-url',
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('Head', () => {
|
describe('Head', () => {
|
||||||
it('should render page title with site name from config', () => {
|
it('snapshot', () => {
|
||||||
const { container } = render(<Head />);
|
const el = shallow(<Head />);
|
||||||
const titleElement = container.querySelector('title');
|
expect(el).toMatchSnapshot();
|
||||||
expect(titleElement).toBeInTheDocument();
|
|
||||||
expect(titleElement.textContent).toContain('ORA staff grading | site-name');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should render favicon link with URL from config', () => {
|
expect(el.find('title').text()).toContain(getConfig().SITE_NAME);
|
||||||
const { container } = render(<Head />);
|
expect(el.find('link').prop('href')).toEqual(getConfig().FAVICON_URL);
|
||||||
const faviconLink = container.querySelector('link[rel="shortcut icon"]');
|
|
||||||
expect(faviconLink).toBeInTheDocument();
|
|
||||||
expect(faviconLink.getAttribute('href')).toEqual('favicon-url');
|
|
||||||
expect(faviconLink.getAttribute('type')).toEqual('image/x-icon');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
29
src/components/InfoPopover/__snapshots__/index.test.jsx.snap
Normal file
29
src/components/InfoPopover/__snapshots__/index.test.jsx.snap
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`Info Popover Component snapshot 1`] = `
|
||||||
|
<OverlayTrigger
|
||||||
|
flip={true}
|
||||||
|
overlay={
|
||||||
|
<Popover
|
||||||
|
className="overlay-help-popover"
|
||||||
|
id="info-popover"
|
||||||
|
>
|
||||||
|
<Popover.Content>
|
||||||
|
<div>
|
||||||
|
Children component
|
||||||
|
</div>
|
||||||
|
</Popover.Content>
|
||||||
|
</Popover>
|
||||||
|
}
|
||||||
|
placement="right-end"
|
||||||
|
trigger="focus"
|
||||||
|
>
|
||||||
|
<IconButton
|
||||||
|
alt="Display more info"
|
||||||
|
className="esg-help-icon"
|
||||||
|
iconAs="Icon"
|
||||||
|
onClick={[MockFunction this.props.onClick]}
|
||||||
|
src={[MockFunction icons.InfoOutline]}
|
||||||
|
/>
|
||||||
|
</OverlayTrigger>
|
||||||
|
`;
|
||||||
@@ -6,9 +6,9 @@ import {
|
|||||||
Popover,
|
Popover,
|
||||||
Icon,
|
Icon,
|
||||||
IconButton,
|
IconButton,
|
||||||
} from '@openedx/paragon';
|
} from '@edx/paragon';
|
||||||
import { InfoOutline } from '@openedx/paragon/icons';
|
import { InfoOutline } from '@edx/paragon/icons';
|
||||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||||
|
|
||||||
import { nullMethod } from 'hooks';
|
import { nullMethod } from 'hooks';
|
||||||
|
|
||||||
@@ -17,35 +17,26 @@ import messages from './messages';
|
|||||||
/**
|
/**
|
||||||
* <InfoPopover />
|
* <InfoPopover />
|
||||||
*/
|
*/
|
||||||
export const InfoPopover = (
|
export const InfoPopover = ({ onClick, children, intl }) => (
|
||||||
{
|
<OverlayTrigger
|
||||||
onClick,
|
trigger="focus"
|
||||||
children,
|
placement="right-end"
|
||||||
},
|
flip
|
||||||
) => {
|
overlay={(
|
||||||
const intl = useIntl();
|
<Popover id="info-popover" className="overlay-help-popover">
|
||||||
return (
|
<Popover.Content>{children}</Popover.Content>
|
||||||
<OverlayTrigger
|
</Popover>
|
||||||
trigger="focus"
|
)}
|
||||||
placement="left-end"
|
>
|
||||||
flip
|
<IconButton
|
||||||
overlay={(
|
className="esg-help-icon"
|
||||||
<Popover id="info-popover" className="overlay-help-popover">
|
src={InfoOutline}
|
||||||
<Popover.Content>{children}</Popover.Content>
|
alt={intl.formatMessage(messages.altText)}
|
||||||
</Popover>
|
iconAs={Icon}
|
||||||
)}
|
onClick={onClick}
|
||||||
>
|
/>
|
||||||
<IconButton
|
</OverlayTrigger>
|
||||||
className="esg-help-icon"
|
);
|
||||||
data-testid="esg-help-icon"
|
|
||||||
src={InfoOutline}
|
|
||||||
alt={intl.formatMessage(messages.altText)}
|
|
||||||
iconAs={Icon}
|
|
||||||
onClick={onClick}
|
|
||||||
/>
|
|
||||||
</OverlayTrigger>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
InfoPopover.defaultProps = {
|
InfoPopover.defaultProps = {
|
||||||
onClick: nullMethod,
|
onClick: nullMethod,
|
||||||
@@ -56,6 +47,7 @@ InfoPopover.propTypes = {
|
|||||||
PropTypes.arrayOf(PropTypes.node),
|
PropTypes.arrayOf(PropTypes.node),
|
||||||
PropTypes.node,
|
PropTypes.node,
|
||||||
]).isRequired,
|
]).isRequired,
|
||||||
|
intl: intlShape.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default InfoPopover;
|
export default injectIntl(InfoPopover);
|
||||||
|
|||||||
@@ -1,31 +1,23 @@
|
|||||||
import { screen } from '@testing-library/react';
|
import React from 'react';
|
||||||
import userEvent from '@testing-library/user-event';
|
import { shallow } from 'enzyme';
|
||||||
import { renderWithIntl } from '../../testUtils';
|
|
||||||
|
import { formatMessage } from 'testUtils';
|
||||||
import { InfoPopover } from '.';
|
import { InfoPopover } from '.';
|
||||||
|
|
||||||
describe('Info Popover Component', () => {
|
describe('Info Popover Component', () => {
|
||||||
const child = <div>Children component</div>;
|
const child = <div>Children component</div>;
|
||||||
const onClick = jest.fn().mockName('this.props.onClick');
|
const onClick = jest.fn().mockName('this.props.onClick');
|
||||||
|
let el;
|
||||||
|
beforeEach(() => {
|
||||||
|
el = shallow(<InfoPopover onClick={onClick} intl={{ formatMessage }}>{child}</InfoPopover>);
|
||||||
|
});
|
||||||
|
test('snapshot', () => {
|
||||||
|
expect(el).toMatchSnapshot();
|
||||||
|
});
|
||||||
describe('Component', () => {
|
describe('Component', () => {
|
||||||
it('renders the help icon button', () => {
|
test('Test component render', () => {
|
||||||
renderWithIntl(
|
expect(el.length).toEqual(1);
|
||||||
<InfoPopover onClick={onClick}>
|
expect(el.find('.esg-help-icon').length).toEqual(1);
|
||||||
{child}
|
|
||||||
</InfoPopover>,
|
|
||||||
);
|
|
||||||
expect(screen.getByTestId('esg-help-icon')).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calls onClick when the help icon is clicked', async () => {
|
|
||||||
renderWithIntl(
|
|
||||||
<InfoPopover onClick={onClick}>
|
|
||||||
{child}
|
|
||||||
</InfoPopover>,
|
|
||||||
);
|
|
||||||
const user = userEvent.setup();
|
|
||||||
await user.click(screen.getByTestId('esg-help-icon'));
|
|
||||||
expect(onClick).toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import { Spinner } from '@openedx/paragon';
|
import { Spinner } from '@edx/paragon';
|
||||||
import { FormattedMessage } from '@edx/frontend-platform/i18n';
|
import { FormattedMessage } from '@edx/frontend-platform/i18n';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import { Badge } from '@openedx/paragon';
|
import { Badge } from '@edx/paragon';
|
||||||
import { FormattedMessage } from '@edx/frontend-platform/i18n';
|
import { FormattedMessage } from '@edx/frontend-platform/i18n';
|
||||||
|
|
||||||
import { StrictDict } from 'utils';
|
import { StrictDict } from 'utils';
|
||||||
|
|||||||
@@ -1,36 +1,34 @@
|
|||||||
import { screen } from '@testing-library/react';
|
import React from 'react';
|
||||||
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import { gradingStatuses } from 'data/services/lms/constants';
|
import { gradingStatuses } from 'data/services/lms/constants';
|
||||||
import messages from '../data/services/lms/messages';
|
|
||||||
import { renderWithIntl } from '../testUtils';
|
|
||||||
import { StatusBadge } from './StatusBadge';
|
import { StatusBadge } from './StatusBadge';
|
||||||
|
|
||||||
const className = 'test-className';
|
const className = 'test-className';
|
||||||
describe('StatusBadge component', () => {
|
describe('StatusBadge component', () => {
|
||||||
|
const render = (status) => shallow(<StatusBadge className={className} status={status} />);
|
||||||
describe('behavior', () => {
|
describe('behavior', () => {
|
||||||
it('does not render if status does not have configured variant', () => {
|
it('does not render if status does not have configured variant', () => {
|
||||||
const { container } = renderWithIntl(<StatusBadge className={className} status="arbitrary" />);
|
const el = render('arbitrary');
|
||||||
expect(container.firstChild).toBeNull();
|
expect(el).toMatchSnapshot();
|
||||||
|
expect(el.isEmptyRender()).toEqual(true);
|
||||||
});
|
});
|
||||||
describe('status rendering: loads badge with configured variant and message', () => {
|
describe('status snapshots: loads badge with configured variant and message.', () => {
|
||||||
it('`ungraded` shows primary button variant and message', () => {
|
test('`ungraded` shows primary button variant and message', () => {
|
||||||
renderWithIntl(<StatusBadge className={className} status={gradingStatuses.ungraded} />);
|
const el = render(gradingStatuses.ungraded);
|
||||||
const badge = screen.getByText(messages.ungraded.defaultMessage);
|
expect(el).toMatchSnapshot();
|
||||||
expect(badge).toHaveClass('badge-primary');
|
|
||||||
});
|
});
|
||||||
it('`locked` shows light button variant and message', () => {
|
test('`locked` shows light button variant and message', () => {
|
||||||
renderWithIntl(<StatusBadge className={className} status={gradingStatuses.locked} />);
|
const el = render(gradingStatuses.locked);
|
||||||
const badge = screen.getByText(messages.locked.defaultMessage);
|
expect(el).toMatchSnapshot();
|
||||||
expect(badge).toHaveClass('badge-light');
|
|
||||||
});
|
});
|
||||||
it('`graded` shows success button variant and message', () => {
|
test('`graded` shows success button variant and message', () => {
|
||||||
renderWithIntl(<StatusBadge className={className} status={gradingStatuses.graded} />);
|
const el = render(gradingStatuses.graded);
|
||||||
const badge = screen.getByText(messages.graded.defaultMessage);
|
expect(el).toMatchSnapshot();
|
||||||
expect(badge).toHaveClass('badge-success');
|
|
||||||
});
|
});
|
||||||
it('`inProgress` shows warning button variant and message', () => {
|
test('`inProgress` shows warning button variant and message', () => {
|
||||||
renderWithIntl(<StatusBadge className={className} status={gradingStatuses.inProgress} />);
|
const el = render(gradingStatuses.inProgress);
|
||||||
const badge = screen.getByText(messages['in-progress'].defaultMessage);
|
expect(el).toMatchSnapshot();
|
||||||
expect(badge).toHaveClass('badge-warning');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
59
src/components/__snapshots__/ConfirmModal.test.jsx.snap
Normal file
59
src/components/__snapshots__/ConfirmModal.test.jsx.snap
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`ConfirmModal snapshot: closed 1`] = `
|
||||||
|
<AlertModal
|
||||||
|
className="confirm-modal"
|
||||||
|
footerNode={
|
||||||
|
<ActionRow>
|
||||||
|
<Button
|
||||||
|
onClick={[MockFunction this.props.onCancel]}
|
||||||
|
variant="tertiary"
|
||||||
|
>
|
||||||
|
test-cancel-text
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={[MockFunction this.props.onConfirm]}
|
||||||
|
variant="primary"
|
||||||
|
>
|
||||||
|
test-confirm-text
|
||||||
|
</Button>
|
||||||
|
</ActionRow>
|
||||||
|
}
|
||||||
|
isOpen={false}
|
||||||
|
onClose={[MockFunction hooks.nullMethod]}
|
||||||
|
title="test-title"
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
test-content
|
||||||
|
</p>
|
||||||
|
</AlertModal>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`ConfirmModal snapshot: open 1`] = `
|
||||||
|
<AlertModal
|
||||||
|
className="confirm-modal"
|
||||||
|
footerNode={
|
||||||
|
<ActionRow>
|
||||||
|
<Button
|
||||||
|
onClick={[MockFunction this.props.onCancel]}
|
||||||
|
variant="tertiary"
|
||||||
|
>
|
||||||
|
test-cancel-text
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={[MockFunction this.props.onConfirm]}
|
||||||
|
variant="primary"
|
||||||
|
>
|
||||||
|
test-confirm-text
|
||||||
|
</Button>
|
||||||
|
</ActionRow>
|
||||||
|
}
|
||||||
|
isOpen={true}
|
||||||
|
onClose={[MockFunction hooks.nullMethod]}
|
||||||
|
title="test-title"
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
test-content
|
||||||
|
</p>
|
||||||
|
</AlertModal>
|
||||||
|
`;
|
||||||
55
src/components/__snapshots__/StatusBadge.test.jsx.snap
Normal file
55
src/components/__snapshots__/StatusBadge.test.jsx.snap
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`StatusBadge component behavior does not render if status does not have configured variant 1`] = `""`;
|
||||||
|
|
||||||
|
exports[`StatusBadge component behavior status snapshots: loads badge with configured variant and message. \`graded\` shows success button variant and message 1`] = `
|
||||||
|
<Badge
|
||||||
|
className="test-className"
|
||||||
|
variant="success"
|
||||||
|
>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="Grading Completed"
|
||||||
|
description="Grading status label for graded submission"
|
||||||
|
id="ora-grading.lms-api.gradingStatusDisplay.graded"
|
||||||
|
/>
|
||||||
|
</Badge>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`StatusBadge component behavior status snapshots: loads badge with configured variant and message. \`inProgress\` shows warning button variant and message 1`] = `
|
||||||
|
<Badge
|
||||||
|
className="test-className"
|
||||||
|
variant="warning"
|
||||||
|
>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="You are currently grading this response"
|
||||||
|
description="Grading status label for in-progress submission"
|
||||||
|
id="ora-grading.lms-api.gradingStatusDisplay.inProgress"
|
||||||
|
/>
|
||||||
|
</Badge>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`StatusBadge component behavior status snapshots: loads badge with configured variant and message. \`locked\` shows light button variant and message 1`] = `
|
||||||
|
<Badge
|
||||||
|
className="test-className"
|
||||||
|
variant="light"
|
||||||
|
>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="Currently being graded by someone else"
|
||||||
|
description="Grading status label for locked submission"
|
||||||
|
id="ora-grading.lms-api.gradingStatusDisplay.locked"
|
||||||
|
/>
|
||||||
|
</Badge>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`StatusBadge component behavior status snapshots: loads badge with configured variant and message. \`ungraded\` shows primary button variant and message 1`] = `
|
||||||
|
<Badge
|
||||||
|
className="test-className"
|
||||||
|
variant="primary"
|
||||||
|
>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="Ungraded"
|
||||||
|
description="Grading status label for ungraded submission"
|
||||||
|
id="ora-grading.lms-api.gradingStatusDisplay.ungraded"
|
||||||
|
/>
|
||||||
|
</Badge>
|
||||||
|
`;
|
||||||
11
src/containers/CTA/CTA.test.jsx
Normal file
11
src/containers/CTA/CTA.test.jsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
|
import { CTA } from '.';
|
||||||
|
|
||||||
|
describe('CTA component', () => {
|
||||||
|
test('snapshots', () => {
|
||||||
|
const el = shallow(<CTA hide />);
|
||||||
|
expect(el).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
});
|
||||||
31
src/containers/CTA/__snapshots__/CTA.test.jsx.snap
Normal file
31
src/containers/CTA/__snapshots__/CTA.test.jsx.snap
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`CTA component snapshots 1`] = `
|
||||||
|
<PageBanner>
|
||||||
|
<span>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="Thanks for using the new ORA staff grading experience. "
|
||||||
|
description="Thank user for using ora and ask for feed back"
|
||||||
|
id="ora-grading.CTA.feedbackMessage"
|
||||||
|
/>
|
||||||
|
<Hyperlink
|
||||||
|
destination="https://docs.google.com/forms/d/1Hu1rgJcCHl5_EtDb5Up3hiZ40sSUtkZQfRHJ3fWOvfQ/edit"
|
||||||
|
isInline={true}
|
||||||
|
showLaunchIcon={false}
|
||||||
|
target="_blank"
|
||||||
|
variant="muted"
|
||||||
|
>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="Provide some feedback"
|
||||||
|
description="placeholder for the feedback anchor link"
|
||||||
|
id="ora-grading.CTA.linkMessage"
|
||||||
|
/>
|
||||||
|
</Hyperlink>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage=" and let us know what you think!"
|
||||||
|
description="inform user to provide feedback"
|
||||||
|
id="ora-grading.CTA.letUsKnowMessage"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</PageBanner>
|
||||||
|
`;
|
||||||
29
src/containers/CTA/index.jsx
Normal file
29
src/containers/CTA/index.jsx
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { FormattedMessage } from '@edx/frontend-platform/i18n';
|
||||||
|
import { PageBanner, Hyperlink } from '@edx/paragon';
|
||||||
|
|
||||||
|
import messages from './messages';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <CTA />
|
||||||
|
*/
|
||||||
|
export const CTA = () => (
|
||||||
|
<PageBanner>
|
||||||
|
<span>
|
||||||
|
<FormattedMessage {...messages.ctaFeedbackMessage} />
|
||||||
|
<Hyperlink
|
||||||
|
isInline
|
||||||
|
variant="muted"
|
||||||
|
destination="https://docs.google.com/forms/d/1Hu1rgJcCHl5_EtDb5Up3hiZ40sSUtkZQfRHJ3fWOvfQ/edit"
|
||||||
|
target="_blank"
|
||||||
|
showLaunchIcon={false}
|
||||||
|
>
|
||||||
|
<FormattedMessage {...messages.ctaLinkMessage} />
|
||||||
|
</Hyperlink>
|
||||||
|
<FormattedMessage {...messages.ctaLetUsKnowMessage} />
|
||||||
|
</span>
|
||||||
|
</PageBanner>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default CTA;
|
||||||
23
src/containers/CTA/messages.js
Normal file
23
src/containers/CTA/messages.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* eslint-disable quotes */
|
||||||
|
import { defineMessages } from '@edx/frontend-platform/i18n';
|
||||||
|
import { StrictDict } from 'utils';
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
ctaFeedbackMessage: {
|
||||||
|
id: 'ora-grading.CTA.feedbackMessage',
|
||||||
|
defaultMessage: 'Thanks for using the new ORA staff grading experience. ',
|
||||||
|
description: 'Thank user for using ora and ask for feed back',
|
||||||
|
},
|
||||||
|
ctaLinkMessage: {
|
||||||
|
id: 'ora-grading.CTA.linkMessage',
|
||||||
|
defaultMessage: 'Provide some feedback',
|
||||||
|
description: 'placeholder for the feedback anchor link',
|
||||||
|
},
|
||||||
|
ctaLetUsKnowMessage: {
|
||||||
|
id: 'ora-grading.CTA.letUsKnowMessage',
|
||||||
|
defaultMessage: ' and let us know what you think!',
|
||||||
|
description: 'inform user to provide feedback',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default StrictDict(messages);
|
||||||
@@ -2,8 +2,8 @@ import React from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
import { Form } from '@openedx/paragon';
|
import { Form } from '@edx/paragon';
|
||||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||||
|
|
||||||
import { feedbackRequirement } from 'data/services/lms/constants';
|
import { feedbackRequirement } from 'data/services/lms/constants';
|
||||||
import { actions, selectors } from 'data/redux';
|
import { actions, selectors } from 'data/redux';
|
||||||
@@ -12,56 +12,59 @@ import messages from './messages';
|
|||||||
/**
|
/**
|
||||||
* <CriterionFeedback />
|
* <CriterionFeedback />
|
||||||
*/
|
*/
|
||||||
export const CriterionFeedback = ({
|
export class CriterionFeedback extends React.Component {
|
||||||
orderNum,
|
constructor(props) {
|
||||||
isGrading,
|
super(props);
|
||||||
config,
|
this.onChange = this.onChange.bind(this);
|
||||||
setValue,
|
|
||||||
value,
|
|
||||||
isInvalid,
|
|
||||||
}) => {
|
|
||||||
const intl = useIntl();
|
|
||||||
|
|
||||||
const onChange = (event) => {
|
|
||||||
setValue({
|
|
||||||
value: event.target.value,
|
|
||||||
orderNum,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const translate = (msg) => intl.formatMessage(msg);
|
|
||||||
|
|
||||||
const getCommentMessage = () => {
|
|
||||||
let commentMessage = translate(isGrading ? messages.addComments : messages.comments);
|
|
||||||
if (config === feedbackRequirement.optional) {
|
|
||||||
commentMessage += ` ${translate(messages.optional)}`;
|
|
||||||
}
|
|
||||||
return commentMessage;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (config === feedbackRequirement.disabled) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
onChange(event) {
|
||||||
<Form.Group isInvalid={isInvalid}>
|
this.props.setValue({
|
||||||
<Form.Control
|
value: event.target.value,
|
||||||
as="textarea"
|
orderNum: this.props.orderNum,
|
||||||
className="criterion-feedback feedback-input"
|
});
|
||||||
data-testid="criterion-feedback-input"
|
}
|
||||||
floatingLabel={getCommentMessage()}
|
|
||||||
value={value}
|
get commentMessage() {
|
||||||
onChange={onChange}
|
const { config, isGrading } = this.props;
|
||||||
disabled={!isGrading}
|
let commentMessage = this.translate(isGrading ? messages.addComments : messages.comments);
|
||||||
/>
|
if (config === feedbackRequirement.optional) {
|
||||||
{isInvalid && (
|
commentMessage += ` ${this.translate(messages.optional)}`;
|
||||||
<Form.Control.Feedback type="invalid" className="feedback-error-msg" data-testid="criterion-feedback-error-msg">
|
}
|
||||||
{translate(messages.criterionFeedbackError)}
|
return commentMessage;
|
||||||
</Form.Control.Feedback>
|
}
|
||||||
)}
|
|
||||||
</Form.Group>
|
translate = (msg) => this.props.intl.formatMessage(msg);
|
||||||
);
|
|
||||||
};
|
render() {
|
||||||
|
const {
|
||||||
|
config,
|
||||||
|
isGrading,
|
||||||
|
value,
|
||||||
|
isInvalid,
|
||||||
|
} = this.props;
|
||||||
|
if (config === feedbackRequirement.disabled) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Form.Group isInvalid={this.feedbackIsInvalid}>
|
||||||
|
<Form.Control
|
||||||
|
as="textarea"
|
||||||
|
className="criterion-feedback feedback-input"
|
||||||
|
floatingLabel={this.commentMessage}
|
||||||
|
value={value}
|
||||||
|
onChange={this.onChange}
|
||||||
|
disabled={!isGrading}
|
||||||
|
/>
|
||||||
|
{isInvalid && (
|
||||||
|
<Form.Control.Feedback type="invalid" className="feedback-error-msg">
|
||||||
|
{this.translate(messages.criterionFeedbackError)}
|
||||||
|
</Form.Control.Feedback>
|
||||||
|
)}
|
||||||
|
</Form.Group>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CriterionFeedback.defaultProps = {
|
CriterionFeedback.defaultProps = {
|
||||||
value: '',
|
value: '',
|
||||||
@@ -70,6 +73,8 @@ CriterionFeedback.defaultProps = {
|
|||||||
CriterionFeedback.propTypes = {
|
CriterionFeedback.propTypes = {
|
||||||
orderNum: PropTypes.number.isRequired,
|
orderNum: PropTypes.number.isRequired,
|
||||||
isGrading: PropTypes.bool.isRequired,
|
isGrading: PropTypes.bool.isRequired,
|
||||||
|
// injected
|
||||||
|
intl: intlShape.isRequired,
|
||||||
// redux
|
// redux
|
||||||
config: PropTypes.string.isRequired,
|
config: PropTypes.string.isRequired,
|
||||||
setValue: PropTypes.func.isRequired,
|
setValue: PropTypes.func.isRequired,
|
||||||
@@ -87,4 +92,6 @@ export const mapDispatchToProps = {
|
|||||||
setValue: actions.grading.setCriterionFeedback,
|
setValue: actions.grading.setCriterionFeedback,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(CriterionFeedback);
|
export default injectIntl(
|
||||||
|
connect(mapStateToProps, mapDispatchToProps)(CriterionFeedback),
|
||||||
|
);
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { screen } from '@testing-library/react';
|
import { shallow } from 'enzyme';
|
||||||
import userEvent from '@testing-library/user-event';
|
|
||||||
|
|
||||||
import { actions, selectors } from 'data/redux';
|
import { actions, selectors } from 'data/redux';
|
||||||
import {
|
import {
|
||||||
feedbackRequirement,
|
feedbackRequirement,
|
||||||
gradeStatuses,
|
gradeStatuses,
|
||||||
} from 'data/services/lms/constants';
|
} from 'data/services/lms/constants';
|
||||||
|
import { formatMessage } from 'testUtils';
|
||||||
import {
|
import {
|
||||||
CriterionFeedback,
|
CriterionFeedback,
|
||||||
mapStateToProps,
|
mapStateToProps,
|
||||||
mapDispatchToProps,
|
mapDispatchToProps,
|
||||||
} from './CriterionFeedback';
|
} from './CriterionFeedback';
|
||||||
import { renderWithIntl } from '../../testUtils';
|
import messages from './messages';
|
||||||
|
|
||||||
jest.mock('data/redux/app/selectors', () => ({
|
jest.mock('data/redux/app/selectors', () => ({
|
||||||
rubric: {
|
rubric: {
|
||||||
@@ -36,6 +36,7 @@ jest.mock('data/redux/grading/selectors', () => ({
|
|||||||
|
|
||||||
describe('Criterion Feedback', () => {
|
describe('Criterion Feedback', () => {
|
||||||
const props = {
|
const props = {
|
||||||
|
intl: { formatMessage },
|
||||||
orderNum: 1,
|
orderNum: 1,
|
||||||
config: 'config string',
|
config: 'config string',
|
||||||
isGrading: true,
|
isGrading: true,
|
||||||
@@ -44,72 +45,141 @@ describe('Criterion Feedback', () => {
|
|||||||
setValue: jest.fn().mockName('this.props.setValue'),
|
setValue: jest.fn().mockName('this.props.setValue'),
|
||||||
isInvalid: false,
|
isInvalid: false,
|
||||||
};
|
};
|
||||||
|
let el;
|
||||||
|
beforeEach(() => {
|
||||||
|
el = shallow(<CriterionFeedback {...props} />);
|
||||||
|
el.instance().onChange = jest.fn().mockName('this.onChange');
|
||||||
|
});
|
||||||
|
describe('snapshot', () => {
|
||||||
|
test('is grading', () => {
|
||||||
|
expect(el.instance().render()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('is graded', () => {
|
||||||
|
el.setProps({
|
||||||
|
isGrading: false,
|
||||||
|
gradeStatus: gradeStatuses.graded,
|
||||||
|
});
|
||||||
|
expect(el.instance().render()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('feedback value is invalid', () => {
|
||||||
|
el.setProps({
|
||||||
|
isInvalid: true,
|
||||||
|
});
|
||||||
|
expect(el.instance().render()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.values(feedbackRequirement).forEach((requirement) => {
|
||||||
|
test(`feedback is configured to ${requirement}`, () => {
|
||||||
|
el.setProps({
|
||||||
|
config: requirement,
|
||||||
|
});
|
||||||
|
expect(el.instance().render()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('component', () => {
|
describe('component', () => {
|
||||||
describe('render', () => {
|
describe('render', () => {
|
||||||
it('shows a non-disabled input when grading', () => {
|
test('is grading (the feedback input is not disabled)', () => {
|
||||||
renderWithIntl(<CriterionFeedback {...props} />);
|
expect(el.isEmptyRender()).toEqual(false);
|
||||||
const input = screen.getByTestId('criterion-feedback-input');
|
expect(el.instance().props.value).toEqual(props.value);
|
||||||
expect(input).toBeInTheDocument();
|
const controlEl = el.find('.feedback-input');
|
||||||
expect(input).not.toBeDisabled();
|
expect(controlEl.prop('disabled')).toEqual(false);
|
||||||
expect(input).toHaveValue(props.value);
|
expect(controlEl.prop('value')).toEqual(props.value);
|
||||||
});
|
});
|
||||||
|
test('is graded (the input is disabled)', () => {
|
||||||
it('shows a disabled input when not grading', () => {
|
el.setProps({
|
||||||
renderWithIntl(
|
isGrading: false,
|
||||||
<CriterionFeedback {...props} isGrading={false} gradeStatus={gradeStatuses.graded} />,
|
gradeStatus: gradeStatuses.graded,
|
||||||
);
|
});
|
||||||
const input = screen.getByTestId('criterion-feedback-input');
|
expect(el.instance().props.value).toEqual(props.value);
|
||||||
expect(input).toBeInTheDocument();
|
const controlEl = el.find('.feedback-input');
|
||||||
expect(input).toBeDisabled();
|
expect(controlEl.prop('disabled')).toEqual(true);
|
||||||
expect(input).toHaveValue(props.value);
|
expect(controlEl.prop('value')).toEqual(props.value);
|
||||||
});
|
});
|
||||||
|
test('is having invalid feedback (feedback get render)', () => {
|
||||||
it('displays an error message when feedback is invalid', () => {
|
el.setProps({
|
||||||
renderWithIntl(<CriterionFeedback {...props} isInvalid />);
|
isInvalid: true,
|
||||||
expect(screen.getByTestId('criterion-feedback-error-msg')).toBeInTheDocument();
|
});
|
||||||
|
const feedbackErrorEl = el.find('.feedback-error-msg');
|
||||||
|
expect(el.instance().props.isInvalid).toEqual(true);
|
||||||
|
expect(feedbackErrorEl).toBeDefined();
|
||||||
});
|
});
|
||||||
|
test('is configure to disabled (the input does not get render)', () => {
|
||||||
it('does not render anything when config is set to disabled', () => {
|
el.setProps({
|
||||||
const { container } = renderWithIntl(
|
config: feedbackRequirement.disabled,
|
||||||
<CriterionFeedback {...props} config={feedbackRequirement.disabled} />,
|
});
|
||||||
);
|
expect(el.isEmptyRender()).toEqual(true);
|
||||||
expect(container.firstChild).toBeNull();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('behavior', () => {
|
describe('behavior', () => {
|
||||||
it('calls setValue when input value changes', async () => {
|
test('onChange call set value', () => {
|
||||||
renderWithIntl(<CriterionFeedback {...props} />);
|
el = shallow(<CriterionFeedback {...props} />);
|
||||||
const user = userEvent.setup();
|
el.instance().onChange({
|
||||||
const input = screen.getByTestId('criterion-feedback-input');
|
target: {
|
||||||
await user.clear(input);
|
value: 'some value',
|
||||||
expect(props.setValue).toHaveBeenCalledWith({
|
},
|
||||||
value: '',
|
|
||||||
orderNum: props.orderNum,
|
|
||||||
});
|
});
|
||||||
|
expect(props.setValue).toBeCalledTimes(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getter commentMessage', () => {
|
||||||
|
test('is grading', () => {
|
||||||
|
el.setProps({ config: feedbackRequirement.optional, isGrading: true });
|
||||||
|
expect(el.instance().commentMessage).toContain(
|
||||||
|
messages.optional.defaultMessage,
|
||||||
|
);
|
||||||
|
|
||||||
|
el.setProps({ config: feedbackRequirement.required });
|
||||||
|
expect(el.instance().commentMessage).not.toContain(
|
||||||
|
messages.optional.defaultMessage,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(el.instance().commentMessage).toContain(
|
||||||
|
messages.addComments.defaultMessage,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('is not grading', () => {
|
||||||
|
el.setProps({ config: feedbackRequirement.optional, isGrading: false });
|
||||||
|
expect(el.instance().commentMessage).toContain(
|
||||||
|
messages.optional.defaultMessage,
|
||||||
|
);
|
||||||
|
|
||||||
|
el.setProps({ config: feedbackRequirement.required });
|
||||||
|
expect(el.instance().commentMessage).not.toContain(
|
||||||
|
messages.optional.defaultMessage,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(el.instance().commentMessage).toContain(
|
||||||
|
messages.comments.defaultMessage,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('mapStateToProps', () => {
|
describe('mapStateToProps', () => {
|
||||||
const testState = { arbitraryState: 'some data' };
|
const testState = { abitaryState: 'some data' };
|
||||||
const ownProps = { orderNum: props.orderNum };
|
const ownProps = { orderNum: props.orderNum };
|
||||||
let mapped;
|
let mapped;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mapped = mapStateToProps(testState, ownProps);
|
mapped = mapStateToProps(testState, ownProps);
|
||||||
});
|
});
|
||||||
it('gets config from selectors.app.rubric.criterionFeedbackConfig', () => {
|
test('selectors.app.rubric.criterionFeedbackConfig', () => {
|
||||||
expect(mapped.config).toEqual(
|
expect(mapped.config).toEqual(
|
||||||
selectors.app.rubric.criterionFeedbackConfig(testState, ownProps),
|
selectors.app.rubric.criterionFeedbackConfig(testState, ownProps),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('gets value from selectors.grading.selected.criterionFeedback', () => {
|
test('selector.grading.selected.criterionFeedback', () => {
|
||||||
expect(mapped.value).toEqual(
|
expect(mapped.value).toEqual(
|
||||||
selectors.grading.selected.criterionFeedback(testState, ownProps),
|
selectors.grading.selected.criterionFeedback(testState, ownProps),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('gets isInvalid from selectors.grading.validation.criterionFeedbackIsInvalid', () => {
|
test('selector.grading.validation.criterionFeedbackIsInvalid', () => {
|
||||||
expect(mapped.isInvalid).toEqual(
|
expect(mapped.isInvalid).toEqual(
|
||||||
selectors.grading.validation.criterionFeedbackIsInvalid(
|
selectors.grading.validation.criterionFeedbackIsInvalid(
|
||||||
testState,
|
testState,
|
||||||
@@ -120,7 +190,7 @@ describe('Criterion Feedback', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('mapDispatchToProps', () => {
|
describe('mapDispatchToProps', () => {
|
||||||
it('maps actions.grading.setCriterionFeedback to setValue prop', () => {
|
test('maps actions.grading.setCriterionFeedback to setValue prop', () => {
|
||||||
expect(mapDispatchToProps.setValue).toEqual(
|
expect(mapDispatchToProps.setValue).toEqual(
|
||||||
actions.grading.setCriterionFeedback,
|
actions.grading.setCriterionFeedback,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import React from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
import { Form } from '@openedx/paragon';
|
import { Form } from '@edx/paragon';
|
||||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||||
|
|
||||||
import { actions, selectors } from 'data/redux';
|
import { actions, selectors } from 'data/redux';
|
||||||
import messages from './messages';
|
import messages from './messages';
|
||||||
@@ -11,46 +11,50 @@ import messages from './messages';
|
|||||||
/**
|
/**
|
||||||
* <RadioCriterion />
|
* <RadioCriterion />
|
||||||
*/
|
*/
|
||||||
export const RadioCriterion = ({
|
export class RadioCriterion extends React.Component {
|
||||||
orderNum,
|
constructor(props) {
|
||||||
isGrading,
|
super(props);
|
||||||
config,
|
this.onChange = this.onChange.bind(this);
|
||||||
data,
|
}
|
||||||
setCriterionOption,
|
|
||||||
isInvalid,
|
|
||||||
}) => {
|
|
||||||
const intl = useIntl();
|
|
||||||
|
|
||||||
const onChange = (event) => {
|
onChange(event) {
|
||||||
setCriterionOption({
|
this.props.setCriterionOption({
|
||||||
orderNum,
|
orderNum: this.props.orderNum,
|
||||||
value: event.target.value,
|
value: event.target.value,
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
return (
|
render() {
|
||||||
<Form.RadioSet name={config.name} value={data}>
|
const {
|
||||||
{config.options.map((option) => (
|
config,
|
||||||
<Form.Radio
|
data,
|
||||||
className="criteria-option align-items-center"
|
intl,
|
||||||
key={option.name}
|
isGrading,
|
||||||
value={option.name}
|
isInvalid,
|
||||||
description={intl.formatMessage(messages.optionPoints, { points: option.points })}
|
} = this.props;
|
||||||
onChange={onChange}
|
return (
|
||||||
disabled={!isGrading}
|
<Form.RadioSet name={config.name} value={data}>
|
||||||
style={{ flexShrink: 0 }}
|
{config.options.map((option) => (
|
||||||
>
|
<Form.Radio
|
||||||
{option.label}
|
className="criteria-option"
|
||||||
</Form.Radio>
|
key={option.name}
|
||||||
))}
|
value={option.name}
|
||||||
{isInvalid && (
|
description={intl.formatMessage(messages.optionPoints, { points: option.points })}
|
||||||
<Form.Control.Feedback type="invalid" className="feedback-error-msg">
|
onChange={this.onChange}
|
||||||
{intl.formatMessage(messages.rubricSelectedError)}
|
disabled={!isGrading}
|
||||||
</Form.Control.Feedback>
|
>
|
||||||
)}
|
{option.label}
|
||||||
</Form.RadioSet>
|
</Form.Radio>
|
||||||
);
|
))}
|
||||||
};
|
{isInvalid && (
|
||||||
|
<Form.Control.Feedback type="invalid" className="feedback-error-msg">
|
||||||
|
{intl.formatMessage(messages.rubricSelectedError)}
|
||||||
|
</Form.Control.Feedback>
|
||||||
|
)}
|
||||||
|
</Form.RadioSet>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RadioCriterion.defaultProps = {
|
RadioCriterion.defaultProps = {
|
||||||
data: {
|
data: {
|
||||||
@@ -62,6 +66,8 @@ RadioCriterion.defaultProps = {
|
|||||||
RadioCriterion.propTypes = {
|
RadioCriterion.propTypes = {
|
||||||
orderNum: PropTypes.number.isRequired,
|
orderNum: PropTypes.number.isRequired,
|
||||||
isGrading: PropTypes.bool.isRequired,
|
isGrading: PropTypes.bool.isRequired,
|
||||||
|
// injected
|
||||||
|
intl: intlShape.isRequired,
|
||||||
// redux
|
// redux
|
||||||
config: PropTypes.shape({
|
config: PropTypes.shape({
|
||||||
prompt: PropTypes.string,
|
prompt: PropTypes.string,
|
||||||
@@ -92,4 +98,4 @@ export const mapDispatchToProps = {
|
|||||||
setCriterionOption: actions.grading.setCriterionOption,
|
setCriterionOption: actions.grading.setCriterionOption,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(RadioCriterion);
|
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(RadioCriterion));
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import { screen } from '@testing-library/react';
|
import React from 'react';
|
||||||
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import { actions, selectors } from 'data/redux';
|
import { actions, selectors } from 'data/redux';
|
||||||
|
import { formatMessage } from 'testUtils';
|
||||||
import {
|
import {
|
||||||
RadioCriterion,
|
RadioCriterion,
|
||||||
mapDispatchToProps,
|
mapDispatchToProps,
|
||||||
mapStateToProps,
|
mapStateToProps,
|
||||||
} from './RadioCriterion';
|
} from './RadioCriterion';
|
||||||
import { renderWithIntl } from '../../testUtils';
|
|
||||||
|
|
||||||
jest.mock('data/redux/app/selectors', () => ({
|
jest.mock('data/redux/app/selectors', () => ({
|
||||||
rubric: {
|
rubric: {
|
||||||
@@ -30,6 +31,7 @@ jest.mock('data/redux/grading/selectors', () => ({
|
|||||||
|
|
||||||
describe('Radio Criterion Container', () => {
|
describe('Radio Criterion Container', () => {
|
||||||
const props = {
|
const props = {
|
||||||
|
intl: { formatMessage },
|
||||||
orderNum: 1,
|
orderNum: 1,
|
||||||
isGrading: true,
|
isGrading: true,
|
||||||
config: {
|
config: {
|
||||||
@@ -38,14 +40,14 @@ describe('Radio Criterion Container', () => {
|
|||||||
feedback: 'feedback mock',
|
feedback: 'feedback mock',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
explanation: 'explanation',
|
explanation: 'explaination',
|
||||||
feedback: 'option feedback',
|
feedback: 'option feedback',
|
||||||
label: 'this label',
|
label: 'this label',
|
||||||
name: 'option name',
|
name: 'option name',
|
||||||
points: 1,
|
points: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
explanation: 'explanation 2',
|
explanation: 'explaination 2',
|
||||||
feedback: 'option feedback 2',
|
feedback: 'option feedback 2',
|
||||||
label: 'this label 2',
|
label: 'this label 2',
|
||||||
name: 'option name 2',
|
name: 'option name 2',
|
||||||
@@ -53,70 +55,98 @@ describe('Radio Criterion Container', () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
data: 'option name',
|
data: 'selected radio option',
|
||||||
setCriterionOption: jest.fn().mockName('this.props.setCriterionOption'),
|
setCriterionOption: jest.fn().mockName('this.props.setCriterionOption'),
|
||||||
isInvalid: false,
|
isInvalid: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('component rendering', () => {
|
let el;
|
||||||
it('should render radio buttons that are enabled when in grading mode', () => {
|
beforeEach(() => {
|
||||||
const { container } = renderWithIntl(<RadioCriterion {...props} />);
|
el = shallow(<RadioCriterion {...props} />);
|
||||||
|
el.instance().onChange = jest.fn().mockName('this.onChange');
|
||||||
|
});
|
||||||
|
describe('snapshot', () => {
|
||||||
|
test('is grading', () => {
|
||||||
|
expect(el.instance().render()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
const radioButtons = container.querySelectorAll('input[type="radio"]');
|
test('is not grading', () => {
|
||||||
expect(radioButtons.length).toEqual(props.config.options.length);
|
el.setProps({
|
||||||
|
isGrading: false,
|
||||||
|
});
|
||||||
|
expect(el.instance().render()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
radioButtons.forEach(button => {
|
test('radio contain invalid response', () => {
|
||||||
expect(button).not.toBeDisabled();
|
el.setProps({
|
||||||
|
isInvalid: true,
|
||||||
|
});
|
||||||
|
expect(el.instance().render()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('component', () => {
|
||||||
|
describe('rendering', () => {
|
||||||
|
test('is grading (all options are not disabled)', () => {
|
||||||
|
expect(el.isEmptyRender()).toEqual(false);
|
||||||
|
const optionsEl = el.find('.criteria-option');
|
||||||
|
expect(optionsEl.length).toEqual(props.config.options.length);
|
||||||
|
optionsEl.forEach((optionEl) => expect(optionEl.prop('disabled')).toEqual(false));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('is not grading (all options are disabled)', () => {
|
||||||
|
el.setProps({
|
||||||
|
isGrading: false,
|
||||||
|
});
|
||||||
|
expect(el.isEmptyRender()).toEqual(false);
|
||||||
|
const optionsEl = el.find('.criteria-option');
|
||||||
|
expect(optionsEl.length).toEqual(props.config.options.length);
|
||||||
|
optionsEl.forEach((optionEl) => expect(optionEl.prop('disabled')).toEqual(true));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('radio contain invalid response (error response get render)', () => {
|
||||||
|
el.setProps({
|
||||||
|
isInvalid: true,
|
||||||
|
});
|
||||||
|
expect(el.isEmptyRender()).toEqual(false);
|
||||||
|
const radioErrorEl = el.find('.feedback-error-msg');
|
||||||
|
expect(el.instance().props.isInvalid).toEqual(true);
|
||||||
|
expect(radioErrorEl).toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render radio buttons that are disabled when not in grading mode', () => {
|
describe('behavior', () => {
|
||||||
renderWithIntl(<RadioCriterion {...props} isGrading={false} />);
|
test('onChange call set crition option', () => {
|
||||||
|
el = shallow(<RadioCriterion {...props} />);
|
||||||
const radioButtons = screen.queryAllByRole('radio');
|
el.instance().onChange({
|
||||||
expect(radioButtons.length).toEqual(props.config.options.length);
|
target: {
|
||||||
|
value: 'some value',
|
||||||
radioButtons.forEach(button => {
|
},
|
||||||
expect(button).toBeDisabled();
|
});
|
||||||
|
expect(props.setCriterionOption).toBeCalledTimes(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render an error message when the criterion is invalid', () => {
|
|
||||||
const { container } = renderWithIntl(<RadioCriterion {...props} isInvalid />);
|
|
||||||
|
|
||||||
const errorMessage = container.querySelector('.feedback-error-msg');
|
|
||||||
expect(errorMessage).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not render an error message when the criterion is valid', () => {
|
|
||||||
const { container } = renderWithIntl(<RadioCriterion {...props} />);
|
|
||||||
|
|
||||||
const errorMessage = container.querySelector('.feedback-error-msg');
|
|
||||||
expect(errorMessage).not.toBeInTheDocument();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('mapStateToProps', () => {
|
describe('mapStateToProps', () => {
|
||||||
const testState = { arbitrary: 'some data' };
|
const testState = { arbitary: 'some data' };
|
||||||
const ownProps = { orderNum: props.orderNum };
|
const ownProps = { orderNum: props.orderNum };
|
||||||
let mapped;
|
let mapped;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mapped = mapStateToProps(testState, ownProps);
|
mapped = mapStateToProps(testState, ownProps);
|
||||||
});
|
});
|
||||||
|
test('selectors.app.rubric.criterionConfig', () => {
|
||||||
it('should properly map config from rubric criterion config selector', () => {
|
|
||||||
expect(mapped.config).toEqual(
|
expect(mapped.config).toEqual(
|
||||||
selectors.app.rubric.criterionConfig(testState, ownProps),
|
selectors.app.rubric.criterionConfig(testState, ownProps),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should properly map data from selected criterion option selector', () => {
|
test('selectors.grading.selected.criterionSelectedOption', () => {
|
||||||
expect(mapped.data).toEqual(
|
expect(mapped.data).toEqual(
|
||||||
selectors.grading.selected.criterionSelectedOption(testState, ownProps),
|
selectors.grading.selected.criterionSelectedOption(testState, ownProps),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
test('selectors.grading.validation.criterionSelectedOptionIsInvalid', () => {
|
||||||
it('should properly map isInvalid from criterion validation selector', () => {
|
|
||||||
expect(mapped.isInvalid).toEqual(
|
expect(mapped.isInvalid).toEqual(
|
||||||
selectors.grading.validation.criterionSelectedOptionIsInvalid(testState, ownProps),
|
selectors.grading.validation.criterionSelectedOptionIsInvalid(testState, ownProps),
|
||||||
);
|
);
|
||||||
@@ -124,7 +154,7 @@ describe('Radio Criterion Container', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('mapDispatchToProps', () => {
|
describe('mapDispatchToProps', () => {
|
||||||
it('should map setCriterionOption action to props', () => {
|
test('maps actions.grading.setCriterionFeedback to setValue prop', () => {
|
||||||
expect(mapDispatchToProps.setCriterionOption).toEqual(
|
expect(mapDispatchToProps.setCriterionOption).toEqual(
|
||||||
actions.grading.setCriterionOption,
|
actions.grading.setCriterionOption,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
import { Form, FormControlFeedback } from '@openedx/paragon';
|
import { Form, FormControlFeedback } from '@edx/paragon';
|
||||||
import { FormattedMessage } from '@edx/frontend-platform/i18n';
|
import { FormattedMessage } from '@edx/frontend-platform/i18n';
|
||||||
|
|
||||||
import { selectors } from 'data/redux';
|
import { selectors } from 'data/redux';
|
||||||
@@ -14,10 +14,10 @@ import messages from './messages';
|
|||||||
export const ReviewCriterion = ({ config }) => (
|
export const ReviewCriterion = ({ config }) => (
|
||||||
<div className="review-criterion">
|
<div className="review-criterion">
|
||||||
{config.options.map((option) => (
|
{config.options.map((option) => (
|
||||||
<div key={option.name} className="criteria-option" data-testid="criteria-option">
|
<div key={option.name} className="criteria-option">
|
||||||
<div>
|
<div>
|
||||||
<Form.Label className="option-label" data-testid="option-label">{option.label}</Form.Label>
|
<Form.Label className="option-label">{option.label}</Form.Label>
|
||||||
<FormControlFeedback className="option-points" data-testid="option-points">
|
<FormControlFeedback className="option-points">
|
||||||
<FormattedMessage {...messages.optionPoints} values={{ points: option.points }} />
|
<FormattedMessage {...messages.optionPoints} values={{ points: option.points }} />
|
||||||
</FormControlFeedback>
|
</FormControlFeedback>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { screen } from '@testing-library/react';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import { selectors } from 'data/redux';
|
import { selectors } from 'data/redux';
|
||||||
import { renderWithIntl } from '../../testUtils';
|
|
||||||
import { ReviewCriterion, mapStateToProps } from './ReviewCriterion';
|
import { ReviewCriterion, mapStateToProps } from './ReviewCriterion';
|
||||||
|
import messages from './messages';
|
||||||
|
|
||||||
jest.mock('data/redux/app/selectors', () => ({
|
jest.mock('data/redux/app/selectors', () => ({
|
||||||
rubric: {
|
rubric: {
|
||||||
@@ -20,7 +20,7 @@ jest.mock('data/redux/grading/selectors', () => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('Review Criterion Container', () => {
|
describe('Review Crition Container', () => {
|
||||||
const props = {
|
const props = {
|
||||||
orderNum: 1,
|
orderNum: 1,
|
||||||
config: {
|
config: {
|
||||||
@@ -29,14 +29,14 @@ describe('Review Criterion Container', () => {
|
|||||||
feedback: 'feedback mock',
|
feedback: 'feedback mock',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
explanation: 'explanation',
|
explanation: 'explaination',
|
||||||
feedback: 'option feedback',
|
feedback: 'option feedback',
|
||||||
label: 'this label',
|
label: 'this label',
|
||||||
name: 'option name',
|
name: 'option name',
|
||||||
points: 1,
|
points: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
explanation: 'explanation 2',
|
explanation: 'explaination 2',
|
||||||
feedback: 'option feedback 2',
|
feedback: 'option feedback 2',
|
||||||
label: 'this label 2',
|
label: 'this label 2',
|
||||||
name: 'option name 2',
|
name: 'option name 2',
|
||||||
@@ -50,40 +50,47 @@ describe('Review Criterion Container', () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let el;
|
||||||
|
beforeEach(() => {
|
||||||
|
el = shallow(<ReviewCriterion {...props} />);
|
||||||
|
});
|
||||||
|
test('snapshot', () => {
|
||||||
|
expect(el).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
describe('component', () => {
|
describe('component', () => {
|
||||||
it('renders all criteria options with correct labels and points', () => {
|
test('rendering (everything show up)', () => {
|
||||||
renderWithIntl(<ReviewCriterion {...props} />);
|
expect(el.isEmptyRender()).toEqual(false);
|
||||||
|
const optionsEl = el.find('.criteria-option');
|
||||||
const optionsElements = screen.getAllByTestId('criteria-option');
|
expect(optionsEl.length).toEqual(props.config.options.length);
|
||||||
expect(optionsElements.length).toEqual(props.config.options.length);
|
optionsEl.forEach((optionEl, i) => {
|
||||||
|
const option = props.config.options[i];
|
||||||
props.config.options.forEach((option, index) => {
|
expect(optionEl.key()).toEqual(option.name);
|
||||||
const optionElement = optionsElements[index];
|
expect(optionEl.find('.option-label').childAt(0).text()).toEqual(
|
||||||
const labelElement = optionElement.querySelector('[data-testid="option-label"]');
|
option.label,
|
||||||
const pointsElement = optionElement.querySelector('[data-testid="option-points"]');
|
);
|
||||||
|
expect(optionEl.find('.option-points').childAt(0).props()).toEqual({
|
||||||
expect(labelElement.textContent).toEqual(option.label);
|
...messages.optionPoints,
|
||||||
expect(pointsElement.textContent).toEqual(`${props.config.options[index].points} points`);
|
values: { points: option.points },
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('mapStateToProps', () => {
|
describe('mapStateToProps', () => {
|
||||||
const testState = { arbitrary: 'some data' };
|
const testState = { arbitary: 'some data' };
|
||||||
const ownProps = { orderNum: props.orderNum };
|
const ownProps = { orderNum: props.orderNum };
|
||||||
let mapped;
|
let mapped;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mapped = mapStateToProps(testState, ownProps);
|
mapped = mapStateToProps(testState, ownProps);
|
||||||
});
|
});
|
||||||
|
test('selectors.app.rubric.criterionConfig', () => {
|
||||||
it('should map criterion config from state', () => {
|
|
||||||
expect(mapped.config).toEqual(
|
expect(mapped.config).toEqual(
|
||||||
selectors.app.rubric.criterionConfig(testState, ownProps),
|
selectors.app.rubric.criterionConfig(testState, ownProps),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should map criterion grade data from state', () => {
|
test('selectors.grading.selected.criterionGradeData', () => {
|
||||||
expect(mapped.data).toEqual(
|
expect(mapped.data).toEqual(
|
||||||
selectors.grading.selected.criterionGradeData(testState, ownProps),
|
selectors.grading.selected.criterionGradeData(testState, ownProps),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`Criterion Feedback snapshot feedback is configured to disabled 1`] = `null`;
|
||||||
|
|
||||||
|
exports[`Criterion Feedback snapshot feedback is configured to optional 1`] = `
|
||||||
|
<Form.Group>
|
||||||
|
<Form.Control
|
||||||
|
as="textarea"
|
||||||
|
className="criterion-feedback feedback-input"
|
||||||
|
disabled={false}
|
||||||
|
floatingLabel="Add comments (Optional)"
|
||||||
|
onChange={[MockFunction this.onChange]}
|
||||||
|
value="criterion value"
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Criterion Feedback snapshot feedback is configured to required 1`] = `
|
||||||
|
<Form.Group>
|
||||||
|
<Form.Control
|
||||||
|
as="textarea"
|
||||||
|
className="criterion-feedback feedback-input"
|
||||||
|
disabled={false}
|
||||||
|
floatingLabel="Add comments"
|
||||||
|
onChange={[MockFunction this.onChange]}
|
||||||
|
value="criterion value"
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Criterion Feedback snapshot feedback value is invalid 1`] = `
|
||||||
|
<Form.Group>
|
||||||
|
<Form.Control
|
||||||
|
as="textarea"
|
||||||
|
className="criterion-feedback feedback-input"
|
||||||
|
disabled={false}
|
||||||
|
floatingLabel="Add comments"
|
||||||
|
onChange={[MockFunction this.onChange]}
|
||||||
|
value="criterion value"
|
||||||
|
/>
|
||||||
|
<Form.Control.Feedback
|
||||||
|
className="feedback-error-msg"
|
||||||
|
type="invalid"
|
||||||
|
>
|
||||||
|
The feedback is required
|
||||||
|
</Form.Control.Feedback>
|
||||||
|
</Form.Group>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Criterion Feedback snapshot is graded 1`] = `
|
||||||
|
<Form.Group>
|
||||||
|
<Form.Control
|
||||||
|
as="textarea"
|
||||||
|
className="criterion-feedback feedback-input"
|
||||||
|
disabled={true}
|
||||||
|
floatingLabel="Comments"
|
||||||
|
onChange={[MockFunction this.onChange]}
|
||||||
|
value="criterion value"
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Criterion Feedback snapshot is grading 1`] = `
|
||||||
|
<Form.Group>
|
||||||
|
<Form.Control
|
||||||
|
as="textarea"
|
||||||
|
className="criterion-feedback feedback-input"
|
||||||
|
disabled={false}
|
||||||
|
floatingLabel="Add comments"
|
||||||
|
onChange={[MockFunction this.onChange]}
|
||||||
|
value="criterion value"
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
`;
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`Radio Criterion Container snapshot is grading 1`] = `
|
||||||
|
<Form.RadioSet
|
||||||
|
name="random name"
|
||||||
|
value="selected radio option"
|
||||||
|
>
|
||||||
|
<Form.Radio
|
||||||
|
className="criteria-option"
|
||||||
|
description="1 points"
|
||||||
|
disabled={false}
|
||||||
|
onChange={[MockFunction this.onChange]}
|
||||||
|
value="option name"
|
||||||
|
>
|
||||||
|
this label
|
||||||
|
</Form.Radio>
|
||||||
|
<Form.Radio
|
||||||
|
className="criteria-option"
|
||||||
|
description="2 points"
|
||||||
|
disabled={false}
|
||||||
|
onChange={[MockFunction this.onChange]}
|
||||||
|
value="option name 2"
|
||||||
|
>
|
||||||
|
this label 2
|
||||||
|
</Form.Radio>
|
||||||
|
</Form.RadioSet>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Radio Criterion Container snapshot is not grading 1`] = `
|
||||||
|
<Form.RadioSet
|
||||||
|
name="random name"
|
||||||
|
value="selected radio option"
|
||||||
|
>
|
||||||
|
<Form.Radio
|
||||||
|
className="criteria-option"
|
||||||
|
description="1 points"
|
||||||
|
disabled={true}
|
||||||
|
onChange={[MockFunction this.onChange]}
|
||||||
|
value="option name"
|
||||||
|
>
|
||||||
|
this label
|
||||||
|
</Form.Radio>
|
||||||
|
<Form.Radio
|
||||||
|
className="criteria-option"
|
||||||
|
description="2 points"
|
||||||
|
disabled={true}
|
||||||
|
onChange={[MockFunction this.onChange]}
|
||||||
|
value="option name 2"
|
||||||
|
>
|
||||||
|
this label 2
|
||||||
|
</Form.Radio>
|
||||||
|
</Form.RadioSet>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Radio Criterion Container snapshot radio contain invalid response 1`] = `
|
||||||
|
<Form.RadioSet
|
||||||
|
name="random name"
|
||||||
|
value="selected radio option"
|
||||||
|
>
|
||||||
|
<Form.Radio
|
||||||
|
className="criteria-option"
|
||||||
|
description="1 points"
|
||||||
|
disabled={false}
|
||||||
|
onChange={[MockFunction this.onChange]}
|
||||||
|
value="option name"
|
||||||
|
>
|
||||||
|
this label
|
||||||
|
</Form.Radio>
|
||||||
|
<Form.Radio
|
||||||
|
className="criteria-option"
|
||||||
|
description="2 points"
|
||||||
|
disabled={false}
|
||||||
|
onChange={[MockFunction this.onChange]}
|
||||||
|
value="option name 2"
|
||||||
|
>
|
||||||
|
this label 2
|
||||||
|
</Form.Radio>
|
||||||
|
<Form.Control.Feedback
|
||||||
|
className="feedback-error-msg"
|
||||||
|
type="invalid"
|
||||||
|
>
|
||||||
|
Rubric selection is required
|
||||||
|
</Form.Control.Feedback>
|
||||||
|
</Form.RadioSet>
|
||||||
|
`;
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`Review Crition Container snapshot 1`] = `
|
||||||
|
<div
|
||||||
|
className="review-criterion"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="criteria-option"
|
||||||
|
key="option name"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<Form.Label
|
||||||
|
className="option-label"
|
||||||
|
>
|
||||||
|
this label
|
||||||
|
</Form.Label>
|
||||||
|
<FormControlFeedback
|
||||||
|
className="option-points"
|
||||||
|
>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="{points} points"
|
||||||
|
description="criterion option point value display"
|
||||||
|
id="ora-grading.RadioCriterion.optionPoints"
|
||||||
|
values={
|
||||||
|
Object {
|
||||||
|
"points": 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</FormControlFeedback>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="criteria-option"
|
||||||
|
key="option name 2"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<Form.Label
|
||||||
|
className="option-label"
|
||||||
|
>
|
||||||
|
this label 2
|
||||||
|
</Form.Label>
|
||||||
|
<FormControlFeedback
|
||||||
|
className="option-points"
|
||||||
|
>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="{points} points"
|
||||||
|
description="criterion option point value display"
|
||||||
|
id="ora-grading.RadioCriterion.optionPoints"
|
||||||
|
values={
|
||||||
|
Object {
|
||||||
|
"points": 2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</FormControlFeedback>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`Criterion Container snapshot is graded and is not grading 1`] = `
|
||||||
|
<Form.Group>
|
||||||
|
<Form.Label
|
||||||
|
className="criteria-label"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="criteria-title"
|
||||||
|
>
|
||||||
|
prompt
|
||||||
|
</span>
|
||||||
|
<InfoPopover>
|
||||||
|
<div
|
||||||
|
className="help-popover-option"
|
||||||
|
key="option name"
|
||||||
|
>
|
||||||
|
<strong>
|
||||||
|
this label
|
||||||
|
</strong>
|
||||||
|
<br />
|
||||||
|
explaination
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="help-popover-option"
|
||||||
|
key="option name 2"
|
||||||
|
>
|
||||||
|
<strong>
|
||||||
|
this label 2
|
||||||
|
</strong>
|
||||||
|
<br />
|
||||||
|
explaination 2
|
||||||
|
</div>
|
||||||
|
</InfoPopover>
|
||||||
|
</Form.Label>
|
||||||
|
<div
|
||||||
|
className="rubric-criteria"
|
||||||
|
>
|
||||||
|
<RadioCriterion
|
||||||
|
isGrading={false}
|
||||||
|
orderNum={1}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<CriterionFeedback
|
||||||
|
isGrading={false}
|
||||||
|
orderNum={1}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Criterion Container snapshot is ungraded and is grading 1`] = `
|
||||||
|
<Form.Group>
|
||||||
|
<Form.Label
|
||||||
|
className="criteria-label"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="criteria-title"
|
||||||
|
>
|
||||||
|
prompt
|
||||||
|
</span>
|
||||||
|
<InfoPopover>
|
||||||
|
<div
|
||||||
|
className="help-popover-option"
|
||||||
|
key="option name"
|
||||||
|
>
|
||||||
|
<strong>
|
||||||
|
this label
|
||||||
|
</strong>
|
||||||
|
<br />
|
||||||
|
explaination
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="help-popover-option"
|
||||||
|
key="option name 2"
|
||||||
|
>
|
||||||
|
<strong>
|
||||||
|
this label 2
|
||||||
|
</strong>
|
||||||
|
<br />
|
||||||
|
explaination 2
|
||||||
|
</div>
|
||||||
|
</InfoPopover>
|
||||||
|
</Form.Label>
|
||||||
|
<div
|
||||||
|
className="rubric-criteria"
|
||||||
|
>
|
||||||
|
<RadioCriterion
|
||||||
|
isGrading={true}
|
||||||
|
orderNum={1}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<CriterionFeedback
|
||||||
|
isGrading={true}
|
||||||
|
orderNum={1}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Criterion Container snapshot is ungraded and is not grading 1`] = `
|
||||||
|
<Form.Group>
|
||||||
|
<Form.Label
|
||||||
|
className="criteria-label"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="criteria-title"
|
||||||
|
>
|
||||||
|
prompt
|
||||||
|
</span>
|
||||||
|
<InfoPopover>
|
||||||
|
<div
|
||||||
|
className="help-popover-option"
|
||||||
|
key="option name"
|
||||||
|
>
|
||||||
|
<strong>
|
||||||
|
this label
|
||||||
|
</strong>
|
||||||
|
<br />
|
||||||
|
explaination
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="help-popover-option"
|
||||||
|
key="option name 2"
|
||||||
|
>
|
||||||
|
<strong>
|
||||||
|
this label 2
|
||||||
|
</strong>
|
||||||
|
<br />
|
||||||
|
explaination 2
|
||||||
|
</div>
|
||||||
|
</InfoPopover>
|
||||||
|
</Form.Label>
|
||||||
|
<div
|
||||||
|
className="rubric-criteria"
|
||||||
|
>
|
||||||
|
<ReviewCriterion
|
||||||
|
orderNum={1}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<CriterionFeedback
|
||||||
|
isGrading={false}
|
||||||
|
orderNum={1}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
`;
|
||||||
@@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
import { Form } from '@openedx/paragon';
|
import { Form } from '@edx/paragon';
|
||||||
|
|
||||||
import { selectors } from 'data/redux';
|
import { selectors } from 'data/redux';
|
||||||
import { gradeStatuses } from 'data/services/lms/constants';
|
import { gradeStatuses } from 'data/services/lms/constants';
|
||||||
@@ -25,7 +25,7 @@ export const CriterionContainer = (props) => {
|
|||||||
<span className="criteria-title">{config.prompt}</span>
|
<span className="criteria-title">{config.prompt}</span>
|
||||||
<InfoPopover>
|
<InfoPopover>
|
||||||
{config.options.map((option) => (
|
{config.options.map((option) => (
|
||||||
<div key={option.name} className="help-popover-option" data-testid="help-popover-option">
|
<div key={option.name} className="help-popover-option">
|
||||||
<strong>{option.label}</strong>
|
<strong>{option.label}</strong>
|
||||||
<br />
|
<br />
|
||||||
{option.explanation}
|
{option.explanation}
|
||||||
@@ -33,7 +33,7 @@ export const CriterionContainer = (props) => {
|
|||||||
))}
|
))}
|
||||||
</InfoPopover>
|
</InfoPopover>
|
||||||
</Form.Label>
|
</Form.Label>
|
||||||
<div className="rubric-criteria" data-testid="rubric-criteria">
|
<div className="rubric-criteria">
|
||||||
{isGrading || gradeStatus === gradeStatuses.graded ? (
|
{isGrading || gradeStatus === gradeStatuses.graded ? (
|
||||||
<RadioCriterion orderNum={orderNum} isGrading={isGrading} />
|
<RadioCriterion orderNum={orderNum} isGrading={isGrading} />
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -1,50 +1,15 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import { selectors } from 'data/redux';
|
import { selectors } from 'data/redux';
|
||||||
import { gradeStatuses } from 'data/services/lms/constants';
|
import { gradeStatuses } from 'data/services/lms/constants';
|
||||||
|
|
||||||
import { CriterionContainer, mapStateToProps } from '.';
|
import { CriterionContainer, mapStateToProps } from '.';
|
||||||
|
|
||||||
const MockRadioCriterion = ({ orderNum, isGrading }) => (
|
jest.mock('components/InfoPopover', () => 'InfoPopover');
|
||||||
<div data-testid="radio-criterion-component">
|
jest.mock('./RadioCriterion', () => 'RadioCriterion');
|
||||||
RadioCriterion Component (orderNum={orderNum}, isGrading={String(isGrading)})
|
jest.mock('./CriterionFeedback', () => 'CriterionFeedback');
|
||||||
</div>
|
jest.mock('./ReviewCriterion', () => 'ReviewCriterion');
|
||||||
);
|
|
||||||
|
|
||||||
MockRadioCriterion.propTypes = {
|
|
||||||
orderNum: PropTypes.number.isRequired,
|
|
||||||
isGrading: PropTypes.bool.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
const MockReviewCriterion = ({ orderNum }) => (
|
|
||||||
<div data-testid="review-criterion-component">
|
|
||||||
ReviewCriterion Component (orderNum={orderNum})
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
MockReviewCriterion.propTypes = {
|
|
||||||
orderNum: PropTypes.number.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
const MockCriterionFeedback = ({ orderNum, isGrading }) => (
|
|
||||||
<div data-testid="criterion-feedback-component">
|
|
||||||
CriterionFeedback Component (orderNum={orderNum}, isGrading={String(isGrading)})
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
MockCriterionFeedback.propTypes = {
|
|
||||||
orderNum: PropTypes.number.isRequired,
|
|
||||||
isGrading: PropTypes.bool.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
const MockInfoPopover = ({ children }) => (
|
|
||||||
<div data-testid="info-popover">{children}</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
MockInfoPopover.propTypes = {
|
|
||||||
children: PropTypes.node.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
jest.mock('data/redux/app/selectors', () => ({
|
jest.mock('data/redux/app/selectors', () => ({
|
||||||
rubric: {
|
rubric: {
|
||||||
@@ -53,18 +18,12 @@ jest.mock('data/redux/app/selectors', () => ({
|
|||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('data/redux/grading/selectors', () => ({
|
jest.mock('data/redux/grading/selectors', () => ({
|
||||||
selected: {
|
selected: {
|
||||||
gradeStatus: jest.fn((...args) => ({ selectedGradeStatus: args })),
|
gradeStatus: jest.fn((...args) => ({ selectedGradeStatus: args })),
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('./RadioCriterion', () => jest.fn((props) => MockRadioCriterion(props)));
|
|
||||||
jest.mock('./ReviewCriterion', () => jest.fn((props) => MockReviewCriterion(props)));
|
|
||||||
jest.mock('./CriterionFeedback', () => jest.fn((props) => MockCriterionFeedback(props)));
|
|
||||||
jest.mock('components/InfoPopover', () => jest.fn((props) => MockInfoPopover(props)));
|
|
||||||
|
|
||||||
describe('Criterion Container', () => {
|
describe('Criterion Container', () => {
|
||||||
const props = {
|
const props = {
|
||||||
isGrading: true,
|
isGrading: true,
|
||||||
@@ -75,14 +34,14 @@ describe('Criterion Container', () => {
|
|||||||
feedback: 'feedback mock',
|
feedback: 'feedback mock',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
explanation: 'explanation',
|
explanation: 'explaination',
|
||||||
feedback: 'option feedback',
|
feedback: 'option feedback',
|
||||||
label: 'this label',
|
label: 'this label',
|
||||||
name: 'option name',
|
name: 'option name',
|
||||||
points: 2,
|
points: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
explanation: 'explanation 2',
|
explanation: 'explaination 2',
|
||||||
feedback: 'option feedback 2',
|
feedback: 'option feedback 2',
|
||||||
label: 'this label 2',
|
label: 'this label 2',
|
||||||
name: 'option name 2',
|
name: 'option name 2',
|
||||||
@@ -92,62 +51,80 @@ describe('Criterion Container', () => {
|
|||||||
},
|
},
|
||||||
gradeStatus: gradeStatuses.ungraded,
|
gradeStatus: gradeStatuses.ungraded,
|
||||||
};
|
};
|
||||||
|
let el;
|
||||||
|
beforeEach(() => {
|
||||||
|
el = shallow(<CriterionContainer {...props} />);
|
||||||
|
});
|
||||||
|
|
||||||
describe('component rendering', () => {
|
describe('snapshot', () => {
|
||||||
it('displays the criterion prompt', () => {
|
test('is ungraded and is grading', () => {
|
||||||
render(<CriterionContainer {...props} />);
|
expect(el).toMatchSnapshot();
|
||||||
expect(screen.getByText('prompt')).toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('displays all option explanations in the info popover', () => {
|
test('is ungraded and is not grading', () => {
|
||||||
render(<CriterionContainer {...props} />);
|
el.setProps({
|
||||||
const infoPopover = screen.getByTestId('info-popover');
|
isGrading: false,
|
||||||
expect(infoPopover).toHaveTextContent('explanation');
|
});
|
||||||
expect(infoPopover).toHaveTextContent('explanation 2');
|
expect(el).toMatchSnapshot();
|
||||||
expect(infoPopover).toHaveTextContent('this label');
|
|
||||||
expect(infoPopover).toHaveTextContent('this label 2');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders RadioCriterion when is ungraded and is grading', () => {
|
test('is graded and is not grading', () => {
|
||||||
render(<CriterionContainer {...props} />);
|
el.setProps({
|
||||||
expect(screen.getByTestId('radio-criterion-component')).toBeInTheDocument();
|
isGrading: false,
|
||||||
expect(screen.queryByTestId('review-criterion-component')).not.toBeInTheDocument();
|
gradeStatus: gradeStatuses.graded,
|
||||||
|
});
|
||||||
|
expect(el).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('component', () => {
|
||||||
|
test('rendering and all of the option show up', () => {
|
||||||
|
expect(el.isEmptyRender()).toEqual(false);
|
||||||
|
const optionsEl = el.find('.help-popover-option');
|
||||||
|
expect(optionsEl.length).toEqual(props.config.options.length);
|
||||||
|
optionsEl.forEach((optionEl, i) => {
|
||||||
|
expect(optionEl.key()).toEqual(props.config.options[i].name);
|
||||||
|
expect(optionEl.text()).toContain(props.config.options[i].explanation);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders ReviewCriterion when is ungraded and is not grading', () => {
|
test('is ungraded and is grading (Radio criterion get render)', () => {
|
||||||
render(<CriterionContainer {...props} isGrading={false} />);
|
const rubricCritera = el.find('.rubric-criteria');
|
||||||
expect(screen.getByTestId('review-criterion-component')).toBeInTheDocument();
|
expect(rubricCritera.children(0).name()).toEqual('RadioCriterion');
|
||||||
expect(screen.queryByTestId('radio-criterion-component')).not.toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders RadioCriterion when is graded and is not grading', () => {
|
test('is ungraded and is not grading (Review criterion get render)', () => {
|
||||||
render(<CriterionContainer {...props} isGrading={false} gradeStatus={gradeStatuses.graded} />);
|
el.setProps({
|
||||||
expect(screen.getByTestId('radio-criterion-component')).toBeInTheDocument();
|
isGrading: false,
|
||||||
expect(screen.queryByTestId('review-criterion-component')).not.toBeInTheDocument();
|
});
|
||||||
|
const rubricCritera = el.find('.rubric-criteria');
|
||||||
|
expect(rubricCritera.children(0).name()).toEqual('ReviewCriterion');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders CriterionFeedback component', () => {
|
test('is graded and is not grading (Radio criterion get render)', () => {
|
||||||
render(<CriterionContainer {...props} />);
|
el.setProps({
|
||||||
expect(screen.getByTestId('criterion-feedback-component')).toBeInTheDocument();
|
isGrading: false,
|
||||||
|
gradeStatus: gradeStatuses.graded,
|
||||||
|
});
|
||||||
|
const rubricCritera = el.find('.rubric-criteria');
|
||||||
|
expect(rubricCritera.children(0).name()).toEqual('RadioCriterion');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('mapStateToProps', () => {
|
describe('mapStateToProps', () => {
|
||||||
const testState = { arbitraryState: 'some data' };
|
const testState = { abitaryState: 'some data' };
|
||||||
const ownProps = { orderNum: props.orderNum };
|
const ownProps = { orderNum: props.orderNum };
|
||||||
let mapped;
|
let mapped;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mapped = mapStateToProps(testState, ownProps);
|
mapped = mapStateToProps(testState, ownProps);
|
||||||
});
|
});
|
||||||
|
test('selectors.app.rubric.criterionConfig', () => {
|
||||||
it('maps rubric criterion config to props', () => {
|
|
||||||
expect(mapped.config).toEqual(
|
expect(mapped.config).toEqual(
|
||||||
selectors.app.rubric.criterionConfig(testState, ownProps),
|
selectors.app.rubric.criterionConfig(testState, ownProps),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('maps grading status to props', () => {
|
test('selectors.grading.selected.gradeStatus', () => {
|
||||||
expect(mapped.gradeStatus).toEqual(
|
expect(mapped.gradeStatus).toEqual(
|
||||||
selectors.grading.selected.gradeStatus(testState),
|
selectors.grading.selected.gradeStatus(testState),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const messages = defineMessages({
|
|||||||
optional: {
|
optional: {
|
||||||
id: 'ora-grading.CriterionFeedback.optional',
|
id: 'ora-grading.CriterionFeedback.optional',
|
||||||
defaultMessage: '(Optional)',
|
defaultMessage: '(Optional)',
|
||||||
description: 'additional label for optional feedback field',
|
description: 'addtional label for optional feedback field',
|
||||||
},
|
},
|
||||||
optionPoints: {
|
optionPoints: {
|
||||||
id: 'ora-grading.RadioCriterion.optionPoints',
|
id: 'ora-grading.RadioCriterion.optionPoints',
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
import React from 'react';
|
||||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import { selectors } from 'data/redux';
|
import { selectors } from 'data/redux';
|
||||||
import { DemoWarning, mapStateToProps } from '.';
|
import { DemoWarning, mapStateToProps } from '.';
|
||||||
import messages from './messages';
|
|
||||||
|
|
||||||
jest.mock('data/redux', () => ({
|
jest.mock('data/redux', () => ({
|
||||||
selectors: {
|
selectors: {
|
||||||
@@ -10,26 +10,24 @@ jest.mock('data/redux', () => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('DemoWarning component', () => {
|
let el;
|
||||||
describe('behavior', () => {
|
|
||||||
it('does not render when hide prop is true', () => {
|
|
||||||
const { container } = render(<IntlProvider locale="en"><DemoWarning hide /></IntlProvider>);
|
|
||||||
expect(container.firstChild).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders alert with warning message when hide prop is false', () => {
|
describe('DemoWarning component', () => {
|
||||||
render(<IntlProvider locale="en"><DemoWarning hide={false} /></IntlProvider>);
|
describe('snapshots', () => {
|
||||||
const alert = screen.getByRole('alert');
|
test('does not render if disabled flag is missing', () => {
|
||||||
expect(alert).toBeInTheDocument();
|
el = shallow(<DemoWarning hide />);
|
||||||
expect(alert).toHaveClass('alert-warning');
|
expect(el).toMatchSnapshot();
|
||||||
expect(alert).toHaveTextContent(messages.demoModeMessage.defaultMessage);
|
expect(el.isEmptyRender()).toEqual(true);
|
||||||
expect(alert).toHaveTextContent(messages.demoModeHeading.defaultMessage);
|
});
|
||||||
|
test('snapshot: disabled flag is present', () => {
|
||||||
|
el = shallow(<DemoWarning hide={false} />);
|
||||||
|
expect(el).toMatchSnapshot();
|
||||||
|
expect(el.isEmptyRender()).toEqual(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('mapStateToProps', () => {
|
describe('mapStateToProps', () => {
|
||||||
it('maps hide prop from app.isEnabled selector', () => {
|
const testState = { some: 'test-state' };
|
||||||
const testState = { some: 'test-state' };
|
test('hide is forwarded from app.isEnabled', () => {
|
||||||
expect(mapStateToProps(testState).hide).toEqual(
|
expect(mapStateToProps(testState).hide).toEqual(
|
||||||
selectors.app.isEnabled(testState),
|
selectors.app.isEnabled(testState),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`DemoWarning component snapshots does not render if disabled flag is missing 1`] = `""`;
|
||||||
|
|
||||||
|
exports[`DemoWarning component snapshots snapshot: disabled flag is present 1`] = `
|
||||||
|
<Alert
|
||||||
|
className="mb-0 rounded-0"
|
||||||
|
variant="warning"
|
||||||
|
>
|
||||||
|
<Alert.Heading>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="Demo Mode"
|
||||||
|
description="Demo mode heading"
|
||||||
|
id="ora-grading.ReviewModal.demoHeading"
|
||||||
|
/>
|
||||||
|
</Alert.Heading>
|
||||||
|
<p>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="You are demoing the new ORA staff grading experience. You will be unable to submit grades until you activate the feature. This will become the default grading experience on May 9th (05/09/2022). To opt-in early, or opt-out, please contact Partner Support."
|
||||||
|
description="Demo mode message"
|
||||||
|
id="ora-grading.ReviewModal.demoMessage"
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
</Alert>
|
||||||
|
`;
|
||||||
@@ -3,8 +3,8 @@ import { connect } from 'react-redux';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import { FormattedMessage } from '@edx/frontend-platform/i18n';
|
import { FormattedMessage } from '@edx/frontend-platform/i18n';
|
||||||
import { Alert } from '@openedx/paragon';
|
import { Alert } from '@edx/paragon';
|
||||||
import { Info } from '@openedx/paragon/icons';
|
import { Info } from '@edx/paragon/icons';
|
||||||
|
|
||||||
import { selectors } from 'data/redux';
|
import { selectors } from 'data/redux';
|
||||||
import messages from './messages';
|
import messages from './messages';
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import { FormattedMessage } from '@edx/frontend-platform/i18n';
|
import { FormattedMessage } from '@edx/frontend-platform/i18n';
|
||||||
import { Hyperlink, Button } from '@openedx/paragon';
|
import { Hyperlink, Button } from '@edx/paragon';
|
||||||
|
|
||||||
import urls from 'data/services/lms/urls';
|
import urls from 'data/services/lms/urls';
|
||||||
import emptyStateSVG from './assets/empty-state.svg';
|
import emptyStateSVG from './assets/empty-state.svg';
|
||||||
|
|||||||
@@ -1,38 +1,33 @@
|
|||||||
import { screen } from '@testing-library/react';
|
import React from 'react';
|
||||||
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
|
import { Hyperlink } from '@edx/paragon';
|
||||||
|
|
||||||
import urls from 'data/services/lms/urls';
|
import urls from 'data/services/lms/urls';
|
||||||
import { renderWithIntl } from '../../testUtils';
|
|
||||||
import EmptySubmission from './EmptySubmission';
|
import EmptySubmission from './EmptySubmission';
|
||||||
|
|
||||||
jest.mock('data/services/lms/urls', () => ({
|
jest.mock('data/services/lms/urls', () => ({
|
||||||
openResponse: (courseId) => `openResponseUrl(${courseId})`,
|
openResponse: (courseId) => `openResponseUrl(${courseId})`,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('./assets/empty-state.svg', () => './assets/empty-state.svg');
|
jest.mock('./assets/emptyState.svg', () => './assets/emptyState.svg');
|
||||||
|
|
||||||
|
let el;
|
||||||
|
|
||||||
describe('EmptySubmission component', () => {
|
describe('EmptySubmission component', () => {
|
||||||
const props = { courseId: 'test-course-id' };
|
describe('component', () => {
|
||||||
|
const props = { courseId: 'test-course-id' };
|
||||||
it('renders the empty state image with correct alt text', () => {
|
beforeEach(() => {
|
||||||
renderWithIntl(<EmptySubmission {...props} />);
|
el = shallow(<EmptySubmission {...props} />);
|
||||||
expect(screen.getByAltText('empty state')).toBeInTheDocument();
|
});
|
||||||
});
|
test('snapshot', () => {
|
||||||
|
expect(el).toMatchSnapshot();
|
||||||
it('renders the no results found title message', () => {
|
});
|
||||||
renderWithIntl(<EmptySubmission {...props} />);
|
test('openResponse destination', () => {
|
||||||
expect(screen.getByText('Nothing here yet')).toBeInTheDocument();
|
expect(
|
||||||
});
|
el.find(Hyperlink).at(0).props().destination,
|
||||||
|
).toEqual(urls.openResponse(props.courseId));
|
||||||
it('renders hyperlink with correct destination URL', () => {
|
});
|
||||||
renderWithIntl(<EmptySubmission {...props} />);
|
|
||||||
const hyperlink = screen.getByRole('link');
|
|
||||||
expect(hyperlink).toHaveAttribute(
|
|
||||||
'href',
|
|
||||||
urls.openResponse(props.courseId),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders the back to responses button', () => {
|
|
||||||
renderWithIntl(<EmptySubmission {...props} />);
|
|
||||||
expect(screen.getByText('Back to all open responses')).toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Button, DataTableContext } from '@openedx/paragon';
|
import { Button, DataTableContext } from '@edx/paragon';
|
||||||
|
|
||||||
import * as module from './FilterStatusComponent';
|
import * as module from './FilterStatusComponent';
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,54 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import { shallow } from 'enzyme';
|
||||||
import { render } from '@testing-library/react';
|
|
||||||
import { DataTableContext } from '@openedx/paragon';
|
|
||||||
|
|
||||||
import * as module from './FilterStatusComponent';
|
import * as module from './FilterStatusComponent';
|
||||||
|
|
||||||
const fieldIds = ['field-id-0', 'field-id-1', 'field-id-2', 'field-id-3'];
|
const fieldIds = [
|
||||||
|
'field-id-0',
|
||||||
|
'field-id-1',
|
||||||
|
'field-id-2',
|
||||||
|
'field-id-3',
|
||||||
|
];
|
||||||
const filterOrder = [1, 0, 3, 2];
|
const filterOrder = [1, 0, 3, 2];
|
||||||
const filters = filterOrder.map((v) => ({ id: fieldIds[v] }));
|
const filters = filterOrder.map(v => ({ id: fieldIds[v] }));
|
||||||
const headers = [0, 1, 2, 3].map((v) => ({
|
const headers = [0, 1, 2, 3].map(v => ({
|
||||||
id: fieldIds[v],
|
id: fieldIds[v],
|
||||||
Header: `HeaDer-${v}`,
|
Header: `HeaDer-${v}`,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
describe('FilterStatusComponent hooks', () => {
|
||||||
|
const context = { headers, state: { filters } };
|
||||||
|
const mockTableContext = (newContext) => {
|
||||||
|
React.useContext.mockReturnValueOnce(newContext);
|
||||||
|
};
|
||||||
|
beforeEach(() => {
|
||||||
|
context.setAllFilters = jest.fn();
|
||||||
|
});
|
||||||
|
it('returns empty dict if setAllFilters or state.filters is falsey', () => {
|
||||||
|
mockTableContext({ ...context, setAllFilters: null });
|
||||||
|
expect(module.filterHooks()).toEqual({});
|
||||||
|
mockTableContext({ ...context, state: { filters: null } });
|
||||||
|
expect(module.filterHooks()).toEqual({});
|
||||||
|
});
|
||||||
|
describe('clearFilters', () => {
|
||||||
|
it('uses React.useCallback to clear filters, only once', () => {
|
||||||
|
mockTableContext(context);
|
||||||
|
const { cb, prereqs } = module.filterHooks().clearFilters.useCallback;
|
||||||
|
expect(prereqs).toEqual([context.setAllFilters]);
|
||||||
|
expect(context.setAllFilters).not.toHaveBeenCalled();
|
||||||
|
cb();
|
||||||
|
expect(context.setAllFilters).toHaveBeenCalledWith([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('filterNames', () => {
|
||||||
|
it('returns list of Header values by filter order', () => {
|
||||||
|
mockTableContext(context);
|
||||||
|
expect(module.filterHooks().filterNames).toEqual(
|
||||||
|
filterOrder.map(v => headers[v].Header),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
describe('FilterStatusComponent component', () => {
|
describe('FilterStatusComponent component', () => {
|
||||||
const props = {
|
const props = {
|
||||||
className: 'css-class-name',
|
className: 'css-class-name',
|
||||||
@@ -22,98 +58,34 @@ describe('FilterStatusComponent component', () => {
|
|||||||
buttonClassName: 'css-class-name-for-button',
|
buttonClassName: 'css-class-name-for-button',
|
||||||
showFilteredFields: true,
|
showFilteredFields: true,
|
||||||
};
|
};
|
||||||
const { FilterStatusComponent } = module;
|
const hookProps = {
|
||||||
|
clearFilters: jest.fn().mockName('hookProps.clearFilters'),
|
||||||
const renderWithContext = (contextValue, componentProps = props) => {
|
filterNames: ['filter-name-0', 'filter-name-1'],
|
||||||
const TestWrapper = ({ children }) => (
|
|
||||||
<DataTableContext.Provider value={contextValue}>
|
|
||||||
{children}
|
|
||||||
</DataTableContext.Provider>
|
|
||||||
);
|
|
||||||
TestWrapper.propTypes = {
|
|
||||||
children: PropTypes.node,
|
|
||||||
};
|
|
||||||
return render(
|
|
||||||
<TestWrapper>
|
|
||||||
<FilterStatusComponent {...componentProps} />
|
|
||||||
</TestWrapper>,
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
const { FilterStatusComponent } = module;
|
||||||
beforeEach(() => {
|
const mockHooks = (value) => {
|
||||||
jest.clearAllMocks();
|
jest.spyOn(module, 'filterHooks').mockReturnValueOnce(value);
|
||||||
});
|
};
|
||||||
|
describe('snapshot', () => {
|
||||||
describe('behavior', () => {
|
describe('with filters', () => {
|
||||||
it('does not render when there are no filters', () => {
|
test('showFilteredFields', () => {
|
||||||
const contextValue = {
|
mockHooks(hookProps);
|
||||||
headers,
|
const el = shallow(<FilterStatusComponent {...props} />);
|
||||||
state: { filters: null },
|
expect(el).toMatchSnapshot();
|
||||||
setAllFilters: jest.fn(),
|
});
|
||||||
};
|
test('showFilteredFields=false - hide filterTexts', () => {
|
||||||
const { container } = renderWithContext(contextValue);
|
mockHooks(hookProps);
|
||||||
expect(container.firstChild).toBeNull();
|
const el = shallow(
|
||||||
});
|
<FilterStatusComponent {...props} showFilteredFields={false} />,
|
||||||
|
);
|
||||||
it('does not render when setAllFilters is not available', () => {
|
expect(el).toMatchSnapshot();
|
||||||
const contextValue = { headers, state: { filters }, setAllFilters: null };
|
|
||||||
const { container } = renderWithContext(contextValue);
|
|
||||||
expect(container.firstChild).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders clear filters button with correct text when filters exist', () => {
|
|
||||||
const contextValue = {
|
|
||||||
headers,
|
|
||||||
state: { filters },
|
|
||||||
setAllFilters: jest.fn(),
|
|
||||||
};
|
|
||||||
const { getByText } = renderWithContext(contextValue);
|
|
||||||
expect(getByText(props.clearFiltersText)).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('displays filtered field names when showFilteredFields is true', () => {
|
|
||||||
const contextValue = {
|
|
||||||
headers,
|
|
||||||
state: { filters },
|
|
||||||
setAllFilters: jest.fn(),
|
|
||||||
};
|
|
||||||
const { getByText } = renderWithContext(contextValue);
|
|
||||||
const expectedFilterNames = filterOrder.map((v) => headers[v].Header);
|
|
||||||
expectedFilterNames.forEach((name) => {
|
|
||||||
expect(getByText(name, { exact: false })).toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
test('without filters', () => {
|
||||||
it('does not display filtered field names when showFilteredFields is false', () => {
|
mockHooks({});
|
||||||
const contextValue = {
|
const el = shallow(<FilterStatusComponent {...props} />);
|
||||||
headers,
|
expect(el).toMatchSnapshot();
|
||||||
state: { filters },
|
expect(el.isEmptyRender()).toEqual(true);
|
||||||
setAllFilters: jest.fn(),
|
|
||||||
};
|
|
||||||
const { queryByText } = renderWithContext(contextValue, {
|
|
||||||
...props,
|
|
||||||
showFilteredFields: false,
|
|
||||||
});
|
|
||||||
expect(queryByText(/Filtered by/)).not.toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('applies correct CSS classes to the component', () => {
|
|
||||||
const contextValue = {
|
|
||||||
headers,
|
|
||||||
state: { filters },
|
|
||||||
setAllFilters: jest.fn(),
|
|
||||||
};
|
|
||||||
const { container } = renderWithContext(contextValue);
|
|
||||||
expect(container.firstChild).toHaveClass(props.className);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calls setAllFilters with empty array when clear button is clicked', () => {
|
|
||||||
const setAllFilters = jest.fn();
|
|
||||||
const contextValue = { headers, state: { filters }, setAllFilters };
|
|
||||||
const { getByText } = renderWithContext(contextValue);
|
|
||||||
const clearButton = getByText(props.clearFiltersText);
|
|
||||||
clearButton.click();
|
|
||||||
expect(setAllFilters).toHaveBeenCalledWith([]);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import {
|
|||||||
Alert,
|
Alert,
|
||||||
Button,
|
Button,
|
||||||
Hyperlink,
|
Hyperlink,
|
||||||
} from '@openedx/paragon';
|
} from '@edx/paragon';
|
||||||
import { Info } from '@openedx/paragon/icons';
|
import { Info } from '@edx/paragon/icons';
|
||||||
import { FormattedMessage } from '@edx/frontend-platform/i18n';
|
import { FormattedMessage } from '@edx/frontend-platform/i18n';
|
||||||
|
|
||||||
import urls from 'data/services/lms/urls';
|
import urls from 'data/services/lms/urls';
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
import { screen } from '@testing-library/react';
|
import React from 'react';
|
||||||
import userEvent from '@testing-library/user-event';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import { selectors, thunkActions } from 'data/redux';
|
import { selectors, thunkActions } from 'data/redux';
|
||||||
import { renderWithIntl } from '../../testUtils';
|
|
||||||
import { ListError, mapDispatchToProps, mapStateToProps } from './ListError';
|
import { formatMessage } from 'testUtils';
|
||||||
import messages from './messages';
|
import {
|
||||||
|
ListError,
|
||||||
|
mapDispatchToProps,
|
||||||
|
mapStateToProps,
|
||||||
|
} from './ListError';
|
||||||
|
|
||||||
jest.mock('data/redux', () => ({
|
jest.mock('data/redux', () => ({
|
||||||
selectors: {
|
selectors: {
|
||||||
app: {
|
app: {
|
||||||
courseId: jest.fn((state) => state.courseId || 'test-course-id'),
|
courseId: (...args) => ({ courseId: args }),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
thunkActions: {
|
thunkActions: {
|
||||||
@@ -22,60 +27,41 @@ jest.mock('data/services/lms/urls', () => ({
|
|||||||
openResponse: (courseId) => `api/openResponse/${courseId}`,
|
openResponse: (courseId) => `api/openResponse/${courseId}`,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
let el;
|
||||||
|
jest.useFakeTimers('modern');
|
||||||
|
|
||||||
describe('ListError component', () => {
|
describe('ListError component', () => {
|
||||||
const props = {
|
describe('component', () => {
|
||||||
courseId: 'test-course-id',
|
const props = {
|
||||||
initializeApp: jest.fn(),
|
courseId: 'test-course-id',
|
||||||
};
|
};
|
||||||
|
beforeEach(() => {
|
||||||
beforeEach(() => {
|
props.loadSelectionForReview = jest.fn();
|
||||||
jest.clearAllMocks();
|
props.intl = { formatMessage };
|
||||||
});
|
props.initializeApp = jest.fn();
|
||||||
|
|
||||||
describe('behavior', () => {
|
|
||||||
it('renders error alert with proper styling', () => {
|
|
||||||
renderWithIntl(<ListError {...props} />);
|
|
||||||
const alert = screen.getByRole('alert');
|
|
||||||
expect(alert).toBeInTheDocument();
|
|
||||||
expect(alert).toHaveClass('alert-danger');
|
|
||||||
});
|
});
|
||||||
|
describe('render tests', () => {
|
||||||
it('displays error heading and message', () => {
|
beforeEach(() => {
|
||||||
renderWithIntl(<ListError {...props} />);
|
el = shallow(<ListError {...props} />);
|
||||||
const heading = screen.getByRole('alert').querySelector('.alert-heading');
|
});
|
||||||
expect(heading).toBeInTheDocument();
|
test('snapshot', () => {
|
||||||
expect(heading).toHaveTextContent(messages.loadErrorHeading.defaultMessage);
|
expect(el).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('displays try again button', () => {
|
|
||||||
renderWithIntl(<ListError {...props} />);
|
|
||||||
const button = screen.getByRole('button');
|
|
||||||
expect(button).toBeInTheDocument();
|
|
||||||
expect(button).toHaveClass('btn-primary');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calls initializeApp when try again button is clicked', async () => {
|
|
||||||
renderWithIntl(<ListError {...props} />);
|
|
||||||
const user = userEvent.setup();
|
|
||||||
const button = screen.getByRole('button');
|
|
||||||
await user.click(button);
|
|
||||||
expect(props.initializeApp).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('mapStateToProps', () => {
|
describe('mapStateToProps', () => {
|
||||||
|
let mapped;
|
||||||
const testState = { some: 'test-state' };
|
const testState = { some: 'test-state' };
|
||||||
it('maps courseId from app.courseId selector', () => {
|
beforeEach(() => {
|
||||||
const mapped = mapStateToProps(testState);
|
mapped = mapStateToProps(testState);
|
||||||
|
});
|
||||||
|
test('courseId loads from app.courseId', () => {
|
||||||
expect(mapped.courseId).toEqual(selectors.app.courseId(testState));
|
expect(mapped.courseId).toEqual(selectors.app.courseId(testState));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('mapDispatchToProps', () => {
|
describe('mapDispatchToProps', () => {
|
||||||
it('maps initializeApp from thunkActions.app.initialize', () => {
|
it('loads initializeApp from thunkActions.app.initialize', () => {
|
||||||
expect(mapDispatchToProps.initializeApp).toEqual(
|
expect(mapDispatchToProps.initializeApp).toEqual(thunkActions.app.initialize);
|
||||||
thunkActions.app.initialize,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user