Skip to content
Snippets Groups Projects
Select Git revision
  • facca955e6f952a12176d139f972bf912b852ee3
  • mui5-annotation-on-video-stable default
  • get_setter_canvasSizeInformations
  • fix-error-div-into-p
  • annotation-on-video-v2
  • detached
  • annotation-on-video-r17
  • mui5
  • mui5-react-18
  • jacob-test
  • annotation-on-video protected
  • master
  • test-antoinev1
  • 20-fetch-thumbnail-on-annotation
  • add-research-field
  • Save
  • add-plugin
  • 14-wip-no-seek-to
  • 14-bug-on-video-time-control
  • 9_wip_videotests
  • _upgrade_material_ui
  • latest-tetras-16
  • v3.3.0
  • v3.2.0
  • v3.1.1
  • v3.1.0
  • v3.0.0
  • v3.0.0-rc.7
  • v3.0.0-rc.6
  • v3.0.0-rc.5
  • v3.0.0-rc.4
  • v3.0.0-rc.3
  • v3.0.0-rc.2
  • v3.0.0-rc.1
  • v3.0.0-beta.10
  • v3.0.0-beta.9
  • v3.0.0-beta.8
  • v3.0.0-beta.7
  • v3.0.0-beta.6
  • v3.0.0-beta.5
  • v3.0.0-beta.3
41 results

utils.test.js

Blame
  • utils.test.js 2.06 KiB
    import { set, update, unset } from '../../../src/state/reducers/utils';
    
    describe('set', () => {
      it('does not change input object', () => {
        const object = { foo: { a: 1 } };
        set(object, 'foo', { b: 2 });
        expect(object).toEqual({ foo: { a: 1 } });
      });
    
      it('sets a new item with the provided props', () => {
        const object = { foo: { a: 1 } };
        const result = set(object, 'bar', { b: 2 });
        expect(result).toEqual({
          bar: { b: 2 },
          foo: { a: 1 },
        });
      });
    
      it('overrides an existing item', () => {
        const object = { foo: { a: 1 } };
        const result = set(object, 'foo', { b: 2 });
        expect(result).toEqual({ foo: { b: 2 } });
      });
    });
    
    describe('updateItem', () => {
      it('does not change input object', () => {
        const object = { foo: { a: 1 } };
        update(object, 'foo', { b: 2 });
        expect(object).toEqual({ foo: { a: 1 } });
      });
    
      it('updates an item with the provided props', () => {
        const object = { bar: { b: 2, c: 3 }, foo: { a: 1 } };
        const result = update(object, 'bar', { c: 4, d: 5 });
        expect(result).toEqual({
          bar: { b: 2, c: 4, d: 5 },
          foo: { a: 1 },
        });
      });
    
      it('updates an item based on the function passed', () => {
        const object = { bar: { b: 2, c: 3 }, foo: { a: 1 } };
        /** */ const fn = props => ({ ...props, c: props.c + 1 });
        const result = update(object, 'bar', fn);
        expect(result).toEqual({
          bar: { b: 2, c: 4 },
          foo: { a: 1 },
        });
      });
    });
    
    describe('removeItem', () => {
      it('does not change input object', () => {
        const object = { foo: { a: 1 } };
        unset(object, 'foo');
        expect(object).toEqual({ foo: { a: 1 } });
      });
    
      it('removes item from object', () => {
        const object = { bar: { a: 1 }, foo: { b: 2 } };
        const result = unset(object, 'bar');
        expect(result).toEqual({ foo: { b: 2 } });
      });
    
      it('returns the same object shape if item does not exist', () => {
        const object = { bar: { a: 1 }, foo: { b: 2 } };
        const result = unset(object, 'bubu');
        expect(result).toEqual({ bar: { a: 1 }, foo: { b: 2 } });
      });