Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor and fix flakiness of LibraryAuthoringTest [FC-0062] #1263

Merged
merged 7 commits into from
Sep 10, 2024
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ module.exports = createConfig(
'template-curly-spacing': 'off',
'react-hooks/exhaustive-deps': 'off',
'no-restricted-exports': 'off',
// There is no reason to disallow this syntax anymore; we don't use regenerator-runtime in new browsers
'no-restricted-syntax': 'off',
},
settings: {
// Import URLs should be resolved using aliases
Expand Down
1 change: 0 additions & 1 deletion src/header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/require-default-props */
import React from 'react';
import { getConfig } from '@edx/frontend-platform';
import { useIntl } from '@edx/frontend-platform/i18n';
Expand Down
403 changes: 134 additions & 269 deletions src/library-authoring/LibraryAuthoringPage.test.tsx

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/library-authoring/LibraryAuthoringPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
const navigate = useNavigate();

const { libraryId } = useParams();
if (!libraryId) {
throw new Error('Rendered without libraryId URL parameter');

Check warning on line 123 in src/library-authoring/LibraryAuthoringPage.tsx

View check run for this annotation

Codecov / codecov/patch

src/library-authoring/LibraryAuthoringPage.tsx#L123

Added line #L123 was not covered by tests
}
const { data: libraryData, isLoading } = useContentLibrary(libraryId);

const currentPath = location.pathname.split('/').pop();
Expand All @@ -138,7 +141,7 @@
return <Loading />;
}

