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

feat: use backend GET endpoint to determine whether to show Learning Assistant #41

Merged

Conversation

MichaelRoytman
Copy link
Member

@MichaelRoytman MichaelRoytman commented Jan 30, 2024

Description

Jira: COSMO-161

Prerequisite: edx/learning-assistant#63 must be merged and deployed before this pull request is merged and deployed.

This commit uses a new GET endpoint published on the Learning Assistant backend to determine whether the Learning Assistant feature is enabled. If the features is not enabled, the Learning Assistant is not rendered, and vice-versa.

This is an alternative to using the edx-platform Courseware API to determine whether the feature is enabled. The reason this decision was made was so as not to introduce 2U-specific code into the platform in the form of calls to the learning-assistant plugin and it's models and APIs. This allows the Learning Assistant frontend to encapsulate calls to the backend instead.

Please see edx/learning-assistant#63 for more details.

Copy link

codecov bot commented Jan 31, 2024

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (7b940f4) 82.35% compared to head (84bbd84) 81.36%.

Files Patch % Lines
src/data/api.js 0.00% 4 Missing ⚠️
src/data/thunks.js 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #41      +/-   ##
==========================================
- Coverage   82.35%   81.36%   -0.99%     
==========================================
  Files          13       13              
  Lines         204      220      +16     
  Branches       27       30       +3     
==========================================
+ Hits          168      179      +11     
- Misses         34       39       +5     
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MichaelRoytman MichaelRoytman force-pushed the michaelroytman/COSMO-161-dont-render-when-disabled branch 2 times, most recently from ad2715e to a070130 Compare January 31, 2024 13:31
…Assistant

This commit uses a new GET endpoint published on the Learning Assistant backend to determine whether the Learning Assistant feature is enabled. If the features is not enabled, the Learning Assistant is not rendered, and vice-versa.

This is an alternative to using the edx-platform Courseware API to determine whether the feature is enabled. The reason this decision was made was so as not to introduce 2U-specific code into the platform in the form of calls to the learning-assistant plugin and it's models and APIs. This allows the Learning Assistant frontend to encapsulate calls to the backend instead.

Please see edx/learning-assistant#63 for more details.
@MichaelRoytman MichaelRoytman force-pushed the michaelroytman/COSMO-161-dont-render-when-disabled branch from a070130 to 84bbd84 Compare January 31, 2024 13:39
const data = await fetchLearningAssistantEnabled(courseId);
dispatch(setIsEnabled(data.enabled));
} catch (error) {
dispatch(setApiError());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was considering ensuring that the Learning Assistant isn't rendered when this API call fails (i.e. adding a condition to the render function), but I don't think it's necessary. If the API calls fails, isEnabled in the Redux store will remain as the default false, so the Learning Assistant won't be rendered.

I could add individual states for the two API calls to be sure I know which API call failed. I'm happy to do that, but I don't feel that it's necessary at this time. Let me know if you disagree.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your approach makes sense to me!

@@ -19,4 +19,12 @@ async function fetchChatResponse(courseId, messageList, unitId) {
return data;
}

async function fetchLearningAssistantEnabled(courseId) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have testing for everything in this repository - just happy path. So I'm okay with these being uncovered. We should probably bump up the test coverage at some point, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense to me.

Copy link
Member

@varshamenon4 varshamenon4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@@ -19,4 +19,12 @@ async function fetchChatResponse(courseId, messageList, unitId) {
return data;
}

async function fetchLearningAssistantEnabled(courseId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense to me.

@@ -12,6 +12,7 @@ export const learningAssistantSlice = createSlice({
conversationId: uuidv4(),
disclosureAcknowledged: false,
sidebarIsOpen: false,
isEnabled: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

const data = await fetchLearningAssistantEnabled(courseId);
dispatch(setIsEnabled(data.enabled));
} catch (error) {
dispatch(setApiError());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your approach makes sense to me!

@@ -76,6 +88,9 @@ test('clicking the call to action opens the sidebar', async () => {

render(<Xpert courseId={courseId} contentToolsEnabled={false} />, { preloadedState: initialState });

// wait for button to appear
await screen.findByTestId('message-button');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[question] so you've just added this check to make sure that the LA is loaded before testing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly! I've added an async API call that must complete before the LA is loaded in this commit, so I have to use async React Testing Library utilities to wait for that API call to complete. Before this change, all the tests would fail 🥲, because the test runner was trying to run the rest of the test (e.g. user actions and assertions) before the mock API call "completed" (i.e. the mock promise resolved). This line tells it to wait by saying something like "wait until you can find this element in the DOM". Once that button is in the DOM, we know that the LA has rendered and we can proceed with the rest of the test.

@MichaelRoytman MichaelRoytman merged commit b20b8c4 into main Feb 7, 2024
4 of 6 checks passed
@MichaelRoytman MichaelRoytman deleted the michaelroytman/COSMO-161-dont-render-when-disabled branch February 7, 2024 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants