From 0b2b11bad1457e7f388ab2a99af6ebf231e862e3 Mon Sep 17 00:00:00 2001 From: Steve Thomas Date: Thu, 29 Mar 2018 14:41:43 -0400 Subject: increasing test coverage to 10% Issue-ID: AAI-980 Change-Id: Idb816df11fa14b5668349f24bac1aafd7235e00a Signed-off-by: Steven Thomas --- test/components/dateRange.test.js | 259 ------------------- test/components/dateRangeSelector.test.js | 303 ----------------------- test/components/inlineMessage.test.js | 90 ------- test/components/notificationReducer.test.js | 108 -------- test/components/toggleButtonGroupReducer.test.js | 41 --- 5 files changed, 801 deletions(-) delete mode 100644 test/components/dateRange.test.js delete mode 100644 test/components/dateRangeSelector.test.js delete mode 100644 test/components/inlineMessage.test.js delete mode 100644 test/components/notificationReducer.test.js delete mode 100644 test/components/toggleButtonGroupReducer.test.js (limited to 'test/components') diff --git a/test/components/dateRange.test.js b/test/components/dateRange.test.js deleted file mode 100644 index 161a57a..0000000 --- a/test/components/dateRange.test.js +++ /dev/null @@ -1,259 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ -import React from 'react'; -import TestUtils from 'react-dom/test-utils'; -import {Provider} from 'react-redux'; -import {expect} from 'chai'; -import i18n from 'utils/i18n/i18n'; - -import store from 'app/AppStore.js'; -import DateRange from 'generic-components/dateRange/DateRange.jsx'; -import { - dateRangeActionTypes, - LABEL_START_DATE, - LABEL_END_DATE, - DATE_PICKER_PLACEHOLDER, - IS_AFTER_END_DATE, - IS_BEFORE_START_DATE, - END_DATE, - START_DATE} from 'generic-components/dateRange/DateRangeConstants.js'; -import DateRangeActions from 'generic-components/dateRange/DateRangeActions.js'; -import reducer from 'generic-components/dateRange/DateRangeReducer.js'; -import sinon from 'sinon'; - -import { moment } from 'moment'; - -describe('Core Date Range suite', function() { - - beforeEach(function() { - this.component = TestUtils.renderIntoDocument(); - }); - - // test structure - it('Date Range - Validate start & end lables', function() { - let labels = TestUtils.scryRenderedDOMComponentsWithTag(this.component, 'label'); - expect(labels.length).to.equal(2); - expect(labels[0].textContent).to.equal(LABEL_START_DATE + ': '); - expect(labels[1].textContent).to.equal(LABEL_END_DATE + ': '); - }); - - it('Date Range - Start Date Picker exists', function() { - let datePicker = TestUtils.findRenderedDOMComponentWithClass(this.component, 'start-date-picker'); - expect(datePicker).to.exist; - expect(datePicker.type).to.equal('text'); - expect(datePicker.placeholder).to.equal(DATE_PICKER_PLACEHOLDER); - }); - - it('Date Range - End Date Picker exists', function() { - let datePicker = TestUtils.findRenderedDOMComponentWithClass(this.component, 'end-date-picker'); - expect(datePicker).to.exist; - expect(datePicker.type).to.equal('text'); - expect(datePicker.placeholder).to.equal(DATE_PICKER_PLACEHOLDER); - }); - - // Reducer Tests - it('Date Range Reducer ... set start date (no initial dates)', function() { - var moment = require('moment'); - const initialState = {}; - const dateChangeAction = {type: dateRangeActionTypes.DATE_RANGE_CHANGE, data: {dateRange: {startDate: moment(new Date('05/04/2016'))}, errorMsg: ''}}; - const newState = reducer(initialState, dateChangeAction); - expect(newState.dateRangeStart).to.exist; - expect(newState.dateRangeStart.toDate().getTime()).to.equal(new Date('05/04/2016').getTime()); - expect(newState.dateRangeEnd).to.not.exist; - expect(newState.dateRangeError).to.equal(''); - }); - it('Date Range Reducer ... update start date (no end date)', function() { - var moment = require('moment'); - const initialStartDate = new Date('05/01/2016'); - const initialState = {dateRange: {startDate: moment(initialStartDate)}}; - const dateChangeAction = {type: dateRangeActionTypes.DATE_RANGE_CHANGE, data: {dateRange: {startDate: moment(new Date('05/04/2016'))}, errorMsg: ''}}; - const newState = reducer(initialState, dateChangeAction); - expect(newState.dateRangeStart).to.exist; - expect(newState.dateRangeStart.toDate().getTime()).to.equal(new Date('05/04/2016').getTime()); - expect(newState.dateRangeEnd).to.not.exist; - expect(newState.dateRangeError).to.equal(''); - }); - it('Date Range Reducer - set end date (no start date)', function() { - var moment = require('moment'); - const initialState = {}; - const dateChangeAction = {type: dateRangeActionTypes.DATE_RANGE_CHANGE, data: {dateRange: {endDate: moment(new Date('05/04/2016'))}, errorMsg: ''}}; - const newState = reducer(initialState, dateChangeAction); - expect(newState.dateRangeEnd).to.exist; - expect(newState.dateRangeEnd.toDate().getTime()).to.equal(new Date('05/04/2016').getTime()); - expect(newState.dateRangeStart).to.not.exist; - expect(newState.dateRangeError).to.equal(''); - }); - it('Date Range Reducer - update end date (no start date)', function() { - var moment = require('moment'); - const initialEndDate = new Date('05/01/2016'); - const initialState = {dateRange: {endDate: moment(initialEndDate)}}; - const dateChangeAction = {type: dateRangeActionTypes.DATE_RANGE_CHANGE, data: {dateRange: {endDate: moment(new Date('05/04/2016'))}, errorMsg: ''}}; - const newState = reducer(initialState, dateChangeAction); - expect(newState.dateRangeEnd).to.exist; - expect(newState.dateRangeEnd.toDate().getTime()).to.equal(new Date('05/04/2016').getTime()); - expect(newState.dateRangeStart).to.not.exist; - expect(newState.dateRangeError).to.equal(''); - }); - it('Date Range Reducer - set end date with initial start date', function() { - var moment = require('moment'); - const initialStartDate = new Date('05/01/2016'); - const initialState = {dateRange: {startDate: moment(initialStartDate)}}; - const dateChangeAction = {type: dateRangeActionTypes.DATE_RANGE_CHANGE, data: {dateRange: {startDate: moment(new Date('05/01/2016')), endDate: moment(new Date('05/04/2016'))}, errorMsg: ''}}; - const newState = reducer(initialState, dateChangeAction); - expect(newState.dateRangeStart).to.exist; - expect(newState.dateRangeStart.toDate().getTime()).to.equal(new Date('05/01/2016').getTime()); - expect(newState.dateRangeEnd).to.exist; - expect(newState.dateRangeEnd.toDate().getTime()).to.equal(new Date('05/04/2016').getTime()); - expect(newState.dateRangeError).to.equal(''); - }); - it('Date Range Reducer - set start date with initial end date', function() { - var moment = require('moment'); - const initialEndDate = new Date('05/04/2016'); - const initialState = {dateRange: {endDate: moment(initialEndDate)}}; - const dateChangeAction = {type: dateRangeActionTypes.DATE_RANGE_CHANGE, data: {dateRange: {startDate: moment(new Date('05/01/2016')), endDate: moment(new Date('05/04/2016'))}, errorMsg: ''}}; - const newState = reducer(initialState, dateChangeAction); - expect(newState.dateRangeStart).to.exist; - expect(newState.dateRangeStart.toDate().getTime()).to.equal(new Date('05/01/2016').getTime()); - expect(newState.dateRangeEnd).to.exist; - expect(newState.dateRangeEnd.toDate().getTime()).to.equal(new Date('05/04/2016').getTime()); - expect(newState.dateRangeError).to.equal(''); - }); - it('Date Range Reducer - verify INVALID_DATE_RANGE event', function() { - var moment = require('moment'); - const errMsg = 'Some error message'; - const initialEndDate = new Date('05/01/2016'); - const initialStartDate = new Date('05/02/2016'); - const initialState = {startDate: moment(initialStartDate), endDate: moment(initialEndDate)}; - const invalidRangeAction = {type: dateRangeActionTypes.INVALID_DATE_RANGE, data: {dateRange: {startDate: moment(initialStartDate), endDate: moment(initialEndDate)}, errorMsg: errMsg}}; - const newState = reducer(initialState, invalidRangeAction); - expect(newState.endDate.toDate().getTime()).to.equal(new Date('05/01/2016').getTime()); - expect(newState.startDate.toDate().getTime()).to.equal(new Date('05/02/2016').getTime()); - expect(newState.dateRangeError).to.equal(errMsg); - }); - - // test Actions - it('Date Range Action - valid start date change', function() { - var moment = require('moment'); - const startDate = moment(new Date('07/19/2016')); - const endDate = moment(new Date('07/20/2016')); - const expectedAction = { - type: dateRangeActionTypes.DATE_RANGE_CHANGE, - data: { - dateRange: { - startDate: startDate, - endDate: endDate - }, - } - - }; - const results = DateRangeActions.onStartDateChange(startDate, endDate); - - expect(results.type).to.equal(expectedAction.type); - expect(results.data.dateRange.startDate).to.equal(expectedAction.data.dateRange.startDate); - expect(results.data.dateRange.endDate).to.equal(expectedAction.data.dateRange.endDate); - }); - it('Date Range Action - valid end date change', function() { - var moment = require('moment'); - const startDate = moment(new Date('07/19/2016')); - const endDate = moment(new Date('07/20/2016')); - const expectedAction = { - type: dateRangeActionTypes.DATE_RANGE_CHANGE, - data: { - dateRange: { - startDate: startDate, - endDate: endDate - }, - } - - }; - const results = DateRangeActions.onEndDateChange(startDate, endDate); - - expect(results.type).to.equal(expectedAction.type); - expect(results.data.dateRange.startDate).to.equal(expectedAction.data.dateRange.startDate); - expect(results.data.dateRange.endDate).to.equal(expectedAction.data.dateRange.endDate); - }); - it('Date Range Action - end date before start date', function() { - var moment = require('moment'); - const startDate = moment(new Date('07/21/2016')); - const endDate = moment(new Date('07/20/2016')); - const errorMsg = i18n(END_DATE) + ': ' + - moment(new Date(endDate)).format(DATE_PICKER_PLACEHOLDER) + - ' ' + i18n(IS_BEFORE_START_DATE); - const expectedAction = { - type: dateRangeActionTypes.INVALID_DATE_RANGE, - data: { - dateRange: { - startDate: startDate, - endDate: endDate - }, - errorMsg: errorMsg - } - - }; - const results = DateRangeActions.onEndDateChange(startDate, endDate); - - expect(results.type).to.equal(expectedAction.type); - expect(results.data.dateRange.startDate).to.equal(expectedAction.data.dateRange.startDate); - expect(results.data.dateRange.endDate).to.equal(expectedAction.data.dateRange.endDate); - expect(results.data.errorMsg).to.equal(expectedAction.data.errorMsg); - }); - it('Date Range Action - start date after date', function() { - var moment = require('moment'); - const startDate = moment(new Date('07/21/2016')); - const endDate = moment(new Date('07/20/2016')); - const errorMsg = i18n(START_DATE) + ': ' + - moment(new Date(startDate)).format(DATE_PICKER_PLACEHOLDER) + - ' ' + i18n(IS_AFTER_END_DATE); - const expectedAction = { - type: dateRangeActionTypes.INVALID_DATE_RANGE, - data: { - dateRange: { - startDate: startDate, - endDate: endDate - }, - errorMsg: errorMsg - } - - }; - const results = DateRangeActions.onStartDateChange(startDate, endDate); - - expect(results.type).to.equal(expectedAction.type); - expect(results.data.dateRange.startDate).to.equal(expectedAction.data.dateRange.startDate); - expect(results.data.dateRange.endDate).to.equal(expectedAction.data.dateRange.endDate); - expect(results.data.errorMsg).to.equal(expectedAction.data.errorMsg); - }); - it('Date Range Action - confirm onStartDateChange action called on startDate change', function() { - const spy = sinon.spy(DateRangeActions, 'onStartDateChange'); - let startDatePicker = TestUtils.findRenderedDOMComponentWithClass(this.component, 'start-date-picker'); - startDatePicker.value = '05/09/2016'; - TestUtils.Simulate.change(startDatePicker); - expect(DateRangeActions.onStartDateChange.calledOnce).to.be.true; - DateRangeActions.onStartDateChange.restore(); - }); - it('Date Range Action - confirm onEndDateChange action called on endDate change', function() { - const spy = sinon.spy(DateRangeActions, 'onEndDateChange'); - let endDatePicker = TestUtils.findRenderedDOMComponentWithClass(this.component, 'end-date-picker'); - endDatePicker.value = '05/09/2016'; - TestUtils.Simulate.change(endDatePicker); - expect(DateRangeActions.onEndDateChange.calledOnce).to.be.true; - DateRangeActions.onEndDateChange.restore(); - }); -}); diff --git a/test/components/dateRangeSelector.test.js b/test/components/dateRangeSelector.test.js deleted file mode 100644 index 134d6c6..0000000 --- a/test/components/dateRangeSelector.test.js +++ /dev/null @@ -1,303 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ -import React from "react"; -import TestUtils from "react-dom/test-utils"; -import {Provider} from "react-redux"; -import {expect} from "chai"; -import {moment} from "moment"; -import store from "app/AppStore.js"; -import DateRangeSelector from "generic-components/dateRangeSelector/DateRangeSelector.jsx"; -import DateRangeSelectorActions from "generic-components/dateRangeSelector/DateRangeSelectorActions.js"; -import { - dateRangeSelectorActionTypes, - TODAY, - YESTERDAY, - LAST_WEEK, - LAST_MONTH, - CUSTOM, - ICON_CLASS_CALENDAR, - ICON_CLASS_DOWN_CARET, - ERROR_UNKNOWN_PERIOD} from "generic-components/dateRangeSelector/DateRangeSelectorConstants.js"; -import reducer from "generic-components/dateRangeSelector/DateRangeSelectorReducer.js"; -import {dateRangeActionTypes, DATE_PICKER_PLACEHOLDER} from "generic-components/dateRange/DateRangeConstants.js"; -import {MESSAGE_LEVEL_DANGER} from "utils/GlobalConstants.js"; - -describe("Date Range Selector Test Suite", function() { - - beforeEach(function () { - this.component = TestUtils.renderIntoDocument( ); - }); - - // test structure - it("Date Range Selector - Validate selector button", function () { - var moment = require('moment'); - let currentDate = moment(new Date()).format(DATE_PICKER_PLACEHOLDER); - let button = TestUtils.findRenderedDOMComponentWithTag(this.component, 'button'); - expect(button).exists; - expect(button.childNodes.length).to.equal(3); - expect(button.childNodes[0].className).to.have.string(ICON_CLASS_CALENDAR); - expect(button.childNodes[1].innerHTML).to.have.string(currentDate + ' - ' + currentDate); - expect(button.childNodes[2].className).to.have.string(ICON_CLASS_DOWN_CARET); - }); - - it("Date Range Selector - Validate quick pick options", function () { - let button = TestUtils.findRenderedDOMComponentWithTag(this.component, 'button'); - TestUtils.Simulate.click(button); - - let popoverMenu = document.body.getElementsByClassName('popover-content'); - // TODO - need to figure out how to get the popover menu (above doesn't work) - }); - - // test reducer - it("Date Range Selector Reducer ... Vaidate DATE_RANGE_CHANGE event)", function() { - var moment = require('moment'); - const initialState = { - startDate: moment(new Date('07/20/2016')), - endDate: moment(new Date('07/09/2016')), - period: CUSTOM, - periodErrText: 'some error text', - periodErrSev: 'some error severity' - }; - const rangeChangeAction = { - type: dateRangeActionTypes.DATE_RANGE_CHANGE, - data: { - dateRange: { - startDate: moment(new Date('05/04/2016')), - endDate: moment(new Date('06/05/2016')) - }, - errorMsg: '' - }}; - const newState = reducer(initialState, rangeChangeAction); - expect(newState.startDate).to.exist; - expect(newState.startDate.toDate().getTime()).to.equal(new Date('05/04/2016').getTime()); - expect(newState.endDate).to.exist; - expect(newState.endDate.toDate().getTime()).to.equal(new Date('06/05/2016').getTime()); - expect(newState.period).to.equal(CUSTOM); - expect(newState.periodErrText).to.equal(''); - expect(newState.periodErrSev).to.equal(''); - }); - it("Date Range Selector Reducer ... Vaidate INVALID_DATE_RANGE event)", function() { - var moment = require('moment'); - const initialState = {}; - const rangeChangeAction = { - type: dateRangeActionTypes.INVALID_DATE_RANGE, - data: { - dateRange: { - startDate: moment(new Date('07/04/2016')), - endDate: moment(new Date('06/05/2016')) - }, - errorMsg: 'some eror message' - }}; - const newState = reducer(initialState, rangeChangeAction); - expect(newState.startDate).to.exist; - expect(newState.startDate.toDate().getTime()).to.equal(new Date('07/04/2016').getTime()); - expect(newState.endDate).to.exist; - expect(newState.endDate.toDate().getTime()).to.equal(new Date('06/05/2016').getTime()); - expect(newState.period).to.not.exist; - expect(newState.periodErrText).to.equal('some eror message'); - expect(newState.periodErrSev).to.equal(MESSAGE_LEVEL_DANGER); - }); - it("Date Range Selector Reducer ... Vaidate PERIOD_CHANGE event)", function() { - var moment = require('moment'); - const initialState = { - startDate: moment(new Date('07/20/2016')), - endDate: moment(new Date('07/09/2016')), - period: CUSTOM, - periodErrText: 'some error text', - periodErrSev: 'some error severity' - }; - const rangeChangeAction = { - type: dateRangeSelectorActionTypes.EVENT_PERIOD_CHANGE, - data: { - dateRange: { - startDate: moment(new Date('07/04/2016')), - endDate: moment(new Date('07/05/2016')) - }, - period: YESTERDAY - } - }; - const newState = reducer(initialState, rangeChangeAction); - expect(newState.startDate).to.exist; - expect(newState.startDate.toDate().getTime()).to.equal(new Date('07/04/2016').getTime()); - expect(newState.endDate).to.exist; - expect(newState.endDate.toDate().getTime()).to.equal(new Date('07/05/2016').getTime()); - expect(newState.period).to.equal(YESTERDAY); - expect(newState.periodErrText).to.equal(''); - expect(newState.periodErrSev).to.equal(''); - }); - - // test Actions - it("Date Range Selector Action - test EVENT_PERIOD_CHANGE (period = Today)", function() { - var moment = require('moment'); - const startDate = moment(new Date()); - const endDate = moment(new Date()); - const period = TODAY; - - const results = DateRangeSelectorActions.onPeriodChange(startDate, endDate, period); - - const expectedStartTime = moment(new Date()); - setTime(expectedStartTime, 0, 0, 0); - const expectedEndTime = moment(new Date()); - setTime(expectedEndTime, 23, 59, 59); - const expectedAction = buildExpectedPeriodChangeAction(expectedStartTime, expectedEndTime, TODAY); - - expect(results.type).to.equal(expectedAction.type); - validateDates(results.data.dateRange.startDate, expectedAction.data.dateRange.startDate); - validateDates(results.data.dateRange.endDate, expectedAction.data.dateRange.endDate); - expect(results.data.period).to.equal(expectedAction.data.period); - }); - it("Date Range Selector Action - test EVENT_PERIOD_CHANGE (period = Yesterday)", function() { - var moment = require('moment'); - const startDate = moment(new Date()); - const endDate = moment(new Date()); - const period = YESTERDAY; - - const results = DateRangeSelectorActions.onPeriodChange(startDate, endDate, period); - - const expectedStartTime = moment(new Date()).subtract(1, 'days'); - setTime(expectedStartTime, 0, 0, 0); - const expectedEndTime = moment(new Date()); - setTime(expectedEndTime, 23, 59, 59); - const expectedAction = buildExpectedPeriodChangeAction(expectedStartTime, expectedEndTime, YESTERDAY); - - expect(results.type).to.equal(expectedAction.type); - validateDates(results.data.dateRange.startDate, expectedAction.data.dateRange.startDate); - validateDates(results.data.dateRange.endDate, expectedAction.data.dateRange.endDate); - expect(results.data.period).to.equal(expectedAction.data.period); - }); - it("Date Range Selector Action - test EVENT_PERIOD_CHANGE (period = Last Week)", function() { - var moment = require('moment'); - const startDate = moment(new Date()); - const endDate = moment(new Date()); - const period = LAST_WEEK; - - const results = DateRangeSelectorActions.onPeriodChange(startDate, endDate, period); - - const expectedStartTime = moment(new Date()).subtract(7, 'days'); - setTime(expectedStartTime, 0, 0, 0); - const expectedEndTime = moment(new Date()); - setTime(expectedEndTime, 23, 59, 59); - const expectedAction = buildExpectedPeriodChangeAction(expectedStartTime, expectedEndTime, LAST_WEEK); - - expect(results.type).to.equal(expectedAction.type); - validateDates(results.data.dateRange.startDate, expectedAction.data.dateRange.startDate); - validateDates(results.data.dateRange.endDate, expectedAction.data.dateRange.endDate); - expect(results.data.period).to.equal(expectedAction.data.period); - }); - it("Date Range Selector Action - test EVENT_PERIOD_CHANGE (period = Last Month)", function() { - var moment = require('moment'); - const startDate = moment(new Date()); - const endDate = moment(new Date()); - const period = LAST_MONTH; - - const results = DateRangeSelectorActions.onPeriodChange(startDate, endDate, period); - - const expectedStartTime = moment(new Date()).subtract(1, 'months'); - setTime(expectedStartTime, 0, 0, 0); - const expectedEndTime = moment(new Date()); - setTime(expectedEndTime, 23, 59, 59); - const expectedAction = buildExpectedPeriodChangeAction(expectedStartTime, expectedEndTime, LAST_MONTH); - - expect(results.type).to.equal(expectedAction.type); - validateDates(results.data.dateRange.startDate, expectedAction.data.dateRange.startDate); - validateDates(results.data.dateRange.endDate, expectedAction.data.dateRange.endDate); - expect(results.data.period).to.equal(expectedAction.data.period); - }); - it("Date Range Selector Action - test EVENT_PERIOD_CHANGE (period = Custom)", function() { - var moment = require('moment'); - const startDate = moment(new Date()).subtract(3, 'months'); - const endDate = moment(new Date()).add(6, 'days'); - const period = CUSTOM; - - const results = DateRangeSelectorActions.onPeriodChange(startDate, endDate, period); - - setTime(startDate, 0, 0, 0); - setTime(endDate, 23, 59, 59); - const expectedAction = buildExpectedPeriodChangeAction(startDate, endDate, CUSTOM); - - expect(results.type).to.equal(expectedAction.type); - validateDates(results.data.dateRange.startDate, expectedAction.data.dateRange.startDate); - validateDates(results.data.dateRange.endDate, expectedAction.data.dateRange.endDate); - expect(results.data.period).to.equal(expectedAction.data.period); - }); - it("Date Range Selector Action - test EVENT_PERIOD_CHANGE (period = Unknown)", function() { - var moment = require('moment'); - const startDate = moment(new Date()).subtract(3, 'months'); - const endDate = moment(new Date()).add(6, 'days'); - const period = 'Some Unknown Period'; - - const results = DateRangeSelectorActions.onPeriodChange(startDate, endDate, period); - - let expectedErrorMsg = ERROR_UNKNOWN_PERIOD + ': ' + period; - const expectedAction = buildExpectedUnknownPeriodAction(startDate, endDate, period, expectedErrorMsg); - - expect(results.type).to.deep.equal(expectedAction.type); - validateDates(results.data.dateRange.startDate, expectedAction.data.dateRange.startDate); - validateDates(results.data.dateRange.endDate, expectedAction.data.dateRange.endDate); - expect(results.data.period).to.equal(expectedAction.data.period); - }); - - // TODO - need tests to confirm DateRangeSelectorActions.onPeriodChange is called when clicking any of the 'quick link' periods - - - // helper functions - function setTime(moment, hours, minutes, seconds) { - moment.toDate(); - moment.hour(hours); - moment.minute(minutes); - moment.second(seconds); - } - - function validateDates(actualDate, expectedDates) { - expect(actualDate.toDate().getYear()).to.equal(expectedDates.toDate().getYear()); - expect(actualDate.toDate().getMonth()).to.equal(expectedDates.toDate().getMonth()); - expect(actualDate.toDate().getDay()).to.equal(expectedDates.toDate().getDay()); - expect(actualDate.toDate().getHours()).to.equal(expectedDates.toDate().getHours()); - expect(actualDate.toDate().getMinutes()).to.equal(expectedDates.toDate().getMinutes()); - } - - function buildExpectedPeriodChangeAction(start, end, period) { - return { - type: dateRangeSelectorActionTypes.EVENT_PERIOD_CHANGE, - data: { - dateRange: { - startDate: start, - endDate: end - }, - period: period - } - }; - } - - function buildExpectedUnknownPeriodAction(start, end, period, errorMsg) { - return { - type: dateRangeSelectorActionTypes.EVENT_PERIOD_ERROR, - data: { - dateRange: { - startDate: start, - endDate: end - }, - period: period, - errorMsg: errorMsg - } - }; - } -}); diff --git a/test/components/inlineMessage.test.js b/test/components/inlineMessage.test.js deleted file mode 100644 index b56a97f..0000000 --- a/test/components/inlineMessage.test.js +++ /dev/null @@ -1,90 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ -import { expect } from 'chai'; -import React from 'react'; -import TestUtils from 'react-dom/test-utils'; -import InlineMessage from 'generic-components/InlineMessage/InlineMessage.jsx'; -import InlineMessageConstants from 'generic-components/InlineMessage/InlineMessageConstants.js'; - -describe('Core Inline Message Suite', function() { - - let _successMessage; - let _warningMessage; - let _dangerMessage; - let _defaultMessage; - - beforeEach(function() { - _warningMessage = TestUtils.renderIntoDocument(); - _successMessage = TestUtils.renderIntoDocument(); - _dangerMessage = TestUtils.renderIntoDocument(); - _defaultMessage = TestUtils.renderIntoDocument(); - }); - - // test structure - it('Inline Message - validate success message panel', function() { - let alertPanel = TestUtils.findRenderedDOMComponentWithClass(_successMessage, 'alert'); - expect(alertPanel).to.exist; // alert panel exists - let alertPanel_style = TestUtils.findRenderedDOMComponentWithClass(_successMessage, 'alert-success'); - expect(alertPanel_style).to.exist; // alert panel has proper styling - let messagePanel = TestUtils.findRenderedDOMComponentWithClass(_successMessage, InlineMessageConstants.MESSAGE_PANEL_CLASSNAME); - expect(messagePanel).to.exist; - expect(messagePanel.innerHTML).to.have.string('Success Message'); // messagePanel panel has proper message - let iconPanel = TestUtils.findRenderedDOMComponentWithClass(_successMessage, InlineMessageConstants.ICON_PANEL_CLASSNAME); - expect(iconPanel).to.exist; - expect(iconPanel.innerHTML).to.have.string(InlineMessageConstants.SUCCESS_CLASSNAME); // notification panel has proper styling - }); - it('Inline Message - validate info message panel', function() { - let alertPanel = TestUtils.findRenderedDOMComponentWithClass(_defaultMessage, 'alert'); - expect(alertPanel).to.exist; // alert panel exists - let alertPanel_style = TestUtils.findRenderedDOMComponentWithClass(_defaultMessage, 'alert-info'); - expect(alertPanel_style).to.exist; // alert panel has proper styling - let messagePanel = TestUtils.findRenderedDOMComponentWithClass(_defaultMessage, InlineMessageConstants.MESSAGE_PANEL_CLASSNAME); - expect(messagePanel).to.exist; - expect(messagePanel.innerHTML).to.have.string('Info Message'); // messagePanel panel has proper message - let iconPanel = TestUtils.findRenderedDOMComponentWithClass(_defaultMessage, InlineMessageConstants.ICON_PANEL_CLASSNAME); - expect(iconPanel).to.exist; - expect(iconPanel.innerHTML).to.have.string(InlineMessageConstants.DEFAULT_CLASSNAME); // icon panel has proper styling - }); - it('Inline Message - validate warning message panel', function() { - let alertPanel = TestUtils.findRenderedDOMComponentWithClass(_warningMessage, 'alert'); - expect(alertPanel).to.exist; // alert panel exists - let alertPanel_style = TestUtils.findRenderedDOMComponentWithClass(_warningMessage, 'alert-warning'); - expect(alertPanel_style).to.exist; // alert panel has proper styling - let messagePanel = TestUtils.findRenderedDOMComponentWithClass(_warningMessage, InlineMessageConstants.MESSAGE_PANEL_CLASSNAME); - expect(messagePanel).to.exist; - expect(messagePanel.innerHTML).to.have.string('Warning Message'); // messagePanel panel has proper message - let iconPanel = TestUtils.findRenderedDOMComponentWithClass(_warningMessage, InlineMessageConstants.ICON_PANEL_CLASSNAME); - expect(iconPanel).to.exist; - expect(iconPanel.innerHTML).to.have.string(InlineMessageConstants.WARNING_CLASSNAME); // icon panel has proper styling - }); - it('Inline Message - validate danger message panel', function() { - let alertPanel = TestUtils.findRenderedDOMComponentWithClass(_dangerMessage, 'alert'); - expect(alertPanel).to.exist; // alert panel exists - let alertPanel_style = TestUtils.findRenderedDOMComponentWithClass(_dangerMessage, 'alert-danger'); - expect(alertPanel_style).to.exist; // alert panel has proper styling - let messagePanel = TestUtils.findRenderedDOMComponentWithClass(_dangerMessage, InlineMessageConstants.MESSAGE_PANEL_CLASSNAME); - expect(messagePanel).to.exist; - expect(messagePanel.innerHTML).to.have.string('Danger Message'); // messagePanel panel has proper message - let iconPanel = TestUtils.findRenderedDOMComponentWithClass(_dangerMessage, InlineMessageConstants.ICON_PANEL_CLASSNAME); - expect(iconPanel).to.exist; - expect(iconPanel.innerHTML).to.have.string(InlineMessageConstants.DANGER_CLASSNAME); // icon panel has proper styling - }); -}); diff --git a/test/components/notificationReducer.test.js b/test/components/notificationReducer.test.js deleted file mode 100644 index 9600a82..0000000 --- a/test/components/notificationReducer.test.js +++ /dev/null @@ -1,108 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ -import { expect } from 'chai'; -import NotificationConstants from 'generic-components/notifications/NotificationConstants.js'; -import reducer from 'generic-components/notifications/NotificationReducer.js'; - -describe("Notification reducer test suite", function() { - const initialState = { - title: '', - msg: '', - timeout: 0 - }; - - it("NOTIFY_INFO event", function() { - const action = { - type: NotificationConstants.NOTIFY_INFO, - data: { - title: 'some title', - msg: 'some message', - timeout: 1 - } - } - const newState = reducer(initialState, action); - - expect(newState.type).to.equal('default'); - expect(newState.title).to.equal('some title'); - expect(newState.msg).to.equal('some message'); - expect(newState.timeout).to.equal(1); - }); - - it("NOTIFY_ERROR event", function() { - const action = { - type: NotificationConstants.NOTIFY_ERROR, - data: { - title: 'some title', - msg: 'some message', - timeout: 1 - } - } - const newState = reducer(initialState, action); - - expect(newState.type).to.equal('error'); - expect(newState.title).to.equal('some title'); - expect(newState.msg).to.equal('some message'); - expect(newState.timeout).to.equal(1); - }); - - it("NOTIFY_WARNING event", function() { - const action = { - type: NotificationConstants.NOTIFY_WARNING, - data: { - title: 'some title', - msg: 'some message', - timeout: 1 - } - } - const newState = reducer(initialState, action); - - expect(newState.type).to.equal('warning'); - expect(newState.title).to.equal('some title'); - expect(newState.msg).to.equal('some message'); - expect(newState.timeout).to.equal(1); - }); - - it("NOTIFY_SUCCESS event", function() { - const action = { - type: NotificationConstants.NOTIFY_SUCCESS, - data: { - title: 'some title', - msg: 'some message', - timeout: 1 - } - } - const newState = reducer(initialState, action); - - expect(newState.type).to.equal('success'); - expect(newState.title).to.equal('some title'); - expect(newState.msg).to.equal('some message'); - expect(newState.timeout).to.equal(1); - }); - - it("NOTIFY_CLOSE event", function() { - const action = { - type: NotificationConstants.NOTIFY_CLOSE - } - const newState = reducer(initialState, action); - - expect(newState).to.be.null; - }); -}); diff --git a/test/components/toggleButtonGroupReducer.test.js b/test/components/toggleButtonGroupReducer.test.js deleted file mode 100644 index 93ddaf9..0000000 --- a/test/components/toggleButtonGroupReducer.test.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ -import { expect } from 'chai'; -import {BUTTON_TOGGLED} from 'generic-components/toggleButtonGroup/ToggleButtonGroupConstants.js'; -import reducer from 'generic-components/toggleButtonGroup/ToggleButtonGroupReducer.js'; - -describe("Toggle Button Group reducer test suite", function() { - const initialState = { - selectedButton: '' - }; - - it("BUTTON_TOGGLED event", function () { - const action = { - type: BUTTON_TOGGLED, - data: { - button: 'some button name' - } - } - const newState = reducer(initialState, action); - - expect(newState.selectedButton).to.equal('some button name'); - }); -}); -- cgit 1.2.3-korg