-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from edx/azan/PROD-2394
refactor: self-contain license component
- Loading branch information
Showing
6 changed files
with
55 additions
and
35 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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { mount } from 'enzyme'; | ||
import React from 'react'; | ||
|
||
import { waitForComponentToPaint } from '../../setupTest'; | ||
import * as api from '../data/api'; | ||
import Licenses from './Licenses'; | ||
import licensesData from '../data/test/licenses'; | ||
import UserMessagesProvider from '../../userMessages/UserMessagesProvider'; | ||
|
@@ -13,23 +14,46 @@ const LicensesPageWrapper = (props) => ( | |
|
||
describe('User Licenses Listing', () => { | ||
let wrapper; | ||
const props = { | ||
userEmail: '[email protected]', | ||
expanded: true, | ||
}; | ||
|
||
beforeEach(() => { | ||
wrapper = mount(<LicensesPageWrapper {...licensesData} />); | ||
afterEach(() => { | ||
wrapper.unmount(); | ||
}); | ||
|
||
it('default collapsible with enrollment data', () => { | ||
it('License Data Loading', async () => { | ||
const licenseData = { ...licensesData, results: [], status: 'No record found' }; | ||
jest.spyOn(api, 'getLicense').mockImplementationOnce(() => Promise.resolve(licenseData)); | ||
|
||
wrapper = mount(<LicensesPageWrapper {...props} />); | ||
const collapsible = wrapper.find('CollapsibleAdvanced').find('.collapsible-trigger').hostNodes(); | ||
expect(collapsible.text()).toEqual('Licenses (2)'); | ||
expect(collapsible.text()).toEqual('Licenses (0)Fetch Status: Loading...'); | ||
}); | ||
|
||
it('No License Data', () => { | ||
const licenseData = { ...licensesData, data: [], status: 'No record found' }; | ||
wrapper = mount(<Licenses {...licenseData} />); | ||
it('No License Data', async () => { | ||
const licenseData = { ...licensesData, results: [], status: 'No record found' }; | ||
jest.spyOn(api, 'getLicense').mockImplementationOnce(() => Promise.resolve(licenseData)); | ||
|
||
wrapper = mount(<LicensesPageWrapper {...props} />); | ||
await waitForComponentToPaint(wrapper); | ||
|
||
const collapsible = wrapper.find('CollapsibleAdvanced').find('.collapsible-trigger').hostNodes(); | ||
expect(collapsible.text()).toEqual('Licenses (0)Fetch Status: No record found'); | ||
}); | ||
|
||
beforeEach(async () => { | ||
jest.spyOn(api, 'getLicense').mockImplementationOnce(() => Promise.resolve(licensesData)); | ||
wrapper = mount(<LicensesPageWrapper {...props} />); | ||
await waitForComponentToPaint(wrapper); | ||
}); | ||
|
||
it('default collapsible with enrollment data', () => { | ||
const collapsible = wrapper.find('CollapsibleAdvanced').find('.collapsible-trigger').hostNodes(); | ||
expect(collapsible.text()).toEqual('Licenses (2)'); | ||
}); | ||
|
||
it('Sorting Columns Button Enabled by default', () => { | ||
const dataTable = wrapper.find('table.table'); | ||
const tableHeaders = dataTable.find('thead tr th'); | ||
|
@@ -56,6 +80,6 @@ describe('User Licenses Listing', () => { | |
it('Table Header Lenght', () => { | ||
const dataTable = wrapper.find('table.table'); | ||
const tableHeaders = dataTable.find('thead tr th'); | ||
expect(tableHeaders).toHaveLength(Object.keys(licensesData.data[0]).length); | ||
expect(tableHeaders).toHaveLength(Object.keys(licensesData.results[0]).length); | ||
}); | ||
}); |