gene.test.ts 1.29 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
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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",
  },
  {
    name: "gene 2",
    strand: "+",
    begin: 60,
    end: 100,
    gene: "yaaY",
  }];

  const geneComponent = Gene();
  const xScale = scaleLinear()
    .domain([0, 120])
    .range([0, 1200]);

  test("test html generated by gene component", () => {
    const container = select("svg")
      .select<SVGGElement>("g");
      
    container
      .datum<GeneData[]>(data)
      .call(geneComponent, xScale);

      expect(container.html()).toBe(result);
  })

});