Skip to content

Commit 694bc98

Browse files
Merge pull request #101 from open-source-labs/plogs
add buildOptionsObj testing
2 parents c3e7e35 + a8b61c5 commit 694bc98

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

__tests__/ProcessLogHelper.test.js

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import {makeArrayOfObjects, buildOptionsObj} from '../src/components/helper/processLogHelper.js';
1+
/**
2+
* @jest-environment jsdom
3+
*/
4+
5+
import { makeArrayOfObjects, buildOptionsObj } from '../src/components/helper/processLogHelper.js';
26
import React from 'react';
37

48
describe('makeArrayOfObjects', () => {
@@ -57,4 +61,54 @@ describe('makeArrayOfObjects', () => {
5761
expect(result[0].timeStamp).toEqual('');
5862
expect(result[0].logMsg).toEqual('');
5963
});
60-
});
64+
});
65+
66+
describe('buildOptionsObj', () => {
67+
68+
let sinceButton;
69+
let tailButton;
70+
let sinceInput;
71+
let tailInput;
72+
73+
beforeEach(() => {
74+
sinceButton = document.createElement('input');
75+
sinceButton.setAttribute('type', 'radio');
76+
sinceButton.setAttribute('id', 'sinceInput');
77+
document.body.appendChild(sinceButton);
78+
79+
tailButton = document.createElement('input');
80+
tailButton.setAttribute('id', 'tailInput');
81+
tailButton.setAttribute('type', 'radio');
82+
document.body.appendChild(tailButton);
83+
84+
sinceInput = document.createElement('input');
85+
sinceInput.setAttribute('id', 'sinceText');
86+
sinceInput.setAttribute('value', '72h10m3s');
87+
document.body.appendChild(sinceInput);
88+
89+
tailInput = document.createElement('input');
90+
tailInput.setAttribute('id', 'tailText');
91+
tailInput.setAttribute('value', '1');
92+
document.body.appendChild(tailInput);
93+
});
94+
95+
afterEach(() => {
96+
document.body.innerHTML = '';
97+
});
98+
99+
it('when tail button is checked, tail value is added to optionsObj', () => {
100+
tailButton.checked = true;
101+
102+
const result = buildOptionsObj('containerID');
103+
104+
expect(result.tail).toEqual('1');
105+
});
106+
107+
it('when since button is checked, since value is added to since key on optionsObj', () => {
108+
sinceButton.checked = true;
109+
110+
const result = buildOptionsObj('containerID');
111+
112+
expect(result.since).toEqual('72h10m3s');
113+
});
114+
});

0 commit comments

Comments
 (0)