Skip to content

Commit

Permalink
update tests to work with extended cdn changes
Browse files Browse the repository at this point in the history
  • Loading branch information
iturgeon committed Jan 31, 2022
1 parent 94f0787 commit 0fefa40
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ jest.mock('../models/collection')
jest.mock('../models/draft_summary')
jest.mock('obojobo-express/server/models/user')
jest.mock('../models/draft_permissions')
jest.mock('../../shared/react-utils')
jest.mock('trianglify')
jest.unmock('fs') // need fs working for view rendering
jest.unmock('express') // we'll use supertest + express for this
Expand All @@ -17,14 +18,11 @@ jest.mock(
jest.setTimeout(10000) // extend test timeout?

const publicLibCollectionId = require('../../shared/publicLibCollectionId')

let trianglify

let Collection
let DraftSummary
let UserModel
let DraftPermissions

// override requireCurrentUser for tests to provide our own user
let mockCurrentUser

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ const clientGlobals = require('../util/client-globals')

const ModuleImage = props => (
<div className="repository--module-icon--image">
<img src={`${clientGlobals.staticAssetUrl}/library/module-icon/${props.id}`} width="100%" height="100%" />
<img
src={`${clientGlobals.staticAssetUrl || ''}/library/module-icon/${props.id}`}
width="100%"
height="100%"
/>
</div>
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
jest.mock('../../react-utils')
jest.mock('./page-module')
jest.mock('../../reducers/dashboard-reducer')
jest.mock('./page-module-hoc')
jest.mock('../../reducers/about-module-reducer')

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

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

expect(ReactUtils.hydrateElWithoutStore).toHaveBeenCalledWith(PageModule, '#react-hydrate-root')
expect(ReactUtils.hydrateEl).toHaveBeenCalledWith(
PageModule,
AboutModuleReducer,
'#react-hydrate-root'
)
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const PageModule = require('./page-module')
const connect = require('react-redux').connect
/* istanbul ignore next */
const mapStoreStateToProps = state => state
module.exports = connect(
mapStoreStateToProps,
Expand Down
4 changes: 2 additions & 2 deletions packages/app/obojobo-repository/shared/react-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const { middleware } = require('redux-pack')
// if initial state contains a globals object, we need to copy
// those globals into clientGlobals so that they can be loaded
// as global constants anywhere in the application.
function populateClientGlobals(initialState){
if(initialState.globals){
function populateClientGlobals(initialState) {
if (initialState && initialState.globals) {
const clientGlobals = require('../shared/util/client-globals')
for (const property in initialState.globals) {
clientGlobals[property] = initialState.globals[property]
Expand Down
17 changes: 16 additions & 1 deletion packages/app/obojobo-repository/shared/react-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ jest.mock('react-redux', () => ({
Provider: jest.fn()
}))
jest.mock('redux-pack')
jest.mock('../shared/util/client-globals')

let React
let Redux // { createStore, applyMiddleware }
Expand Down Expand Up @@ -32,7 +33,7 @@ describe('react utils', () => {
mockReducerFunction: jest.fn()
}
const mockMiddleware = { middlewareKey: 'middlewareProp' }
const mockStore = { storeKey: 'storeProp' }
const mockStore = { storeKey: 'storeProp', getState: jest.fn().mockReturnValue({}) }

beforeAll(() => {
global.ReactDOM = {
Expand Down Expand Up @@ -161,4 +162,18 @@ describe('react utils', () => {
desiredKeyTwo: 'desiredPropTwo'
})
})

test('populateClientGlobals ignores missing globals', () => {
const clientGlobals = require('../shared/util/client-globals')
expect(clientGlobals).not.toHaveProperty('key')
reactUtils.populateClientGlobals({ nonGlobals: { key: 'value' } })
expect(clientGlobals).not.toHaveProperty('key')
})

test('populateClientGlobals registers globals', () => {
const clientGlobals = require('../shared/util/client-globals')
expect(clientGlobals).not.toHaveProperty('key')
reactUtils.populateClientGlobals({ globals: { key: 'value' } })
expect(clientGlobals).toHaveProperty('key', 'value')
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
function AboutModuleReducer(state, action) {
/* istanbul ignore next */
function AboutModuleReducer(state) {
/* istanbul ignore next */
return state
}

Expand Down

0 comments on commit 0fefa40

Please sign in to comment.