From 66f5c4bfc2ee92dbe212e4774852db65e8a20f71 Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 7 Oct 2021 08:41:53 -0600 Subject: [PATCH] Add start of Et2Date tests --- api/js/etemplate/Et2Date/test/Et2Date.test.ts | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 api/js/etemplate/Et2Date/test/Et2Date.test.ts diff --git a/api/js/etemplate/Et2Date/test/Et2Date.test.ts b/api/js/etemplate/Et2Date/test/Et2Date.test.ts new file mode 100644 index 0000000000..0a17c118b3 --- /dev/null +++ b/api/js/etemplate/Et2Date/test/Et2Date.test.ts @@ -0,0 +1,61 @@ +/** + * Test file for Etemplate webComponent Date + */ +import {assert, fixture} from '@open-wc/testing'; +import {Et2Date} from "../Et2Date"; +import {html} from "lit-element"; +import * as sinon from 'sinon'; + +describe("Date widget", () => +{ + // Reference to component under test + let element : Et2Date; + + // Setup run before each test + beforeEach(async() => + { + // Create an element to test with, and wait until it's ready + // @ts-ignore + element = await fixture(html` + + `); + + // Stub egw() + sinon.stub(element, "egw").returns({ + tooltipUnbind: () => {}, + // Image always give check mark. Use data URL to avoid having to serve an actual image + image: i => "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNS4wLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkViZW5lXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB3aWR0aD0iMzJweCIgaGVpZ2h0PSIzMnB4IiB2aWV3Qm94PSIwIDAgMzIgMzIiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDMyIDMyIiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBmaWxsPSIjNjk2OTY5IiBkPSJNNi45NDMsMjguNDUzDQoJYzAuOTA2LDAuNzY1LDIuMDk3LDEuMTI3LDMuMjg2LDEuMTA5YzAuNDMsMC4wMTQsMC44NTItMC4wNjgsMS4yNjUtMC4yMDdjMC42NzktMC4xOCwxLjMyOC0wLjQ1LDEuODY2LTAuOTAyTDI5LjQwMywxNC45DQoJYzEuNzcyLTEuNDk4LDEuNzcyLTMuOTI1LDAtNS40MjJjLTEuNzcyLTEuNDk3LTQuNjQ2LTEuNDk3LTYuNDE4LDBMMTAuMTE5LDIwLjM0OWwtMi4zODktMi40MjRjLTEuNDQtMS40NTctMy43NzItMS40NTctNS4yMTIsMA0KCWMtMS40MzgsMS40Ni0xLjQzOCwzLjgyNSwwLDUuMjgxQzIuNTE4LDIzLjIwNiw1LjQ3NCwyNi45NDcsNi45NDMsMjguNDUzeiIvPg0KPC9zdmc+DQo=" + }); + }); + + // Make sure it works + it('is defined', () => + { + assert.instanceOf(element, Et2Date); + }); + + it('has a label', () => + { + element.set_label("Label set"); + + assert.equal(element.querySelector("[slot='label']").textContent, "Label set"); + }) + + const tz_list = ['US/Pacific','UTC','Australia/Adelaide']; + for(let tz of tz_list) + { + // TODO: Figure out how to mock timezone... + describe("Timezone: " + tz, () => + { + let test_time_string = '2008-09-22 12:00:00Z'; + let test_time = new Date(test_time_string); + it('Can accept a value', () => + { + element.set_value(test_time_string); + + // Widget gives time as a string so we can send to server + assert(element.getValue(), test_time_string); + }); + }); + } +}); \ No newline at end of file