Ejemplo n.º 1
0
  it('supports imbricated Record {min: false}', () => {
    const CDRecord = Immutable.Record({c: 3, d: 4}, 'CDRecord');
    const ABRecord = Immutable.Record({a: CDRecord(), b: 2}, 'ABRecord');

    expect(ABRecord()).toPrettyPrintTo(
      'Immutable.ABRecord {\n  "a": Immutable.CDRecord {\n    "c": 3,\n    "d": 4,\n  },\n  "b": 2,\n}',
    );
  });
Ejemplo n.º 2
0
  it('supports imbricated Record {min: true}', () => {
    const CDRecord = Immutable.Record({c: 3, d: 4}, 'CDRecord');
    const ABRecord = Immutable.Record({a: CDRecord(), b: 2}, 'ABRecord');

    expect(ABRecord()).toPrettyPrintTo(
      'Immutable.ABRecord {"a": Immutable.CDRecord {"c": 3, "d": 4}, "b": 2}',
      {min: true},
    );
  });
Ejemplo n.º 3
0
 it('passes through records of the same type', () => {
   var P2 = Record({ x: 0, y: 0 });
   var P3 = Record({ x: 0, y: 0, z: 0 });
   var p2 = P2();
   var p3 = P3();
   expect(P3(p2) instanceof P3).toBe(true);
   expect(P2(p3) instanceof P2).toBe(true);
   expect(P2(p2)).toBe(p2);
   expect(P3(p3)).toBe(p3);
 })
Ejemplo n.º 4
0
  it('supports a record with values {min: false}', () => {
    const ABRecord = Immutable.Record({a: 1, b: 2}, 'ABRecord');

    expect(ABRecord({a: 3, b: 4})).toPrettyPrintTo(
      'Immutable.ABRecord {\n  "a": 3,\n  "b": 4,\n}',
    );
  });
Ejemplo n.º 5
0
  it('supports a record without descriptive name', () => {
    const ABRecord = Immutable.Record({a: 1, b: 2});

    expect(ABRecord()).toPrettyPrintTo('Immutable.Record {"a": 1, "b": 2}', {
      min: true,
    });
  });
Ejemplo n.º 6
0
  it('supports an empty record {min: false}', () => {
    const ABRecord = Immutable.Record({}, 'ABRecord');

    expect(ABRecord()).toPrettyPrintTo('Immutable.ABRecord {}', {
      min: false,
    });
  });
describe('shared / model-helper', () => {

  interface Mock {
    prop1: string;
    prop2: string;
  }

  const MockModel: Record.Factory<Mock> = Record<Mock>({
    prop1: '',
    prop2: ''
  });

  describe('generateMap', () => {

    const mockData: Mock[] = [
      { prop1: 'value10', prop2: 'value10' },
      { prop1: 'value11', prop2: 'value21' },
      { prop1: 'value12', prop2: 'value22' }
    ];

    it('should return an Immutable Map', () => {
      const expectedMap = Map([
        [0, new MockModel(mockData[0])],
        [1, new MockModel(mockData[1])],
        [2, new MockModel(mockData[2])]
      ]);

      expect(generateMap(mockData, MockModel).toObject()).to.deep.equal(expectedMap.toObject());
    });
  });
});
Ejemplo n.º 8
0
export default function builds(state = initialState["builds"], action) {
    switch (action.type) {

        case actionTypes.CLEAR_BUILD:
            return state
                .setIn(["selected", "info"], Record({})());

        case actionTypes.CLEAR_BUILD_LOG:
            state.get("selected").log.content.next([]);

            return state.setIn(["selected", "log"], {
                start: undefined,
                stop: undefined,
                content: state.get("selected").log.content,
                is_complete: undefined
            });

        case actionTypes.CLEAR_BUILDS:
            return state
                .setIn(["visible"], List());

        case actionTypes.POPULATE_BUILD:
            return state.setIn(["selected", "info"], action.payload);

        case actionTypes.POPULATE_BUILD_LOG:
            let payload = action.payload;
            let content = state.get("selected").log.content;

            // It'll be common to get log requests for builds that haven't
            // started yet (which will surface as errors), so in that case,
            // we'll just hand back the current state.
            if (action.error) {
                return state;
            }

            if (payload.start === 0 && !payload.is_complete) {
                content.next(payload.content || []);
            }
            else if (payload.content.length) {
                content.next(payload.content);
            }

            return state.setIn(["selected", "log"], {
                start: payload.start,
                stop: payload.stop,
                content: content,
                is_complete: payload.is_complete
            });

        case actionTypes.POPULATE_BUILDS:
            return state.setIn(["visible"], List(action.payload));

        case actionTypes.STREAM_BUILD_LOG:
            return state.setIn(["selected", "stream"], action.payload);

        default:
            return state;
    }
}
Ejemplo n.º 9
0
export function makeTypedFactory<E, T extends TypedRecord<T> & E>
  (obj: E, name?: string): (val?: E) => T {

  const ImmutableRecord = Record(obj, name);
  return function TypedFactory(val: E = null): T {
    return new ImmutableRecord(val) as T;
  };
};
Ejemplo n.º 10
0
  it('only allows setting what it knows about', () => {
    var MyType = Record({a:1, b:2, c:3});

    var t1 = new MyType({a: 10, b:20});
    expect(() => {
      t1.set('d', 4);
    }).toThrow('Cannot set unknown key "d" on Record');
  });