gene.test.ts 2.3 KB
Newer Older
Remi  PLANEL's avatar
Remi PLANEL committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import Gene from "../src/scripts/component/sequence/gene";
import { GeneData } from "../src/scripts/types";
import { select } from "d3-selection";
import { scaleLinear } from "d3-scale";

describe("Test gene componennt", () => {
  const result = '<g class="gene" transform="translate(100,60)"><path style="fill-opacity: 0.85; stroke-width: 1px; stroke-opacity: 0.8;" transform="translate(0,35) translate(400,30) rotate(180)" d="M0,0L0,30L390,30L400,15L390,0Z"></path></g><g class="gene" transform="translate(600,60)"><path style="fill-opacity: 0.85; stroke-width: 1px; stroke-opacity: 0.8;" d="M0,0L0,30L390,30L400,15L390,0Z"></path></g>';
  document.body.innerHTML =
    '<div><svg width="500"><g id="container"></g></svg></div>';
  const data: GeneData[] = [{
    name: "gene 1",
    strand: "-",
    begin: 10,
    end: 50,
    gene: "insA",
Remi  PLANEL's avatar
Remi PLANEL committed
16
17
18
    eventHandler: {
      click: (geneLocation) => console.log(geneLocation)
    }
Remi  PLANEL's avatar
Remi PLANEL committed
19
20
21
22
23
24
25
26
  },
  {
    name: "gene 2",
    strand: "+",
    begin: 60,
    end: 100,
    gene: "yaaY",
  }];
Remi  PLANEL's avatar
Remi PLANEL committed
27
  let window = [0, 120];
Remi  PLANEL's avatar
Remi PLANEL committed
28
29
  const geneComponent = Gene();
  const xScale = scaleLinear()
Remi  PLANEL's avatar
Remi PLANEL committed
30
    .domain(window)
Remi  PLANEL's avatar
Remi PLANEL committed
31
32
    .range([0, 1200]);

Remi  PLANEL's avatar
Remi PLANEL committed
33
34
35
  const container = select("svg")
    .select<SVGGElement>("g");

Remi  PLANEL's avatar
Remi PLANEL committed
36
  test("test html generated by gene component", () => {
Remi  PLANEL's avatar
Remi PLANEL committed
37

Remi  PLANEL's avatar
Remi PLANEL committed
38
39
40
41
    container
      .datum<GeneData[]>(data)
      .call(geneComponent, xScale);

Remi  PLANEL's avatar
Remi PLANEL committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
    expect(container.html()).toBe(result);
  });

  test("Click", () => {
    const result = '<g class=\"gene\" transform=\"translate(0,60)\"><path style=\"fill-opacity: 0.85; stroke-width: 1px; stroke-opacity: 0.8;\" transform=\"translate(0,35) translate(533.3333333333333,30) rotate(180)\" d=\"M0,0L0,30L523.3333333333333,30L533.3333333333333,15L523.3333333333333,0Z\"></path></g><g class=\"gene\" transform=\"translate(666.6666666666667,60)\"><path style=\"fill-opacity: 0.85; stroke-width: 1px; stroke-opacity: 0.8;\" d=\"M0,0L0,30L523.3333333333333,30L533.3333333333333,15L523.3333333333333,0Z\"></path></g>';
    const path = container.selectAll(".gene").select<SVGPathElement>("path");
    if (path) {
      path.dispatch("click");
      window = [10, 100]
      xScale.domain(window);
      container
        .datum<GeneData[]>(data)
        .call(geneComponent, xScale);
      // path.dispatchEvent(new Event('click'));
Remi  PLANEL's avatar
Remi PLANEL committed
56
      expect(container.html()).toBe(result);
Remi  PLANEL's avatar
Remi PLANEL committed
57
58
    }
  });
Remi  PLANEL's avatar
Remi PLANEL committed
59
60

});