Skip to content

Commit

Permalink
test: refactor and fix flakiness of LibraryAuthoringTest
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Sep 6, 2024
1 parent dcf05cd commit 92e2156
Show file tree
Hide file tree
Showing 9 changed files with 707 additions and 303 deletions.
450 changes: 159 additions & 291 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 LibraryAuthoringPage = () => {
const navigate = useNavigate();

const { libraryId } = useParams();
if (!libraryId) {
throw new Error('Rendered without libraryId URL parameter');
}
const { data: libraryData, isLoading } = useContentLibrary(libraryId);

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

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

Expand Down
File renamed without changes.
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
Loading

0 comments on commit 92e2156

Please sign in to comment.