summaryrefslogtreecommitdiffstats
path: root/TOSCA
AgeCommit message (Expand)AuthorFilesLines
2018-10-03Update Helm plugin type file artifact pathHong Guan1-1/+1
2018-09-19load ONAP TOSCA into controllerjh245g1-2/+5
2018-09-17Upload ONAP TOSCAjh245g6-452/+432
2018-08-27Bootstrap Cloudifyjh245g5-0/+743
2018-08-20helm 2.9.1 from 2.8.2Michael O'Brien1-1/+1
2018-07-24remove proprietary nameJun (Nicolas) Hu8-1350/+0
2018-05-18Add External Interface NBI project into OOM TOSCAHong Guan1-0/+10
2018-05-15Removed 'mock' from TOSCA deploymentHong Guan1-3/+3
2018-05-14Merge "Added license to blueprints and scripts"Jun (Nicolas) Hu8-0/+136
2018-05-14update helm, docker, kubectl versionJun Hu2-5/+22
2018-05-09sync up with helm configuration changesHong Guan1-2/+12
2018-05-02Added license to blueprints and scriptsHong Guan8-0/+136
2018-04-20Enhanced OOM TOSCA solutionHong Guan5-57/+155
2018-03-12Deploy kube2msb along with msb containersHuabingZhao1-10/+0
2018-02-26add tasks to install k8s toolsHong Guan3-0/+85
2018-02-21Update TOSCA licenseJun (Nicolas) Hu13-13/+13
2018-02-15Merge "Install/uninstall helm chart"Mandeep Khinda3-0/+344
2018-02-15Install/uninstall helm chartJun Hu3-0/+344
2018-02-15create K8S cluster by TOSCAJun Hu12-0/+1336
2017-11-21Deploy MR on VM by TOSCAJun Hu2-0/+284
2017-11-21Deploy SO on VMs by TOSCAHong Guan2-0/+320
2017-11-20Deploy appc on VMs by TOSCAHong Guan2-0/+319
2017-11-17Deploy Policy on VMs by TOSCAJun Hu2-0/+291
#003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * ============LICENSE_START=======================================================
 * Copyright (C) 2021 Nordix Foundation.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */
import React from 'react';
import { mount, shallow } from 'enzyme';
import toJson from "enzyme-to-json";
import { act } from "react-dom/test-utils";
import { createMemoryHistory } from "history";
import CommissioningModal from "./CommissioningModal";
import commonProps from "./testFiles/commonProps.json";
import fullTemp from "./testFiles/fullTemplate.json";
import ControlLoopService from "../../../api/ControlLoopService";