if (!libraryId || !libraryData) {
if (!libraryData) {
return <NotFoundAlert />;
}

Expand Down
273 changes: 273 additions & 0 deletions src/library-authoring/__mocks__/library-search.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
{
"comment": "This mock is captured from a real search result and roughly edited to match the mocks in src/library-authoring/data/api.mocks.ts",
"note": "The _formatted fields have been removed from this result and should be re-added programatically when mocking.",
"results": [
{
"indexUid": "studio_content",
"hits": [
{
"id": "lbaximtesthtml571fe018-f3ce-45c9-8f53-5dafcb422fdd-273ebd90",
"display_name": "Introduction to Testing",
"block_id": "571fe018-f3ce-45c9-8f53-5dafcb422fdd",
"content": {
"html_content": "This is a text component which uses HTML."
},
"tags": {},
"type": "library_block",
"breadcrumbs": [
{
"display_name": "Test Library"
}
],
"created": 1721857069.042984,
"modified": 1725398676.078056,
"last_published": 1725035862.450613,
"usage_key": "lb:Axim:TEST:html:571fe018-f3ce-45c9-8f53-5dafcb422fdd",
"block_type": "html",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
},
{
"id": "lbaximtesthtml73a22298-bcd9-4f4c-ae34-0bc2b0612480-46b4a7f2",
"display_name": "Second Text Component",
"block_id": "73a22298-bcd9-4f4c-ae34-0bc2b0612480",
"content": {
"html_content": "Preview of the second text component here"
},
"type": "library_block",
"breadcrumbs": [
{
"display_name": "Test Library"
}
],
"created": 1724879593.066427,
"modified": 1725034981.663482,
"last_published": 1725035862.450613,
"usage_key": "lb:Axim:TEST:html:73a22298-bcd9-4f4c-ae34-0bc2b0612480",
"block_type": "html",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
},
{
"id": "lbaximtesthtmlbe5b5db9-26ba-4fac-86af-654538c70b5e-73dbaa95",
"display_name": "Third Text component",
"block_id": "be5b5db9-26ba-4fac-86af-654538c70b5e",
"content": {
"html_content": "This is a text component that I've edited within the library. "
},
"tags": {},
"type": "library_block",
"breadcrumbs": [
{
"display_name": "Test Library"
}
],
"created": 1721857034.455737,
"modified": 1722551300.377488,
"last_published": 1724879092.002222,
"usage_key": "lb:Axim:TEST:html:be5b5db9-26ba-4fac-86af-654538c70b5e",
"block_type": "html",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
},
{
"id": "lbaximtesthtmle59e8c73-4056-4894-bca4-062781fb3f68-46a404b2",
"display_name": "Text 4",
"block_id": "e59e8c73-4056-4894-bca4-062781fb3f68",
"content": {
"html_content": ""
},
"tags": {},
"type": "library_block",
"breadcrumbs": [
{
"display_name": "Test Library"
}
],
"created": 1720774228.49832,
"modified": 1720774228.49832,
"last_published": 1724879092.002222,
"usage_key": "lb:Axim:TEST:html:e59e8c73-4056-4894-bca4-062781fb3f68",
"block_type": "html",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
},
{
"id": "lbaximtestproblemf16116c9-516e-4bb9-b99e-103599f62417-f2798115",
"display_name": "Blank Problem",
"block_id": "f16116c9-516e-4bb9-b99e-103599f62417",
"content": {
"problem_types": [],
"capa_content": " "
},
"type": "library_block",
"breadcrumbs": [
{
"display_name": "Test Library"
}
],
"created": 1724725821.973896,
"modified": 1724725821.973896,
"last_published": 1724879092.002222,
"usage_key": "lb:Axim:TEST:problem:f16116c9-516e-4bb9-b99e-103599f62417",
"block_type": "problem",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
},
{
"id": "lbaximtestproblem2ace6b9b-6620-413c-a66f-19c797527f34-3a7973b7",
"display_name": "Multiple Choice Problem",
"block_id": "2ace6b9b-6620-413c-a66f-19c797527f34",
"content": {
"problem_types": ["multiplechoiceresponse"],
"capa_content": "What is the gradient of an inverted hyperspace manifold?cos (x) ey ln(z) i + sin(x)ey ln(z)j + sin(x) ey(1/z)k "
},
"tags": {},
"type": "library_block",
"breadcrumbs": [
{
"display_name": "Test Library"
}
],
"created": 1720774232.76135,
"modified": 1720774232.76135,
"last_published": 1724879092.002222,
"usage_key": "lb:Axim:TEST:problem:2ace6b9b-6620-413c-a66f-19c797527f34",
"block_type": "problem",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
},
{
"id": "lbaximtestproblem7d7e98ba-3ac9-4aa8-8946-159129b39a28-3a7973b7",
"display_name": "Single Choice Problem",
"block_id": "7d7e98ba-3ac9-4aa8-8946-159129b39a28",
"content": {
"problem_types": ["choiceresponse"],
"capa_content": "Blah blah?"
},
"tags": {},
"type": "library_block",
"breadcrumbs": [
{
"display_name": "Test Library"
}
],
"created": 1720774232.76135,
"modified": 1720774232.76135,
"last_published": 1724879092.002222,
"usage_key": "lb:Axim:TEST:problem:7d7e98ba-3ac9-4aa8-8946-159129b39a28",
"block_type": "problem",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
},
{
"id": "lbaximtestproblem4e1a72f9-ac93-42aa-a61c-ab5f9698c398-3a7973b7",
"display_name": "Numerical Response Problem",
"block_id": "4e1a72f9-ac93-42aa-a61c-ab5f9698c398",
"content": {
"problem_types": ["numericalresponse"],
"capa_content": "What is 1 + 1?"
},
"tags": {},
"type": "library_block",
"breadcrumbs": [
{
"display_name": "Test Library"
}
],
"created": 1720774232.76135,
"modified": 1720774232.76135,
"last_published": 1724879092.002222,
"usage_key": "lb:Axim:TEST:problem:4e1a72f9-ac93-42aa-a61c-ab5f9698c398",
"block_type": "problem",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
},
{
"id": "lbaximtestproblemad483625-ade2-4712-88d8-c9743abbd291-3a7973b7",
"display_name": "Option Response Problem",
"block_id": "ad483625-ade2-4712-88d8-c9743abbd291",
"content": {
"problem_types": ["optionresponse"],
"capa_content": "What is foobar?"
},
"tags": {},
"type": "library_block",
"breadcrumbs": [
{
"display_name": "Test Library"
}
],
"created": 1720774232.76135,
"modified": 1720774232.76135,
"last_published": 1724879092.002222,
"usage_key": "lb:Axim:TEST:problem:ad483625-ade2-4712-88d8-c9743abbd291",
"block_type": "problem",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
},
{
"id": "lbaximtestproblemb4c859cb-de70-421a-917b-e6e01ce44bd8-3a7973b7",
"display_name": "String Response Problem",
"block_id": "b4c859cb-de70-421a-917b-e6e01ce44bd8",
"content": {
"problem_types": ["stringresponse"],
"capa_content": "What is your name?"
},
"tags": {},
"type": "library_block",
"breadcrumbs": [
{
"display_name": "Test Library"
}
],
"created": 1720774232.76135,
"modified": 1720774232.76135,
"last_published": 1724879092.002222,
"usage_key": "lb:Axim:TEST:problem:b4c859cb-de70-421a-917b-e6e01ce44bd8",
"block_type": "problem",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
}
],
"query": "",
"processingTimeMs": 1,
"limit": 20,
"offset": 0,
"estimatedTotalHits": 10
},
{
"indexUid": "studio_content",
"hits": [],
"query": "",
"processingTimeMs": 0,
"limit": 0,
"offset": 0,
"estimatedTotalHits": 10,
"facetDistribution": {
"block_type": {
"html": 4,
"problem": 6
},
"content.problem_types": {
"multiplechoiceresponse": 1,
"choiceresponse": 1,
"numericalresponse": 1,
"optionresponse": 1,
"stringresponse": 1
}
},
"facetStats": {}
}
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = [
export default [
{
id: '1',
usageKey: 'lb:org:lib:html:1',
displayName: 'Text',
formatted: {
content: {
Expand All @@ -14,6 +15,7 @@ module.exports = [
},
{
id: '2',
usageKey: 'lb:org:lib:html:2',
displayName: 'Text',
formatted: {
content: {
Expand All @@ -27,6 +29,7 @@ module.exports = [
},
{
id: '3',
usageKey: 'lb:org:lib:video:3',
displayName: 'Video',
formatted: {
content: {
Expand All @@ -40,6 +43,7 @@ module.exports = [
},
{
id: '4',
usageKey: 'lb:org:lib:video:4',
displayName: 'Video',
formatted: {
content: {
Expand All @@ -53,6 +57,7 @@ module.exports = [
},
{
id: '5',
usageKey: 'lb:org:lib:problem:5',
displayName: 'Problem',
formatted: {
content: {
Expand All @@ -63,6 +68,7 @@ module.exports = [
},
{
id: '6',
usageKey: 'lb:org:lib:problem:6',
displayName: 'Problem',
formatted: {
content: {
Expand Down
1 change: 0 additions & 1 deletion src/library-authoring/common/context.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/require-default-props */
import React from 'react';

export enum SidebarBodyComponentId {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/require-default-props */
import React from 'react';
import MockAdapter from 'axios-mock-adapter';
import { IntlProvider } from '@edx/frontend-platform/i18n';
Expand Down
1 change: 0 additions & 1 deletion src/library-authoring/components/LibrarySection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/require-default-props */
import React from 'react';
import { Card, ActionRow, Button } from '@openedx/paragon';

Expand Down
Loading