Загрузка данных


class TestSeries extends BaseSeries<'Line'> {
  public readonly historyHandler = jest.fn();
  public readonly realtimeHandler = jest.fn();

  public readonly legendFormatter = jest
    .fn<LegendValues, [LegendData, LegendData]>()
    .mockReturnValue({});

  public returnEmptyFormattedData = false;

  protected dataSourceSubscription = (next: Candle[]): void => {
    this.historyHandler(next);
  };

  protected dataSourceRealtimeSubscription = (next: Candle): void => {
    this.realtimeHandler(next);
  };

  protected seriesDefinition(): SeriesDefinition<'Line'> {
    return LineSeries;
  }

  protected getDefaultOptions(): SeriesPartialOptionsMap['Line'] {
    return {
      color: '#111111',
    };
  }

  protected formatMainSerie(
    inputData: Candle[],
  ): SeriesDataItemTypeMap<Time>['Line'][] {
    if (this.returnEmptyFormattedData) {
      return [];
    }

    return inputData.map((point) => ({
      time: point.time as Time,
      value: point.close,
      customValues: point as unknown as Record<string, unknown>,
    }));
  }

  protected formatLegendValues(
    currentBar: LegendData,
    prevBar: LegendData,
  ): LegendValues {
    return this.legendFormatter(currentBar, prevBar);
  }

  public updateRealtimeForTest(
    bar: SeriesDataItemTypeMap<Time>['Line'],
  ): void {
    this.updateRealtime(bar);
  }

  public formatDataForTest(
    data: Candle[],
  ): SeriesDataItemTypeMap<Time>['Line'][] {
    return this.formatData(data);
  }

  public subscribeDataSourceForTest(dataSource: DataSource): void {
    this.subscribeDataSource(dataSource);
  }
}