-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit test and documentation #20
Changes from 11 commits
3051e88
fc2bc6f
3237b53
82a5444
509855d
562d98e
d6fc43f
5162e86
b454298
5ac4f35
4368e96
a5a3012
5dc385f
635726f
e66524d
e5608ab
772d351
01d63f4
e0b051b
9de72f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,27 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
/* eslint-disable class-methods-use-this */ | ||
import { expect, describe, it } from '@jest/globals'; | ||
import Grid from '@mui/material/Grid'; | ||
import { render } from '@testing-library/react'; | ||
import * as React from 'react'; | ||
import Dashboard from '../src/route/dashboard/Dashboard'; | ||
import 'resize-observer-polyfill'; | ||
import { render, screen } from '@testing-library/react'; | ||
import Dashboard from 'route/dashboard/Dashboard'; | ||
|
||
class ResizeObserverMock { | ||
observe() {} | ||
|
||
unobserve() {} | ||
|
||
disconnect() {} | ||
} | ||
jest.mock('route/history/Chart', () => ({ | ||
default: () => <div>chart-mock</div>, | ||
})); | ||
jest.mock('route/history/RecentRuns', () => ({ | ||
default: () => <div>recent-runs-mock</div>, | ||
})); | ||
|
||
describe('Dashboard', () => { | ||
it('renders Dashboard without crashing', () => { | ||
window.ResizeObserver = | ||
ResizeObserverMock as unknown as typeof ResizeObserver; | ||
render( | ||
<Grid container spacing={3} sx={{ minHeight: '100%' }}> | ||
<Dashboard /> | ||
</Grid> | ||
); | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('renders Dashboard', () => { | ||
render(<Dashboard />); | ||
expect(true); | ||
}); | ||
|
||
it('renders Chart and RecentRuns components', () => { | ||
render(<Dashboard />); | ||
expect(screen.queryByText('chart-mock')).toBeInTheDocument(); | ||
expect(screen.queryByText('recent-runs-mock')).toBeInTheDocument(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import { expect, describe, it } from '@jest/globals'; | ||
import { render } from '@testing-library/react'; | ||
import * as React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import DigitalTwins from '../src/route/digitaltwins/DigitalTwins'; | ||
|
||
jest.mock('route/digitaltwins/Workflows', () => ({ | ||
default: () => <div>workflows-mock</div>, | ||
})); | ||
|
||
describe('Digital Twins', () => { | ||
it('Reder OK', () => { | ||
render( | ||
<DigitalTwins /> | ||
); | ||
it('reder DigitalTwin', () => { | ||
render(<DigitalTwins />); | ||
expect(true); | ||
}); | ||
|
||
it('renders Dashboard woth components', () => { | ||
render(<DigitalTwins />); | ||
expect(screen.queryByText('workflows-mock')).toBeInTheDocument(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,34 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { describe, expect, it } from '@jest/globals'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
import { render, screen } from '@testing-library/react'; | ||
import Iframe from '../src/components/Iframe'; | ||
|
||
describe('Iframe', () => { | ||
const url = 'https://example.com/'; | ||
const title = 'Example website'; | ||
var iframe: HTMLIFrameElement; | ||
|
||
beforeEach(() => { | ||
render(<Iframe url="https://example.com/" title="Example" />); | ||
iframe = screen.getByTitle('Example') as HTMLIFrameElement; | ||
}); | ||
|
||
it('renders an iframe element with correct src and title', () => { | ||
const { getByTitle } = render(<Iframe url={url} title={title} />); | ||
const iframe = getByTitle(title); | ||
expect(iframe).toHaveProperty('src', url); | ||
it('renders an iframe element with the correct src and title', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 2 locations. Consider refactoring. |
||
expect(iframe.src).toBe('https://example.com/'); | ||
}); | ||
|
||
it('renders an iframe element with correct width', () => { | ||
const { getByTitle } = render(<Iframe url={url} title={title} />); | ||
const iframe = getByTitle(title); | ||
expect(iframe).toHaveProperty('width', '100%'); | ||
it('sets the iframe width to 100%', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 2 locations. Consider refactoring. |
||
expect(iframe.width).toBe('100%'); | ||
}); | ||
|
||
// it('renders an iframe element with fullsize style when fullsize prop is true', () => { | ||
// const { getByTitle } = render( | ||
// <Iframe url={url} title={title} fullsize={true} /> | ||
// ); | ||
// const iframe = getByTitle(title); | ||
// expect(iframe).toHaveStyle({ flexGrow: 1 }); | ||
// }); | ||
it('sets the iframe height to 100% if fullsize prop is not provided', () => { | ||
expect(iframe.style.height).toBe('100%'); | ||
expect(iframe.style.flexGrow).toBe(''); | ||
}); | ||
}); | ||
|
||
// it('renders an iframe element with height style when fullsize prop is false', () => { | ||
// const { getByTitle } = render( | ||
// <Iframe url={url} title={title} fullsize={false} /> | ||
// ); | ||
// const iframe = getByTitle(title); | ||
// expect(iframe).toHaveStyle({ height: '100%' }); | ||
// }); | ||
describe('Iframe fullsize', () => { | ||
it('sets the iframe height to auto if fullsize prop is provided', () => { | ||
render(<Iframe url="https://example.com/" title="Example" fullsize />); | ||
const iframe = screen.getByTitle('Example') as HTMLIFrameElement; | ||
expect(iframe.style.flexGrow).toBe('1'); | ||
expect(iframe.style.height).toBe(''); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@prasadtalasila So codeclimate is kind of dumb when it comes to test... Is it okay if we exclude test from codeclimate or how do we prevent this redunt code smell?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SyntaxXeror
Please check codeclimate config docs. If I am not mistaken, there must be a way to skip this problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@prasadtalasila you already replyed to this early where you wrote directly from email, so this is fixed :)