UNPKG

trc-client-core

Version:
172 lines (135 loc) 5.85 kB
var TechnicalReportStore = require('../TechnicalReportStore'); var {plainRefluxStateSet} = require('../../utils/GenericTests'); var SERVER_DATA = { a: {foo: 1, baz: 2 }, b: {foo: 3, baz: 4 } }; var TRANSFORM_MAP = { chartData: ['foo','baz'] }; var EXPECTED_TRANSFORM = { chartMax: 4, chartData: [ {xlabel: 'a', series: [1,2]}, {xlabel: 'b', series: [3,4]} ] }; describe('TechnicalReportStore', function () { describe('substringThreeChars', function() { it('gets the first 3 chars of a string', function () { expect(TechnicalReportStore.substringThreeChars('test_value')).toBe('tes'); }); }); describe('transformToState', function() { it('turns trc data into peanut friendly array', function () { expect(TechnicalReportStore.transformToState(TRANSFORM_MAP, SERVER_DATA)).toEqual(EXPECTED_TRANSFORM); }); }); // // Training Delivery describe('onFetchTrainingDelivery', plainRefluxStateSet.bind(TechnicalReportStore, { it: 'sets trainingDeliveryFetching to be true', call: 'onFetchTrainingDelivery', get: 'trainingDeliveryFetching', compare: 'toBe', expected: true })); describe('onFetchTrainingDeliveryCompleted', function () { it('performs transformToState on trainingDelivery', function () { TechnicalReportStore.onFetchTrainingDeliveryCompleted(SERVER_DATA); expect(TechnicalReportStore.get('trainingDelivery')).toBeDefined(); }); it('sets trainingDeliveryFetching to false ', function () { TechnicalReportStore.onFetchTrainingDeliveryCompleted(SERVER_DATA); expect(TechnicalReportStore.get('trainingDeliveryFetching')).toBe(false); }); }); // // Class Sizes describe('onFetchClassSizes', plainRefluxStateSet.bind(TechnicalReportStore, { it: 'sets classSizesFetching to be true', call: 'onFetchClassSizes', get: 'classSizesFetching', compare: 'toBe', expected: true })); describe('onFetchClassSizesCompleted', function () { it('performs transformToState on classSizes', function () { TechnicalReportStore.onFetchClassSizesCompleted(SERVER_DATA); expect(TechnicalReportStore.get('classSizes')).toBeDefined(); }); it('sets classSizesFetching to false', function () { TechnicalReportStore.onFetchClassSizesCompleted(SERVER_DATA); expect(TechnicalReportStore.get('classSizesFetching')).toBe(false); }); }); // // Class Sizes Accumulative describe('onFetchClassSizesAccumulative', plainRefluxStateSet.bind(TechnicalReportStore, { it: 'sets classSizesAccumulativeFetching to be true', call: 'onFetchClassSizesAccumulative', get: 'classSizesAccumulativeFetching', compare: 'toBe', expected: true })); describe('onFetchClassSizesAccumulativeCompleted', function () { it('performs transformToState on classSizesAccumulative', function () { TechnicalReportStore.onFetchClassSizesAccumulativeCompleted(SERVER_DATA); expect(TechnicalReportStore.get('classSizesAccumulative')).toBeDefined(); }); it('sets classSizesAccumulativeFetching to false', function () { TechnicalReportStore.onFetchClassSizesAccumulativeCompleted(SERVER_DATA); expect(TechnicalReportStore.get('classSizesAccumulativeFetching')).toBe(false); }); }); // // Stream Certification describe('onFetchStreamCertification', plainRefluxStateSet.bind(TechnicalReportStore, { it: 'sets streamCertificationFetching to be true', call: 'onFetchStreamCertification', get: 'streamCertificationFetching', compare: 'toBe', expected: true })); describe('onFetchStreamCertificationCompleted', function () { it('performs transformToState on streamCertification', function () { TechnicalReportStore.onFetchStreamCertificationCompleted(SERVER_DATA); expect(TechnicalReportStore.get('streamCertification')).toBeDefined(); }); it('sets streamCertificationFetching to false', function () { TechnicalReportStore.onFetchStreamCertificationCompleted(SERVER_DATA); expect(TechnicalReportStore.get('streamCertificationFetching')).toBe(false); }); }); // // Stream Eligibility describe('onFetchStreamEligibility', plainRefluxStateSet.bind(TechnicalReportStore, { it: 'sets streamEligibilityFetching to be true', call: 'onFetchStreamEligibility', get: 'streamEligibilityFetching', compare: 'toBe', expected: true })); describe('onFetchStreamEligibilityCompleted', function () { it('performs streamEligibilityShape on streamEligibility', function () { TechnicalReportStore.onFetchStreamEligibilityCompleted(SERVER_DATA); expect(TechnicalReportStore.get('streamEligibility')).toBeDefined(); }); it('sets streamEligibilityFetching to false', function () { TechnicalReportStore.onFetchStreamEligibilityCompleted(SERVER_DATA); expect(TechnicalReportStore.get('streamEligibilityFetching')).toBe(false); }); }); describe('streamEligibilityShape', function () { it('transform streamEligibility data to peanuts shape', function () { var DATA = { foo:{ eligible:1, completed:2 } }; var EXPECTED = [{xlabel: 'foo', series: [2,1]}]; expect(TechnicalReportStore.streamEligibilityShape(DATA)).toEqual(EXPECTED); }); }); });