Skip to content

Commit

Permalink
Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Jun 9, 2021
1 parent 68e0ec8 commit f30f4ec
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ui/src/app/core/utility/array_move.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {array_move} from './array_move';

it('shifts an item in an array by +1 index', () => {
expect(array_move([1, 2], 0, 1)).toEqual([2, 1]);
});

it('shifts an item in an array by -1 index', () => {
expect(array_move([1, 2], 1, 0)).toEqual([2, 1]);
});
11 changes: 11 additions & 0 deletions ui/src/app/core/utility/download_as_xml.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as FileSaver from 'file-saver';
import { downloadAsXml } from './download_as_xml';
jest.mock('file-saver');

it('attempts to save the provided content', () => {
const name = 'foo.xml';
const xml = '<bar></bar>';

downloadAsXml(name, xml);
expect(FileSaver.saveAs).toHaveBeenCalled();
});
10 changes: 10 additions & 0 deletions ui/src/app/core/utility/get_cookie.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { get_cookie } from './get_cookie';

Object.defineProperty(window.document, 'cookie', {
writable: true,
value: 'XSRF=FOOBAR',
});

it('should retrieve the XSRF Cookie', () => {
expect(get_cookie('XSRF')).toEqual('FOOBAR');
});
9 changes: 9 additions & 0 deletions ui/src/app/core/utility/is_valid_regex.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { isValidRegex } from './is_valid_regex';

it('should return false for a malformed regular expression', () => {
expect(isValidRegex(`\\f;klsdflk;sdf()**(&*&^^()`)).toBe(false)
});

it('should return true for a well-formed regular expression', () => {
expect(isValidRegex(`[a-z0-9][a-z0-9-]{0,31}:`)).toBe(true)
});
14 changes: 14 additions & 0 deletions ui/src/app/core/utility/remove_null.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { removeNull } from './remove_null';

it('should remove null values from an object', () => {

const obj = {
foo: null,
bar: {
baz: null
}
};

expect(removeNull(obj, true)).toEqual({});
expect(removeNull(obj, false)).toEqual({bar: { baz: null }});
});
5 changes: 5 additions & 0 deletions ui/src/app/core/utility/uuid.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { uuid } from './uuid';

it('should return a valid uuid', () => {
expect(uuid()).toMatch(/[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/);
});
44 changes: 44 additions & 0 deletions ui/src/app/metadata/hoc/MetadataSchema.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from "react";
import ReactDOM from 'react-dom';
import { render, screen } from "@testing-library/react";
import { act } from 'react-dom/test-utils';
import { MetadataSchema, useMetadataDefinitionContext } from './MetadataSchema';

let container;
beforeEach(() => {
container = document.createElement('div');
document.body.appendChild(container);
});

afterEach(() => {
document.body.removeChild(container);
container = null;
});

const Tester = () => {
const definition = useMetadataDefinitionContext();

return (
<>
<>{definition.type}</>
</>
);
}


xdescribe("<MetadataSchema />", () => {
/*xact(() => {
ReactDOM.render(
<MetadataSchema type="source">
<Tester></Tester>
</MetadataSchema>,
container
);
});*/

xdescribe("definition context", () => {
it("should provide the type of the definition", () => {
expect(screen.getByText('@MetadataProvider')).toBeTruthy();
});
});
});
Empty file.
Empty file.
Empty file.

0 comments on commit f30f4ec

Please sign in to comment.