-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
V2 of login prompts for mitx online/edx
- Loading branch information
1 parent
d2e389c
commit 9a78149
Showing
19 changed files
with
263 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ class Meta: | |
'enrolled', | ||
'total_courses', | ||
'topics', | ||
'courseware_backends', | ||
) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* global SETTINGS: false */ | ||
import React, { useState, useEffect } from "react" | ||
import Button from "@material-ui/core/Button" | ||
import Dialog from "@material-ui/core/Dialog" | ||
import DialogActions from "@material-ui/core/DialogActions" | ||
import DialogContent from "@material-ui/core/DialogContent" | ||
import DialogTitle from "@material-ui/core/DialogTitle" | ||
import Grid from "@material-ui/core/Grid" | ||
import R from "ramda" | ||
|
||
import { COURSEWARE_BACKEND_NAMES } from "../constants" | ||
|
||
import type { AvailableProgram } from "../flow/enrollmentTypes" | ||
|
||
type Props = { | ||
currentProgramEnrollment: AvailableProgram | ||
} | ||
|
||
const SocialAuthDialog = (props: Props) => { | ||
const { currentProgramEnrollment } = props | ||
const [open, setOpen] = useState(false) | ||
const missingBackend = R.head( | ||
R.difference( | ||
R.propOr([], "courseware_backends", currentProgramEnrollment), | ||
R.propOr([], "social_auth_providers", SETTINGS.user) | ||
) | ||
) | ||
|
||
useEffect(() => { | ||
setOpen(!R.isNil(currentProgramEnrollment) && !R.isNil(missingBackend)) | ||
}, [currentProgramEnrollment, missingBackend]) | ||
|
||
if (R.isNil(currentProgramEnrollment)) { | ||
return null | ||
} | ||
|
||
return ( | ||
<Dialog | ||
classes={{ | ||
paper: "dialog" | ||
}} | ||
open={open} | ||
onClose={() => setOpen(false)} | ||
> | ||
<DialogTitle className="dialog-title">Action Required</DialogTitle> | ||
<DialogContent> | ||
<Grid container style={{ padding: 20 }}> | ||
<Grid item xs={12}> | ||
<p> | ||
Courses for <strong>{currentProgramEnrollment.title}</strong> are | ||
offered on {COURSEWARE_BACKEND_NAMES[missingBackend]}. Continue to | ||
create a new account and link it to your current MicroMasters | ||
account. | ||
</p> | ||
</Grid> | ||
</Grid> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button | ||
key="cancel" | ||
className="primary-button ok-button" | ||
href={`/login/${missingBackend}/`} | ||
> | ||
Continue to {COURSEWARE_BACKEND_NAMES[missingBackend]} | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
) | ||
} | ||
|
||
export default SocialAuthDialog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// @flow | ||
/* global SETTINGS: false */ | ||
import React from "react" | ||
import { mount } from "enzyme" | ||
import { assert } from "chai" | ||
import Button from "@material-ui/core/Button" | ||
import Grid from "@material-ui/core/Grid" | ||
import { MuiThemeProvider, createMuiTheme } from "@material-ui/core/styles" | ||
|
||
import SocialAuthDialog from "./SocialAuthDialog" | ||
import { COURSEWARE_BACKEND_NAMES } from "../constants" | ||
import { makeAvailableProgram } from "../factories/dashboard" | ||
|
||
import type { AvailableProgram } from "../flow/enrollmentTypes" | ||
|
||
describe("SocialAuthDialog", () => { | ||
const renderDialog = (enrollment: AvailableProgram) => | ||
mount( | ||
<MuiThemeProvider theme={createMuiTheme()}> | ||
<SocialAuthDialog currentProgramEnrollment={enrollment} /> | ||
</MuiThemeProvider> | ||
) | ||
.find(SocialAuthDialog) | ||
.children() | ||
|
||
Object.entries(COURSEWARE_BACKEND_NAMES).forEach( | ||
([missingBackend, backendLabel]) => { | ||
describe(`for missing backend '${missingBackend}'`, () => { | ||
let authenticatedEnrollment, | ||
unauthenticatedEnrollment, | ||
availablePrograms | ||
|
||
beforeEach(() => { | ||
availablePrograms = Object.keys(COURSEWARE_BACKEND_NAMES) | ||
SETTINGS.user.social_auth_providers = availablePrograms.filter( | ||
backend => backend !== missingBackend | ||
) | ||
authenticatedEnrollment = makeAvailableProgram( | ||
undefined, | ||
availablePrograms | ||
) | ||
unauthenticatedEnrollment = makeAvailableProgram( | ||
undefined, | ||
availablePrograms.filter(backend => backend === missingBackend) | ||
) | ||
}) | ||
|
||
it("should be closed if the learner is authenticated with the backend", () => { | ||
SETTINGS.user.social_auth_providers = availablePrograms | ||
const wrapper = renderDialog(authenticatedEnrollment) | ||
assert.isBoolean(wrapper.prop("open")) | ||
assert.notOk(wrapper.prop("open")) | ||
}) | ||
|
||
it("should be open if the learner is not authenticated with the backend", () => { | ||
const wrapper = renderDialog(unauthenticatedEnrollment) | ||
assert.isBoolean(wrapper.prop("open")) | ||
assert.ok(wrapper.prop("open")) | ||
}) | ||
|
||
it("should have a continue button linking to the social auth login url", () => { | ||
const wrapper = renderDialog(unauthenticatedEnrollment) | ||
const btn = wrapper.find(Button) | ||
assert.ok(btn.exists()) | ||
assert.equal(btn.prop("href"), `/login/${missingBackend}/`) | ||
assert.equal(btn.text(), `Continue to ${String(backendLabel)}`) | ||
}) | ||
|
||
it("should have a description of what the learner needs to do", () => { | ||
const wrapper = renderDialog(unauthenticatedEnrollment) | ||
const text = wrapper | ||
.find(Grid) | ||
.at(0) | ||
.text() | ||
assert.equal( | ||
text, | ||
`Courses for ${ | ||
unauthenticatedEnrollment.title | ||
} are offered on ${String( | ||
backendLabel | ||
)}. Continue to create a new account and link it to your current MicroMasters account.` | ||
) | ||
}) | ||
}) | ||
} | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.