Add more unit and integration tests (#773)

* Add unit tests for pyloader and pytitle

* Add more unit tests for pyrepl, pybox and pyinputbox

* Add more tests for pyscript and pyconfig

* White space

* Fix d3 tests and improve more examples test

* Update matplotlib test

* Add numpy to dependencies

* Address Madhur comments

* Update test name
This commit is contained in:
Fábio Rosado
2022-09-26 23:17:32 +01:00
committed by GitHub
parent d033ab04da
commit b674515d06
12 changed files with 482 additions and 53 deletions

View File

@@ -1,4 +1,5 @@
import 'jest';
import { PyRepl } from '../../src/components/pyrepl';
customElements.define('py-repl', PyRepl);
@@ -13,4 +14,52 @@ describe('PyRepl', () => {
expect(instance).toBeInstanceOf(PyRepl);
});
it('confirm that codemirror editor is available', async () => {
// We are assuming that if editorNode has the 'editor-box' class
// then the div was created properly.
expect(instance.editorNode.getAttribute('class')).toBe("editor-box")
})
it("connectedCallback gets or sets new id", async () => {
expect(instance.id).toBe("")
instance.connectedCallback()
const instanceId = instance.id;
// id should be similar to py-4850c8c3-d70d-d9e0-03c1-3cfeb0bcec0d
expect(instanceId).toMatch(/py-(\w+-){1,4}\w+/);
// calling checkId directly should return the same id
instance.checkId();
expect(instance.id).toEqual(instanceId);
})
it('confirm that calling connectedCallback renders the expected elements', async () => {
expect(instance.innerHTML).toBe("")
instance.innerHTML = "<p>Hello</p>"
instance.connectedCallback()
expect(instance.code).toBe("<p>Hello</p>")
expect(instance.editorNode.id).toBe("code-editor")
// Just check that the button was created
expect(instance.btnRun.getAttribute("class")).toBe("absolute repl-play-button")
const editorNode = instance.editorNode.innerHTML
expect(editorNode).toContain("Python Script Run Button")
// Confirm that our innerHTML is set as well
expect(editorNode).toContain("Hello")
})
it("confirm that addToOutput updates output element", async () => {
expect(instance.outputElement).toBe(undefined)
// This is just to avoid throwing the test since outputElement is undefined
instance.outputElement = document.createElement("div")
instance.addToOutput("Hello, World!")
expect(instance.outputElement.innerHTML).toBe("<div>Hello, World!</div>")
expect(instance.outputElement.hidden).toBe(false)
})
});