Skip to content
Snippets Groups Projects
Commit fdc05a8e authored by Nithya's avatar Nithya
Browse files
Test scripts updated
parent 583406ef
No related branches found
No related tags found
1 merge request!196Resolve TMSS-239
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
}, },
"devDependencies": { "devDependencies": {
"customize-cra": "^0.9.1", "customize-cra": "^0.9.1",
"react-app-rewired": "^1.6.2" "react-app-rewired": "^1.6.2",
"babel-polyfill": "^6.26.0"
} }
} }
...@@ -54,8 +54,12 @@ class CycleList extends Component{ ...@@ -54,8 +54,12 @@ class CycleList extends Component{
} }
} }
secondsToHours(d) { secondsToHours(d,type='seconds') {
return UnitConversion.getUIResourceUnit('seconds',d) return UnitConversion.getUIResourceUnit(type,d)
}
toBytes(d,type='bytes'){
return UnitConversion.getUIResourceUnit(type,d)
} }
componentDidMount(){ componentDidMount(){
...@@ -79,7 +83,7 @@ class CycleList extends Component{ ...@@ -79,7 +83,7 @@ class CycleList extends Component{
cycle.longterm = longterm.length; cycle.longterm = longterm.length;
cycle.observingTime = this.secondsToHours((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'observing_time') || {value: 0}).value) cycle.observingTime = this.secondsToHours((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'observing_time') || {value: 0}).value)
cycle.processingTime = this.secondsToHours((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'cep_processing_time') || {value: 0}).value) cycle.processingTime = this.secondsToHours((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'cep_processing_time') || {value: 0}).value)
cycle.ltaResources = ((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'lta_storage') || {value: 0}).value) cycle.ltaResources = this.toBytes((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'lta_storage') || {value: 0}).value)
cycle.support = this.secondsToHours((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'support_time') || {value: 0}).value) cycle.support = this.secondsToHours((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'support_time') || {value: 0}).value)
cycle.observingTimeDDT = this.secondsToHours((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'observing_time_commissioning') || {value: 0}).value) cycle.observingTimeDDT = this.secondsToHours((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'observing_time_commissioning') || {value: 0}).value)
cycle.observingTimePrioA = this.secondsToHours((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'observing_time_prio_a') || {value: 0}).value) cycle.observingTimePrioA = this.secondsToHours((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'observing_time_prio_a') || {value: 0}).value)
...@@ -95,8 +99,6 @@ class CycleList extends Component{ ...@@ -95,8 +99,6 @@ class CycleList extends Component{
} }
render(){ render(){
console.log(this.state.cyclelist)
return ( return (
<> <>
{/* {/*
......
import "babel-polyfill";
import React from 'react';
import { render,fireEvent } from '@testing-library/react';
import CycleList from './CycleList';
import UnitConversion from '../../utils/unit.converter';
jest.mock('../../services/cycle.service', () => {
return {
getProjects: () => Promise.resolve({ data: mockData.getProjects }),
getCycleQuota: () => Promise.resolve({ data: mockData.getCycleQuota }),
getAllCycle: () => Promise.resolve({ data: mockData.getAllCycle })
}
});
const flushPromises = () => new Promise(setImmediate);
describe('<CycleList />', () => {
test('render table in the cycle list', async () => {
const { container } = render(<CycleList />);
await flushPromises();
expect(container.querySelector('table')).toBeInTheDocument();
});
test('render cycle list in row', async () => {
const { container } = render(<CycleList />);
await flushPromises();
expect(container.querySelectorAll('tr').length).toBe(4);
});
test('render columns in the cycle list', async () => {
const { container } = render(<CycleList />);
await flushPromises();
expect(container.querySelectorAll('th').length).toBe(container.querySelectorAll('th').length);
});
test('render cycleId - cycle name conversion', async () => {
const { container } = render(<CycleList />);
await flushPromises();
expect(container.querySelectorAll('tr')[1].innerHTML.includes('Cycle00')).toBeTruthy();
});
test('render observing time in hours', async () => {
const { container } = render(<CycleList />);
await flushPromises();
const observing_time = UnitConversion.getUIResourceUnit('seconds',mockData.getCycleQuota.results[0].value);
expect(container.querySelectorAll('tr')[1].innerHTML.includes(observing_time)).toBeTruthy();
});
test('render commissioning time in hours', async () => {
const { container } = render(<CycleList />);
await flushPromises();
const commissioning_time = UnitConversion.getUIResourceUnit('seconds',mockData.getCycleQuota.results[0].value);
expect(container.querySelectorAll('tr')[1].innerHTML.includes(commissioning_time)).toBeTruthy();
});
test('toggle columns in table', async () => {
const { container } = render(<CycleList />);
await flushPromises();
const panel = container.querySelector('#overlay_panel');
expect(panel).toHaveStyle('display: block');
fireEvent.click(container.querySelector('.col-filter-btn'));
await flushPromises();
expect(panel).toHaveStyle('display: none');
expect(container.querySelectorAll("input[type=checkbox]:checked").length).toBe(container.querySelectorAll('th').length)
});
});
const mockData = {
getProjects: {
"results": [{
"name": "TMSS-Commissioning",
"cycles_ids": ["Cycle 14"],
"private_data": true,
"project_category": null,
"project_category_value": null
}]
},
getCycleQuota: {
"results": [{
"id": 1,
"url": "http://localhost:3000/api/cycle_quota/1/",
"cycle": "http://localhost:3000/api/cycle/Cycle%2000/",
"cycle_id": "Cycle 00",
"resource_type": "http://localhost:3000/api/resource_type/observing_time/",
"resource_type_id": "observing_time",
"value": 10575360.0
},{
"cycle": "http://localhost:3000/api/cycle/Cycle%2000/",
"cycle_id": "Cycle 00",
"id": 5,
"resource_type": "http://localhost:3000/api/resource_type/observing_time_commissioning/",
"resource_type_id": "observing_time_commissioning",
"url": "http://localhost:3000/api/cycle_quota/5/",
"value": 660960
}]
},
getAllCycle: {
"results": [{
"name": "Cycle 00",
"url": "http://localhost:3000/api/cycle/Cycle%2000/",
"created_at": "2020-08-06T12:06:09.074400",
"description": "Lofar Cycle 0",
"duration": 13219200.0,
"projects": [],
"projects_ids": [],
"quota": ["http://localhost:3000/api/cycle_quota/1/", "http://localhost:3000/api/cycle_quota/2/", "http://localhost:3000/api/cycle_quota/3/", "http://localhost:3000/api/cycle_quota/4/", "http://localhost:3000/api/cycle_quota/5/", "http://localhost:3000/api/cycle_quota/6/", "http://localhost:3000/api/cycle_quota/7/"],
"quota_ids": [1, 2, 3, 4, 5, 6, 7],
"start": "2013-06-01T00:00:00",
"stop": "2013-11-01T00:00:00",
"tags": [],
"updated_at": "2020-08-06T12:06:09.074437"
}, {
"name": "Cycle 01",
"url": "http://localhost:3000/api/cycle/Cycle%2001/",
"created_at": "2020-08-06T12:06:09.093253",
"description": "Lofar Cycle 1",
"duration": 18316800.0,
"projects": [],
"projects_ids": [],
"quota": ["http://localhost:3000/api/cycle_quota/8/", "http://localhost:3000/api/cycle_quota/9/", "http://localhost:3000/api/cycle_quota/10/", "http://localhost:3000/api/cycle_quota/11/", "http://localhost:3000/api/cycle_quota/12/", "http://localhost:3000/api/cycle_quota/13/", "http://localhost:3000/api/cycle_quota/14/"],
"quota_ids": [8, 9, 10, 11, 12, 13, 14],
"start": "2013-11-01T00:00:00",
"stop": "2014-06-01T00:00:00",
"tags": [],
"updated_at": "2020-08-06T12:06:09.093283"
}, {
"name": "Cycle 02",
"url": "http://localhost:3000/api/cycle/Cycle%2002/",
"created_at": "2020-08-06T12:06:09.107204",
"description": "Lofar Cycle 2",
"duration": 13219200.0,
"projects": [],
"projects_ids": [],
"quota": ["http://localhost:3000/api/cycle_quota/15/", "http://localhost:3000/api/cycle_quota/16/", "http://localhost:3000/api/cycle_quota/17/", "http://localhost:3000/api/cycle_quota/18/", "http://localhost:3000/api/cycle_quota/19/", "http://localhost:3000/api/cycle_quota/20/", "http://localhost:3000/api/cycle_quota/21/"],
"quota_ids": [15, 16, 17, 18, 19, 20, 21],
"start": "2014-06-01T00:00:00",
"stop": "2014-11-01T00:00:00",
"tags": [],
"updated_at": "2020-08-06T12:06:09.107234"
}]
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment