From 91a3d85ab8f6b87c2b8dc6dbd919304a9103b77c Mon Sep 17 00:00:00 2001 From: Aaron Shafovaloff Date: Fri, 24 Jan 2025 10:10:41 -0700 Subject: [PATCH] stabilize index.test.lsx in MasteryCalculation Change-Id: I9b9b1b8b939b57695269354cdb553172b1ea2aef --- .../__tests__/index.test.jsx | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/ui/features/outcome_management/react/MasteryCalculation/__tests__/index.test.jsx b/ui/features/outcome_management/react/MasteryCalculation/__tests__/index.test.jsx index ed25f9816db24..633ac0df60439 100644 --- a/ui/features/outcome_management/react/MasteryCalculation/__tests__/index.test.jsx +++ b/ui/features/outcome_management/react/MasteryCalculation/__tests__/index.test.jsx @@ -19,6 +19,8 @@ import React from 'react' import {act, render as rtlRender, waitFor, fireEvent} from '@testing-library/react' import {MockedProvider} from '@apollo/client/testing' +import {http} from 'msw' +import {setupServer} from 'msw/node' import OutcomesContext from '@canvas/outcomes/react/contexts/OutcomesContext' import { ACCOUNT_OUTCOME_CALCULATION_QUERY, @@ -29,7 +31,19 @@ import {masteryCalculationGraphqlMocks} from '@canvas/outcomes/mocks/Outcomes' jest.useFakeTimers() +const server = setupServer() + describe('MasteryCalculation', () => { + beforeAll(() => { + server.listen({ + onUnhandledRequest: 'error', + }) + }) + + afterAll(() => { + server.close() + }) + beforeEach(() => { window.ENV = { PROFICIENCY_CALCULATION_METHOD_ENABLED_ROLES: [ @@ -56,6 +70,7 @@ describe('MasteryCalculation', () => { afterEach(() => { window.ENV = null + server.resetHandlers() }) const render = ( @@ -71,6 +86,17 @@ describe('MasteryCalculation', () => { ) } + function setupSubmissionHandler(contextType, contextId, payload) { + server.use( + http.post(`/${contextType.toLowerCase()}s/${contextId}/outcome_calculation_method`, async ({request}) => { + const formData = await request.formData() + return new Response(JSON.stringify(payload), { + headers: {'Content-Type': 'application/json'}, + }) + }) + ) + } + it('loads proficiency data for Account', async () => { const {getByDisplayValue} = render() await act(async () => jest.runAllTimers()) @@ -78,6 +104,11 @@ describe('MasteryCalculation', () => { }) it('loads calculation data for Course', async () => { + setupSubmissionHandler('Course', '12', { + calculation_method: 'decaying_average', + calculation_int: 65, + }) + const {findByDisplayValue} = render(, { contextType: 'Course', contextId: '12', @@ -165,6 +196,14 @@ describe('MasteryCalculation', () => { result: updateCall, }, ] + + beforeEach(() => { + setupSubmissionHandler('Account', '11', { + calculation_method: variables.calculationMethod, + calculation_int: variables.calculationInt, + }) + }) + it('submits a request when calculation method is saved', async () => { const {getByText, findByLabelText} = render(, {mocks: updateMocks}) await act(async () => jest.runAllTimers())