Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/javascript/spec/host-edit-form/helper-data.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const samepleInitialValues = {
export const sampleInitialValues = {
id: '1',
name: '10.197.65.254',
hostname: null,
Expand All @@ -7,7 +7,7 @@ export const samepleInitialValues = {
type: 'ManageIQ::Providers::IbmPowerHmc::InfraManager::Host',
};

export const sampleSingleReponse = {
export const sampleSingleResponse = {
data: {
form_schema: {
fields: [
Expand Down
66 changes: 23 additions & 43 deletions app/javascript/spec/host-edit-form/host-edit-form.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,59 @@ import React from 'react';
import toJson from 'enzyme-to-json';
import fetchMock from 'fetch-mock';
import { act } from 'react-dom/test-utils';
import { Button } from 'carbon-components-react';
import HostEditForm from '../../components/host-edit-form/host-edit-form';
import { samepleInitialValues, sampleSingleReponse, sampleMultiResponse } from './helper-data';
import { sampleInitialValues, sampleSingleResponse, sampleMultiResponse } from './helper-data';

import { mount, shallow } from '../helpers/mountForm';
import { mount } from '../helpers/mountForm';
import '../../oldjs/miq_application'; // for miqJqueryRequest
import '../helpers/miqSparkle';

describe('Show Edit Host Form Component', () => {
let submitSpy;

const id = [1];
const ids = [1, 2, 3];

beforeEach(() => {
// fetchMock
// .once('/api/event_streams', sampleReponse);
// submitSpy = jest.spyOn(window, 'miqJqueryRequest');
});

afterEach(() => {
fetchMock.reset();
fetchMock.restore();
// submitSpy.mockRestore();
});

/*
* Render Form
*/

/** Render Form */
it('should render form for *one* host', async(done) => {
let wrapper;
fetchMock
.get(`/api/hosts/${id[0]}?expand=resources&attributes=authentications`, samepleInitialValues)
.mock(`/api/hosts/${id[0]}`, sampleSingleReponse);
await act(async() => {
fetchMock
.get(`/api/hosts/${id[0]}?expand=resources&attributes=authentications`, sampleInitialValues)
.mock(`/api/hosts/${id[0]}`, sampleSingleResponse);
wrapper = mount(<HostEditForm ids={id} />);
});
setImmediate(() => {
wrapper.update();
expect(toJson(wrapper)).toMatchSnapshot();
done();

// Wrap AsyncCredentials updates in act(...)
await act(async() => {
setImmediate(() => {
wrapper.update();
expect(toJson(wrapper)).toMatchSnapshot();
done();
});
});
});

it('should render form for multiple hosts', async(done) => {
let wrapper;
fetchMock.get(`/api/hosts?expand=resources&attributes=id,name&filter[]=id=[${ids}]`, sampleMultiResponse);
await act(async() => {
fetchMock.get(`/api/hosts?expand=resources&attributes=id,name&filter[]=id=[${ids}]`, sampleMultiResponse);
wrapper = mount(<HostEditForm ids={ids} />);
});
setImmediate(() => {
wrapper.update();
expect(toJson(wrapper)).toMatchSnapshot();
done();

// Wrap AsyncCredentials updates in act(...)
await act(async() => {
setImmediate(() => {
wrapper.update();
expect(toJson(wrapper)).toMatchSnapshot();
done();
});
});
});

/*
* Submit Logic
*/

// it('should not submit values when form is empty', async(done) => {
// let wrapper;
// await act(async() => {
// wrapper = mount(<TimelineOptions url="sample/url" />);
// });
// setImmediate(() => {
// wrapper.update();
// expect(wrapper.find(Button)).toHaveLength(1);
// wrapper.find(Button).first().simulate('click');
// expect(submitSpy).toHaveBeenCalledTimes(0);
// done();
// });
// });
});