mercredi 24 mars 2021

How to write test case for switch case in Angular for following case

This is Angular function code where I am using switch(true) and switch case as condition to checking values for testing

  yAxisText() {
    const KilobyteConst = this.KilobyteConst;
    const MegabyteConst = this.MegabyteConst;
    // to rotate text on x axis
    d3.selectAll('g.axis-y>g.tick>text')
    .each(function(d: number, i) {
      let textValue, calculation;
      switch (true) {
        case (d > KilobyteConst && d < MegabyteConst):
          calculation = d / KilobyteConst;
          break;
        case (d > MegabyteConst):
          calculation = d / MegabyteConst;
          break;
        default:
          calculation = d;
      }

      textValue = `${d3.format(',.0f')(calculation)} <title>${d3.format('.2f')(calculation)}</title>`;
      console.log('test on ', textValue, d, i);
      d3.select(this)
      .style('font-size', '12px')
      .style('color', '#525252')
      .style('cursor', 'pointer')
      .html(textValue);
    });
  }

I have added one image for more clarity Angular function with switch cases

Aucun commentaire:

Enregistrer un commentaire