-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,477 additions
and
826 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
42 changes: 42 additions & 0 deletions
42
src/containers/EnterpriseDashboardModal/__snapshots__/index.test.jsx.snap
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,42 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EnterpriseDashboard empty snapshot 1`] = `null`; | ||
|
||
exports[`EnterpriseDashboard snapshot 1`] = ` | ||
<ModalDialog | ||
hasCloseButton={false} | ||
onClose={[MockFunction useEnterpriseDashboardHook.handleEscape]} | ||
title="" | ||
> | ||
<div | ||
className="bg-white p-3 rounded shadow" | ||
style={ | ||
{ | ||
"textAlign": "start", | ||
} | ||
} | ||
> | ||
<h4> | ||
You have access to the edX, Inc. dashboard | ||
</h4> | ||
<p> | ||
To access the courses available to you through edX, Inc., visit the edX, Inc. dashboard now. | ||
</p> | ||
<ActionRow> | ||
<Button | ||
onClick={[MockFunction useEnterpriseDashboardHook.handleClose]} | ||
variant="tertiary" | ||
> | ||
Dismiss | ||
</Button> | ||
<Button | ||
href="/edx-dashboard" | ||
onClick={[MockFunction useEnterpriseDashboardHook.handleCTAClick]} | ||
type="a" | ||
> | ||
Go to dashboard | ||
</Button> | ||
</ActionRow> | ||
</div> | ||
</ModalDialog> | ||
`; |
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,48 @@ | ||
import React from 'react'; | ||
|
||
import { StrictDict } from 'utils'; | ||
import track from 'tracking'; | ||
import { reduxHooks } from 'hooks'; | ||
|
||
import * as module from './hooks'; | ||
|
||
export const state = StrictDict({ | ||
showModal: (val) => React.useState(val), // eslint-disable-line | ||
}); | ||
|
||
const { modalOpened, modalClosed, modalCTAClicked } = track.enterpriseDashboard; | ||
|
||
export const useEnterpriseDashboardHook = () => { | ||
const [showModal, setShowModal] = module.state.showModal(true); | ||
const dashboard = reduxHooks.useEnterpriseDashboardData(); | ||
|
||
const trackOpened = modalOpened(dashboard.enterpriseUUID); | ||
const trackClose = modalClosed(dashboard.enterpriseUUID, 'Cancel button'); | ||
const trackEscape = modalClosed(dashboard.enterpriseUUID, 'Escape'); | ||
|
||
const handleCTAClick = modalCTAClicked(dashboard.enterpriseUUID, dashboard.url); | ||
const handleClose = () => { | ||
trackClose(); | ||
setShowModal(false); | ||
}; | ||
const handleEscape = () => { | ||
trackEscape(); | ||
setShowModal(false); | ||
}; | ||
|
||
React.useEffect(() => { | ||
if (dashboard && dashboard.label) { | ||
trackOpened(); | ||
} | ||
}, []); // eslint-disable-line | ||
|
||
return { | ||
showModal, | ||
handleCTAClick, | ||
handleClose, | ||
handleEscape, | ||
dashboard, | ||
}; | ||
}; | ||
|
||
export default useEnterpriseDashboardHook; |
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,75 @@ | ||
import { MockUseState } from 'testUtils'; | ||
import { reduxHooks } from 'hooks'; | ||
import track from 'tracking'; | ||
|
||
import * as hooks from './hooks'; | ||
|
||
jest.mock('hooks', () => ({ | ||
reduxHooks: { | ||
useEnterpriseDashboardData: jest.fn(), | ||
}, | ||
})); | ||
jest.mock('tracking', () => { | ||
const modalOpenedEvent = jest.fn(); | ||
const modalClosedEvent = jest.fn(); | ||
const modalCTAClickedEvent = jest.fn(); | ||
return { | ||
__esModule: true, | ||
default: { | ||
enterpriseDashboard: { | ||
modalOpenedEvent, | ||
modalClosedEvent, | ||
modalCTAClickedEvent, | ||
modalOpened: jest.fn(() => modalOpenedEvent), | ||
modalClosed: jest.fn(() => modalClosedEvent), | ||
modalCTAClicked: jest.fn(() => modalCTAClickedEvent), | ||
}, | ||
}, | ||
}; | ||
}); | ||
|
||
const state = new MockUseState(hooks); | ||
|
||
const enterpriseDashboardData = { label: 'edX, Inc.', url: '/edx-dashboard' }; | ||
|
||
describe('EnterpriseDashboard hooks', () => { | ||
reduxHooks.useEnterpriseDashboardData.mockReturnValue({ ...enterpriseDashboardData }); | ||
|
||
describe('state values', () => { | ||
state.testGetter(state.keys.showModal); | ||
}); | ||
|
||
describe('behavior', () => { | ||
let out; | ||
|
||
beforeEach(() => { | ||
state.mock(); | ||
out = hooks.useEnterpriseDashboardHook(); | ||
}); | ||
afterEach(state.restore); | ||
|
||
test('useEnterpriseDashboardHook to return dashboard data from redux hooks', () => { | ||
expect(out.dashboard).toMatchObject(enterpriseDashboardData); | ||
}); | ||
|
||
test('modal initializes to shown when rendered and closes on click', () => { | ||
state.expectInitializedWith(state.keys.showModal, true); | ||
out.handleClose(); | ||
expect(state.values.showModal).toEqual(false); | ||
}); | ||
|
||
test('modal initializes to shown when rendered and closes on escape', () => { | ||
state.expectInitializedWith(state.keys.showModal, true); | ||
out.handleEscape(); | ||
expect(state.values.showModal).toEqual(false); | ||
}); | ||
|
||
test('CTA click tracks modalCTAClicked', () => { | ||
out.handleCTAClick(); | ||
expect(track.enterpriseDashboard.modalCTAClicked).toHaveBeenCalledWith( | ||
enterpriseDashboardData.enterpriseUUID, | ||
enterpriseDashboardData.url, | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.