Skip to content

Commit

Permalink
Test updates and fixes for Jest
Browse files Browse the repository at this point in the history
  • Loading branch information
droberts-ctrlo committed Jan 24, 2025
1 parent 12887aa commit bca6579
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/frontend/components/button/lib/common.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "../../../testing/globals.definitions";
import {layoutId, recordId, table_key} from "./common";
import {describe, it, expect} from "@jest/globals";

describe("Common button tests",()=>{
it("should populate table_key",()=>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {jest, describe, it, expect, beforeAll, afterEach} from "@jest/globals";
import createRemoveCurvalButton from "./remove-curval-button";

describe("RemoveCurvalButton", ()=>{
// @ts-ignore
window.confirm = jest.fn().mockReturnValue(true);

beforeAll(()=>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import '@testing-library/dom';
import { describe, it, expect, jest } from '@jest/globals';

import DashboardView from './DashboardView';
import { DashboardProps, WidgetProps } from '../types';
import ReactGridLayout, { ReactGridLayoutProps } from 'react-grid-layout';
import { WidgetProps } from '../types';
import { ReactGridLayoutProps } from 'react-grid-layout';

describe('DashboardView', () => {
it('Creates a dashboard', () => {
Expand Down
4 changes: 3 additions & 1 deletion src/frontend/js/lib/set-field-value.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import buttonComponent from "../../components/button";
import multipleSelectComponent from "../../components/form-group/multiple-select";
import selectWidgetComponent from "../../components/form-group/select-widget";
import textAreaComponent from "../../components/form-group/textarea";
import { describe, it, expect } from '@jest/globals';
import { describe, it, expect, jest, beforeEach } from '@jest/globals';
import { setFieldValues } from "./set-field-values";

declare global {
Expand All @@ -16,7 +16,9 @@ declare global {
}

(($)=>{
// @ts-ignore
$.fn.renameButton = jest.fn().mockReturnThis();
// @ts-ignore
$.fn.filedrag = jest.fn().mockReturnThis();
})(jQuery);

Expand Down
4 changes: 3 additions & 1 deletion src/frontend/js/lib/util/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, it, expect, jest, beforeEach, afterEach } from "@jest/globals
import { fromJson, hideElement, showElement, initJquery } from "./common";

describe('common functions', () => {
describe.skip('CSS and ARIA - skipped as they are incorrect',()=>{
describe('CSS and ARIA - skipped as they are incorrect',()=>{
let el: JQuery<HTMLElement>;

beforeEach(() => {
Expand Down Expand Up @@ -78,12 +78,14 @@ describe('common functions', () => {

it('returns an empty object for null', ()=>{
const json = null;
// @ts-ignore
const parsed = fromJson(json);
expect(parsed).toEqual({});
});

it('returns an empty object for undefined', ()=>{
const json = undefined;
// @ts-ignore
const parsed = fromJson(json);
expect(parsed).toEqual({});
});
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/js/lib/util/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const hideElement = (element: HTMLElement | JQuery<HTMLElement>) => {
const $el = $(element);
const $el = element instanceof HTMLElement ? $(element) : element;
if($el.hasClass('hidden')) return;
$el.addClass('hidden');
$el.attr('aria-hidden', 'true');
Expand All @@ -8,7 +8,7 @@ export const hideElement = (element: HTMLElement | JQuery<HTMLElement>) => {
};

export const showElement = (element: HTMLElement |JQuery<HTMLElement>) => {
const $el = $(element);
const $el = element instanceof HTMLElement ? $(element) : element;
if (!$el.hasClass('hidden')) return;
$el.removeClass('hidden');
$el.removeAttr('aria-hidden');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { setupCrypto } from '../../../../../testing/globals.definitions';
import { setupCrypto } from 'testing/globals.definitions';
import { EncryptedStorage } from './encryptedStorage';
import {describe, expect, beforeAll, beforeEach, afterEach, it} from "@jest/globals";

class TestStorage implements Storage {
private map = new Map<string, string>();
Expand Down
5 changes: 2 additions & 3 deletions src/frontend/js/lib/util/gadsStorage/lib/AppStorage.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import "../../../../../testing/globals.definitions";
import { describe, it, expect, jest } from "@jest/globals";
import { describe, it, expect, jest, afterEach } from "@jest/globals";
import { AppStorage } from "./AppStorage";
import { GadsStorage } from "./GadsStorage";
import { NullStorage } from "./NullStorage";
import { setupCrypto } from "../../../../../testing/globals.definitions";
import { setupCrypto } from "testing/globals.definitions";

describe("AppStorage", () => {
afterEach(() => {
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/js/lib/util/gadsStorage/lib/GadsStorage.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "../../../../../testing/globals.definitions";
import { describe, it, expect, beforeAll, beforeEach, afterEach } from "@jest/globals";
import { GadsStorage } from "./GadsStorage";
import { killNoMockCrypto, setupCrypto, setupNoMockCrypto } from "../../../../../testing/globals.definitions";
import { killNoMockCrypto, setupCrypto, setupNoMockCrypto } from "testing/globals.definitions";

if (!process.versions.node.startsWith("18")) {
describe("GadsStorage", () => {
Expand Down

0 comments on commit bca6579

Please sign in to comment.