Skip to content

Commit 0fefa40

Browse files
committed
update tests to work with extended cdn changes
1 parent 94f0787 commit 0fefa40

File tree

7 files changed

+37
-12
lines changed

7 files changed

+37
-12
lines changed

packages/app/obojobo-repository/server/routes/library.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ jest.mock('../models/collection')
22
jest.mock('../models/draft_summary')
33
jest.mock('obojobo-express/server/models/user')
44
jest.mock('../models/draft_permissions')
5+
jest.mock('../../shared/react-utils')
56
jest.mock('trianglify')
67
jest.unmock('fs') // need fs working for view rendering
78
jest.unmock('express') // we'll use supertest + express for this
@@ -17,14 +18,11 @@ jest.mock(
1718
jest.setTimeout(10000) // extend test timeout?
1819

1920
const publicLibCollectionId = require('../../shared/publicLibCollectionId')
20-
2121
let trianglify
22-
2322
let Collection
2423
let DraftSummary
2524
let UserModel
2625
let DraftPermissions
27-
2826
// override requireCurrentUser for tests to provide our own user
2927
let mockCurrentUser
3028

packages/app/obojobo-repository/shared/components/module-image.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ const clientGlobals = require('../util/client-globals')
55

66
const ModuleImage = props => (
77
<div className="repository--module-icon--image">
8-
<img src={`${clientGlobals.staticAssetUrl}/library/module-icon/${props.id}`} width="100%" height="100%" />
8+
<img
9+
src={`${clientGlobals.staticAssetUrl || ''}/library/module-icon/${props.id}`}
10+
width="100%"
11+
height="100%"
12+
/>
913
</div>
1014
)
1115

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
jest.mock('../../react-utils')
2-
jest.mock('./page-module')
3-
jest.mock('../../reducers/dashboard-reducer')
2+
jest.mock('./page-module-hoc')
3+
jest.mock('../../reducers/about-module-reducer')
44

55
const ReactUtils = require('../../react-utils')
6-
const PageModule = require('./page-module')
6+
const PageModule = require('./page-module-hoc')
7+
const AboutModuleReducer = require('../../reducers/about-module-reducer')
78

89
describe('Client-side Module Page', () => {
910
test('passes the right arguments to ReactUtils.hydrateElWithoutStore', () => {
1011
// just need to require this, it will run itself
1112
require('./page-module-client')
1213

13-
expect(ReactUtils.hydrateElWithoutStore).toHaveBeenCalledWith(PageModule, '#react-hydrate-root')
14+
expect(ReactUtils.hydrateEl).toHaveBeenCalledWith(
15+
PageModule,
16+
AboutModuleReducer,
17+
'#react-hydrate-root'
18+
)
1419
})
1520
})

packages/app/obojobo-repository/shared/components/pages/page-module-hoc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const PageModule = require('./page-module')
22
const connect = require('react-redux').connect
3+
/* istanbul ignore next */
34
const mapStoreStateToProps = state => state
45
module.exports = connect(
56
mapStoreStateToProps,

packages/app/obojobo-repository/shared/react-utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const { middleware } = require('redux-pack')
66
// if initial state contains a globals object, we need to copy
77
// those globals into clientGlobals so that they can be loaded
88
// as global constants anywhere in the application.
9-
function populateClientGlobals(initialState){
10-
if(initialState.globals){
9+
function populateClientGlobals(initialState) {
10+
if (initialState && initialState.globals) {
1111
const clientGlobals = require('../shared/util/client-globals')
1212
for (const property in initialState.globals) {
1313
clientGlobals[property] = initialState.globals[property]

packages/app/obojobo-repository/shared/react-utils.test.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ jest.mock('react-redux', () => ({
55
Provider: jest.fn()
66
}))
77
jest.mock('redux-pack')
8+
jest.mock('../shared/util/client-globals')
89

910
let React
1011
let Redux // { createStore, applyMiddleware }
@@ -32,7 +33,7 @@ describe('react utils', () => {
3233
mockReducerFunction: jest.fn()
3334
}
3435
const mockMiddleware = { middlewareKey: 'middlewareProp' }
35-
const mockStore = { storeKey: 'storeProp' }
36+
const mockStore = { storeKey: 'storeProp', getState: jest.fn().mockReturnValue({}) }
3637

3738
beforeAll(() => {
3839
global.ReactDOM = {
@@ -161,4 +162,18 @@ describe('react utils', () => {
161162
desiredKeyTwo: 'desiredPropTwo'
162163
})
163164
})
165+
166+
test('populateClientGlobals ignores missing globals', () => {
167+
const clientGlobals = require('../shared/util/client-globals')
168+
expect(clientGlobals).not.toHaveProperty('key')
169+
reactUtils.populateClientGlobals({ nonGlobals: { key: 'value' } })
170+
expect(clientGlobals).not.toHaveProperty('key')
171+
})
172+
173+
test('populateClientGlobals registers globals', () => {
174+
const clientGlobals = require('../shared/util/client-globals')
175+
expect(clientGlobals).not.toHaveProperty('key')
176+
reactUtils.populateClientGlobals({ globals: { key: 'value' } })
177+
expect(clientGlobals).toHaveProperty('key', 'value')
178+
})
164179
})

packages/app/obojobo-repository/shared/reducers/about-module-reducer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
function AboutModuleReducer(state, action) {
1+
/* istanbul ignore next */
2+
function AboutModuleReducer(state) {
3+
/* istanbul ignore next */
24
return state
35
}
46

0 commit comments

Comments
 (0)