graphics_builder_spec.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import helper from "helper";
  2. import { expect } from "chai";
  3. describe("Graphics Builder", () => {
  4. let graphics_builder;
  5. describe("Non-offsetted frames", () => {
  6. beforeEach(() => {
  7. global.mock_DOM_template = [" ", " "];
  8. global.frame_type = "small";
  9. global.tty = {
  10. width: 4,
  11. height: 2,
  12. x_scroll: 0,
  13. y_scroll: 0,
  14. };
  15. graphics_builder = helper.runGraphicsBuilder();
  16. });
  17. it("should serialise a scaled frame", () => {
  18. const colours = graphics_builder.frame.colours;
  19. expect(colours.length).to.equal(48);
  20. expect(colours[0]).to.equal(0);
  21. expect(colours[2]).to.equal(1);
  22. expect(colours[46]).to.equal(0);
  23. expect(colours[47]).to.equal(16);
  24. });
  25. it("should populate the frame's meta", () => {
  26. const meta = graphics_builder.frame.meta;
  27. expect(meta).to.deep.equal({
  28. sub_left: 0,
  29. sub_top: 0,
  30. sub_width: 4,
  31. sub_height: 4,
  32. total_width: 4,
  33. total_height: 4,
  34. id: 1,
  35. });
  36. });
  37. });
  38. describe("Offset frames", () => {
  39. beforeEach(() => {
  40. global.tty = {
  41. width: 2,
  42. height: 2,
  43. x_scroll: 2,
  44. y_scroll: 1,
  45. };
  46. global.frame_type = "small";
  47. global.mock_DOM_template = [" ", " ", " ", " "];
  48. graphics_builder = helper.runGraphicsBuilder();
  49. });
  50. it("should serialise a scaled frame", () => {
  51. const colours = graphics_builder.frame.colours;
  52. expect(colours.length).to.equal(24);
  53. expect(colours[0]).to.equal(0);
  54. expect(colours[2]).to.equal(1);
  55. expect(colours[22]).to.equal(0);
  56. expect(colours[23]).to.equal(8);
  57. });
  58. it("should populate the frame's meta", () => {
  59. const meta = graphics_builder.frame.meta;
  60. expect(meta).to.deep.equal({
  61. sub_left: 2,
  62. sub_top: 1,
  63. sub_width: 2,
  64. sub_height: 4,
  65. total_width: 4,
  66. total_height: 8,
  67. id: 1,
  68. });
  69. });
  70. });
  71. });