Skip to content
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

Added testcases #2273

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ describe('<Ticks>', () => {
const wrapper = shallow(<Ticks endTime={200} numTicks={5} showLabels startTime={100} />);
expect(wrapper).toBeDefined();
});

it('should match snapshot', () => {
const wrapper = shallow(<Ticks endTime={200} numTicks={5} showLabels startTime={100} />);
expect(wrapper).toMatchSnapshot()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are trying to move away from snapshot testing. What specifically are you trying to validate?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to validate that if same props are passed, component should render same html. So in future if someone accidentally changes anything in the component, it will be caught by this testcase.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

component should render same html

but the component is not obligated to render the same HTML. Its implementation can change and the test will fail, even though the implementation can still be functionally correct. Tests should be validating use-visible behavior, e.g. you asked for 5 ticks - the result should have 5 ticks.

Copy link
Author

@NitinRamnani NitinRamnani Apr 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct but if we are changing implementation then we should also update the testcase. Snapshot testcase make sure until we haven't made any change in component
then HTML shouldn't also change there by help us in catching any accidentally changes.

});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Ticks> should match snapshot 1`] = `
<div
className="Ticks"
>
<div
className="Ticks--tick"
key="0"
style={
Object {
"left": "0%",
}
}
>
<span
className="Ticks--tickLabel "
>
100μs
</span>
</div>
<div
className="Ticks--tick"
key="0.25"
style={
Object {
"left": "25%",
}
}
>
<span
className="Ticks--tickLabel "
>
125μs
</span>
</div>
<div
className="Ticks--tick"
key="0.5"
style={
Object {
"left": "50%",
}
}
>
<span
className="Ticks--tickLabel "
>
150μs
</span>
</div>
<div
className="Ticks--tick"
key="0.75"
style={
Object {
"left": "75%",
}
}
>
<span
className="Ticks--tickLabel "
>
175μs
</span>
</div>
<div
className="Ticks--tick"
key="1"
style={
Object {
"left": "100%",
}
}
>
<span
className="Ticks--tickLabel isEndAnchor"
>
200μs
</span>
</div>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
isServerSpan,
spanContainsErredSpan,
spanHasTag,
isKindClient,
isKindProducer
} from './utils';

import traceGenerator from '../../../demo/trace-generators';
Expand Down Expand Up @@ -153,5 +155,25 @@ describe('TraceTimelineViewer/utils', () => {
spans[1].depth = spans[0].depth;
expect(findServerChildSpan(spans)).toBeFalsy();
});

it('tests isKindClient function', ()=>{
const span = { depth: 0, tags: [{ key: 'span.kind', value: 'producer' }] }
const result = isKindClient(span)
expect(result).toEqual(false)

const span2 = { depth: 0, tags: [{ key: 'span.kind', value: 'client' }] }
const result2 = isKindClient(span2)
expect(result2).toEqual(true)
})

it('tests isKindProducer function', ()=>{
const span = { depth: 0, tags: [{ key: 'span.kind', value: 'producer' }] }
const result = isKindProducer(span)
expect(result).toEqual(true)

const span2 = { depth: 0, tags: [{ key: 'span.kind', value: 'client' }] }
const result2 = isKindProducer(span2)
expect(result2).toEqual(false)
})
});
});
Loading