let logSpy = jest.spyOn(console, 'log')
const commonProperties = JSON.parse(JSON.stringify(commonProps))
const fullTemplate = JSON.parse(JSON.stringify(fullTemp))
describe('Verify CommissioningModal', () => {

  const unmockedFetch = global.fetch
  beforeAll(() => {
    global.fetch = () =>
      Promise.resolve({
        status: 200,
        text: () => "OK",
        json: () => "{GlobalFetch}"
      })
  })

  afterAll(() => {
    global.fetch = unmockedFetch
  })

  beforeEach(() => {
    logSpy.mockClear()
  })

  it("renders without crashing", () => {
    shallow(<CommissioningModal/>);
  });

  it("renders correctly", () => {
    const tree = shallow(<CommissioningModal/>);
    expect(toJson(tree)).toMatchSnapshot();
  });

  it('should have three Button elements', () => {
    const container = shallow(<CommissioningModal/>)
    expect(container.find('Button').length).toEqual(3);
  });

  it('handleClose called when bottom button clicked', () => {
    const history = createMemoryHistory();
    const component = mount(<CommissioningModal history={ history }/>)
    // const logSpy = jest.spyOn(console, 'log');


    act(() => {
      component.find('[variant="secondary"]').simulate('click');
      expect(logSpy).toHaveBeenCalledWith('handleClose called');
    });

    component.unmount();
  });

  it('handleClose called when top-right button clicked', () => {
    const history = createMemoryHistory();
    const component = mount(<CommissioningModal history={ history }/>)

    act(() => {
      component.find('[size="xl"]').get(0).props.onHide();
      expect(logSpy).toHaveBeenCalledWith('handleClose called');
    });

    component.unmount();
  });

  it('handleSave called when save button clicked', () => {
    const component = shallow(<CommissioningModal/>)
    act(() => {
      component.find('[variant="primary"]').simulate('click');
      expect(logSpy).toHaveBeenCalledWith("handleSave called");
    });
  });

  it('getToscaTemplate gets called in useEffect with error',  async() => {
    const fetchMock = jest.spyOn(ControlLoopService, 'getToscaTemplate').mockImplementation(() => Promise.resolve({
      ok: false,
      status: 200,
      text: () => "OK",
      json: () => fullTemplate
    }))

    mount(<CommissioningModal/>)
    await act(async () => {
      expect(fetchMock).toHaveBeenCalled();
    });
  });

  it('getCommonProperties gets called in useEffect with error',  async() => {
    const fetchMock = jest.spyOn(ControlLoopService, 'getToscaTemplate').mockImplementation(() => Promise.resolve({
      ok: false,
      status: 200,
      text: () => "OK",
      json: () => commonProperties
    }))

    mount(<CommissioningModal/>)
    await act(async () => {
      expect(fetchMock).toHaveBeenCalled();
    });
  });

  it('useState gets called in useEffect with error',  async() => {
    const useStateSpy = jest.spyOn(React, 'useState')
    jest
      .spyOn(global, 'fetch')
      .mockImplementation(() =>
        Promise.resolve({
          ok: false,
          status: 200,
          text: () => "OK",
          json: () => "{useState}"
        })
      )

    mount(<CommissioningModal/>)
    await act(async () => {
      expect(useStateSpy).toHaveBeenCalledTimes(6);
    });
  });

  it('set state gets called for setFullToscaTemplate',  () => {
    const setFullToscaTemplate = jest.fn();
    const history = createMemoryHistory();
    jest
      .spyOn(global, 'fetch')
      .mockImplementation(() =>
        Promise.resolve({
          ok: true,
          status: 200,
          text: () => "OK",
          json: () => fullTemplate
        })
      )

    mount(<CommissioningModal history={ history }/>)
    act(async () => {
      // expect(renderJsonEditor).toHaveBeenCalled();
      expect(setFullToscaTemplate).toHaveBeenCalledTimes(1);
    });
  });

  it('set state gets called for setToscaJsonSchema useEffect on success',  () => {
    const setToscaJsonEditor = jest.fn();
    const history = createMemoryHistory();
    jest
      .spyOn(global, 'fetch')
      .mockImplementation(() =>
        Promise.resolve({
          ok: true,
          status: 200,
          text: () => "OK",
          json: () => fullTemplate
        })
      )

    mount(<CommissioningModal history={ history }/>)
    act(async () => {
      // expect(renderJsonEditor).toHaveBeenCalled();
      expect(setToscaJsonEditor).toHaveBeenCalledTimes(1);
    });
  });

  it('Check useEffect is being called', async () => {
    const useEffect = jest.spyOn(React, "useEffect");
    mount(<CommissioningModal/>)
    await act(async () => {
      expect(useEffect).toHaveBeenCalled();
    })
  });

  it('test handleCommission called on click', async () => {
    const deleteToscaTemplateSpy = jest.spyOn(ControlLoopService, 'deleteToscaTemplate').mockImplementation(() => {
      Promise.resolve({
        ok: true,
        status: 200,
        text: () => "OK",
        json: () => "{handleCommissioning}"
      })
    })
    const uploadToscaTemplateSpy = jest.spyOn(ControlLoopService, 'uploadToscaFile').mockImplementation(() => {
      Promise.resolve({
        ok: true,
        status: 200,
        text: () => "OK",
        json: () => "{uploadToscaFile}"
      })
    })


    const useStateSpy = jest.spyOn(React, 'useState')

    const component = shallow(<CommissioningModal/>)
    component.find('[variant="success mr-auto"]').simulate('click');

    await act( async () => {
      expect(logSpy).toHaveBeenCalledWith("handleCommission called")
      expect(await deleteToscaTemplateSpy).toHaveBeenCalled()
      expect(await uploadToscaTemplateSpy).toHaveBeenCalled()
      expect(logSpy).toHaveBeenCalledWith("receiveResponseFromCommissioning called")
      expect(useStateSpy).toHaveBeenCalled()
    })
  })
});