<commit_before>import { BoundingRectangle } from "../../Source/Cesium.js";
import { Color } from "../../Source/Cesium.js";
import { Resource } from "../../Source/Cesium.js";
import { Texture } from "../../Source/Cesium.js";
import { Material } from "../../Source/Cesium.js";
import { ViewportQuad } from "../../Source/Cesium.js";
import createScene from "../createScene.js";
import pollToPromise from "../pollToPromise.js";

describe(
  "Scene/ViewportQuad",
  function () {
    var scene;
    var viewportQuad;
    var testImage;

    beforeAll(function () {
      scene = createScene();
      return Resource.fetchImage("./Data/Images/Red16x16.png").then(function (
        image
      ) {
        testImage = image;
      });
    });

    afterAll(function () {
      scene.destroyForSpecs();
    });

    beforeEach(function () {
      viewportQuad = new ViewportQuad();
      viewportQuad.rectangle = new BoundingRectangle(0, 0, 2, 2);
    });

    afterEach(function () {
      scene.primitives.removeAll();
    });

    it("constructs with a rectangle", function () {
      var rectangle = new BoundingRectangle(1.0, 2.0, 3.0, 4.0);
      var quad = new ViewportQuad(rectangle);
      expect(quad.rectangle).toEqual(rectangle);
    });

    it("constructs with a material", function () {
      var material = Material.fromType(Material.StripeType);
      var quad = new ViewportQuad(undefined, material);
      expect(quad.material.type).toEqual(material.type);
    });

    it("gets the default color", function () {
      expect(viewportQuad.material.uniforms.color).toEqual(
        new Color(1.0, 1.0, 1.0, 1.0)
      );
    });

    it("throws when rendered without a rectangle", function () {
      viewportQuad.rectangle = undefined;
      scene.primitives.add(viewportQuad);

      expect(function () {
        scene.renderForSpecs();
      }).toThrowDeveloperError();
    });

    it("throws when rendered without a material", function () {
      viewportQuad.material = undefined;
      scene.primitives.add(viewportQuad);

      expect(function () {
        scene.renderForSpecs();
      }).toThrowDeveloperError();
    });

    it("does not render when show is false", function () {
      viewportQuad.show = false;
      expect(scene).toRender([0, 0, 0, 255]);
      scene.primitives.add(viewportQuad);
      expect(scene).toRender([0, 0, 0, 255]);
    });

    it("renders material", function () {
      expect(scene).toRender([0, 0, 0, 255]);
      scene.primitives.add(viewportQuad);
      expect(scene).notToRender([0, 0, 0, 255]);
    });

    it("renders user created texture", function () {
      var texture = new Texture({
        context: scene.context,
        source: testImage,
      });

      viewportQuad.material = Material.fromType(Material.ImageType);
      viewportQuad.material.uniforms.image = texture;

      pollToPromise(function () {
        return viewportQuad.material._loadedImages.length !== 0;
      }).then(function () {
        expect(scene).toRender([0, 0, 0, 255]);
        scene.primitives.add(viewportQuad);
        expect(scene).toRender([255, 0, 0, 255]);
      });
    });

    it("isDestroyed", function () {
      var boundRectangle = new BoundingRectangle(0, 0, 10, 10);
      var vq = new ViewportQuad(boundRectangle);

      expect(vq.isDestroyed()).toEqual(false);
      vq.destroy();
      expect(vq.isDestroyed()).toEqual(true);
    });
  },
  "WebGL"
);<commit_msg>Add test for ViewportQuad<commit_after>import { BoundingRectangle } from "../../Source/Cesium.js";
import { Color } from "../../Source/Cesium.js";
import { Resource } from "../../Source/Cesium.js";
import { Texture } from "../../Source/Cesium.js";
import { Material } from "../../Source/Cesium.js";
import { ViewportQuad } from "../../Source/Cesium.js";
import createScene from "../createScene.js";
import pollToPromise from "../pollToPromise.js";

describe(
  "Scene/ViewportQuad",
  function () {
    var scene;
    var viewportQuad;
    var testImage;

    beforeAll(function () {
      scene = createScene();
      return Resource.fetchImage("./Data/Images/Red16x16.png").then(function (
        image
      ) {
        testImage = image;
      });
    });

    afterAll(function () {
      scene.destroyForSpecs();
    });

    beforeEach(function () {
      viewportQuad = new ViewportQuad();
      viewportQuad.rectangle = new BoundingRectangle(0, 0, 2, 2);
    });

    afterEach(function () {
      scene.primitives.removeAll();
    });

    it("constructs with a rectangle", function () {
      var rectangle = new BoundingRectangle(1.0, 2.0, 3.0, 4.0);
      var quad = new ViewportQuad(rectangle);
      expect(quad.rectangle).toEqual(rectangle);
    });

    it("constructs with a material", function () {
      var material = Material.fromType(Material.StripeType);
      var quad = new ViewportQuad(undefined, material);
      expect(quad.material.type).toEqual(material.type);
    });

    it("gets the default color", function () {
      expect(viewportQuad.material.uniforms.color).toEqual(
        new Color(1.0, 1.0, 1.0, 1.0)
      );
    });

    it("throws when rendered without a rectangle", function () {
      viewportQuad.rectangle = undefined;
      scene.primitives.add(viewportQuad);

      expect(function () {
        scene.renderForSpecs();
      }).toThrowDeveloperError();
    });

    it("throws when rendered without a material", function () {
      viewportQuad.material = undefined;
      scene.primitives.add(viewportQuad);

      expect(function () {
        scene.renderForSpecs();
      }).toThrowDeveloperError();
    });

    it("does not render when show is false", function () {
      viewportQuad.show = false;
      expect(scene).toRender([0, 0, 0, 255]);
      scene.primitives.add(viewportQuad);
      expect(scene).toRender([0, 0, 0, 255]);
    });

    it("renders material", function () {
      expect(scene).toRender([0, 0, 0, 255]);
      scene.primitives.add(viewportQuad);
      expect(scene).notToRender([0, 0, 0, 255]);
    });

    it("renders user created texture", function () {
      var texture = new Texture({
        context: scene.context,
        source: testImage,
      });

      viewportQuad.material = Material.fromType(Material.ImageType);
      viewportQuad.material.uniforms.image = texture;

      pollToPromise(function () {
        return viewportQuad.material._loadedImages.length !== 0;
      }).then(function () {
        expect(scene).toRender([0, 0, 0, 255]);
        scene.primitives.add(viewportQuad);
        expect(scene).toRender([255, 0, 0, 255]);
      });
    });

    it("updates rectangle", function () {
      var otherRectangle = new BoundingRectangle(0, 0, 4, 4);

      scene.primitives.add(viewportQuad);
      scene.renderForSpecs();

      viewportQuad.rectangle = otherRectangle;
      scene.renderForSpecs();
      expect(scene.frameState.commandList[0].renderState.viewport).toEqual(
        otherRectangle
      );
    });

    it("isDestroyed", function () {
      var boundRectangle = new BoundingRectangle(0, 0, 10, 10);
      var vq = new ViewportQuad(boundRectangle);

      expect(vq.isDestroyed()).toEqual(false);
      vq.destroy();
      expect(vq.isDestroyed()).toEqual(true);
    });
  },
  "WebGL"
);
{'fraction_non_alphanumeric': 0.1551296194153337, 'fraction_numerical': 0.019718698290126863, 'mean_word_length': 2.7736732570239333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2338927', 'n_tokens_mistral': 2372, 'n_tokens_neox': 2210, 'n_words': 440}