Skip to content

Commit

Permalink
Merge pull request #1699 from LD4P/thunk2
Browse files Browse the repository at this point in the history
Make ImportResourceTemplate a functional component
  • Loading branch information
justinlittman committed Nov 7, 2019
2 parents 67f999c + 11f8c3b commit 7efadb4
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 471 deletions.
94 changes: 93 additions & 1 deletion __tests__/actionCreators/resourceTemplates.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2019 Stanford University see LICENSE for license

import { fetchResourceTemplate } from 'actionCreators/resourceTemplates'
import {
fetchResourceTemplate, setResourceTemplates, handleUpdateResource,
} from 'actionCreators/resourceTemplates'
/* eslint import/namespace: 'off' */
import * as server from 'sinopiaServer'
import { getFixtureResourceTemplate } from '../fixtureLoaderHelper'
Expand Down Expand Up @@ -63,3 +65,93 @@ describe('fetchResourceTemplate', () => {
})
})
})


describe('setResourceTemplates()', () => {
const profileContent = {
Profile: {
resourceTemplates: [
{
id: 'template1',
},
{
id: 'template2',
},
],
},
}

it('opens the modal if there is a conflict', async () => {
const store = mockStore({
authenticate: { authenticationState: {} },
})
server.createResourceTemplate = jest.fn().mockResolvedValue({ response: { status: 409 } })

await store.dispatch(setResourceTemplates(profileContent, 'ld4p'))

expect(store.getActions()).toEqual([
{
type: 'CLEAR_TEMPLATE_MESSAGES',
},
{
type: 'CLEAR_MODAL_MESSAGES',
},
{
type: 'SHOW_MODAL',
payload: 'UpdateResourceModal',
},
])
})

it('updates the flash messages if they were created', async () => {
const store = mockStore({
authenticate: { authenticationState: {} },
})
server.createResourceTemplate = jest.fn()
.mockResolvedValue({ response: { status: 201, headers: { location: 'http://resource1' } } })

await store.dispatch(setResourceTemplates(profileContent, 'ld4p'))

expect(store.getActions()).toEqual([
{
type: 'CLEAR_TEMPLATE_MESSAGES',
},
{
type: 'CLEAR_MODAL_MESSAGES',
},
{
type: 'SET_TEMPLATE_MESSAGES',
messages: ['Created http://resource1', 'Created http://resource1'],
},
])
})
})

describe('handleUpdateResource()', () => {
const templates = [
{
id: 'template1',
},
{
id: 'template2',
},
]

it('updates every template and sets the flash', async () => {
const store = mockStore({
authenticate: { authenticationState: {} },
})
server.updateResourceTemplate = jest.fn()
.mockResolvedValue({ response: { status: 204, headers: { location: 'http://resource1' } } })

await store.dispatch(handleUpdateResource(templates, 'ld4p'))


expect(store.getActions()).toEqual([
{
type: 'SET_TEMPLATE_MESSAGES',
messages: ['Updated http://resource1', 'Updated http://resource1'],
},
])
})
})
16 changes: 8 additions & 8 deletions __tests__/components/templates/ImportFileZone.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Stanford University see LICENSE for license
// Copyright 2019 Stanford University see LICENSE for license

import 'isomorphic-fetch'
import React from 'react'
Expand All @@ -8,15 +8,15 @@ import Config from 'Config'

describe('<ImportFileZone />', () => {
it('has an upload button', () => {
const wrapper = shallow(<ImportFileZone />)
const wrapper = shallow(<ImportFileZone.WrappedComponent />)

expect(wrapper.find('button#ImportProfile').exists()).toBeTruthy()
expect(wrapper.find('button#ImportProfile').text()).toEqual('Import a Profile or Resource Template')
})

describe('schema valid', () => {
describe('schema url in JSON', () => {
const wrapper = shallow(<ImportFileZone />)
const wrapper = shallow(<ImportFileZone.WrappedComponent />)
let schemaUrl
let template

Expand Down Expand Up @@ -52,7 +52,7 @@ describe('<ImportFileZone />', () => {
})

describe('schema url not in JSON - default schemas used', () => {
const wrapper = shallow(<ImportFileZone />)
const wrapper = shallow(<ImportFileZone.WrappedComponent />)
let schemaUrl
let template

Expand Down Expand Up @@ -89,7 +89,7 @@ describe('<ImportFileZone />', () => {
})

describe('not schema valid', () => {
const wrapper = shallow(<ImportFileZone />)
const wrapper = shallow(<ImportFileZone.WrappedComponent />)
let schemaUrl
let template

Expand Down Expand Up @@ -123,7 +123,7 @@ describe('<ImportFileZone />', () => {
})

describe('unfindable schema', () => {
const wrapper = shallow(<ImportFileZone />)
const wrapper = shallow(<ImportFileZone.WrappedComponent />)
let schemaUrl
let template

Expand All @@ -141,7 +141,7 @@ describe('<ImportFileZone />', () => {
})

describe('unable to read json file as text', () => {
const wrapper = shallow(<ImportFileZone />)
const wrapper = shallow(<ImportFileZone.WrappedComponent />)
const notBlob = {}

it('displays an error message if the loaded file cannot be read as text', () => {
Expand All @@ -153,7 +153,7 @@ describe('<ImportFileZone />', () => {
})

describe('<DropZone />', () => {
const wrapper = mount(<ImportFileZone />)
const wrapper = mount(<ImportFileZone.WrappedComponent />)

it('shows the dropzone div when button is clicked', () => {
wrapper.setState({ showDropZone: false })
Expand Down

0 comments on commit 7efadb4

Please sign in to comment.