Skip to content

Commit 318a504

Browse files
chore: improve util test coverage (#232)
1 parent 8098e55 commit 318a504

File tree

4 files changed

+175
-0
lines changed

4 files changed

+175
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright 2024 Google LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { CapacityQuantityLabelPipe } from './capacity-quantity-label.pipe';
18+
19+
describe('CapacityQuantityLabelPipe', () => {
20+
const pipe = new CapacityQuantityLabelPipe();
21+
22+
it('returns undefined when fed a null value', () => {
23+
expect(pipe.transform(null)).toBeUndefined();
24+
});
25+
26+
it('returns undefined when fed an empty string', () => {
27+
expect(pipe.transform('')).toBeUndefined();
28+
});
29+
30+
it('capitalizes a valid string by default', () => {
31+
expect(pipe.transform('label')).toBe('Label');
32+
});
33+
34+
it('does not capitalize a valid string', () => {
35+
expect(pipe.transform('label', false)).toBe('label');
36+
});
37+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright 2024 Google LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { CapacityQuantityUnitPipe } from './capacity-quantity-unit.pipe';
18+
19+
describe('CapacityQuantityUnitPipe', () => {
20+
const pipe = new CapacityQuantityUnitPipe();
21+
22+
it('returns undefined when fed a null value', () => {
23+
expect(pipe.transform(null)).toBeUndefined();
24+
});
25+
26+
it('returns undefined when value cannot be split', () => {
27+
expect(pipe.transform('label')).toBeUndefined();
28+
});
29+
30+
it('returns default string when no abbreviations are provided', () => {
31+
expect(pipe.transform('weight_kilograms')).toBe('kilograms');
32+
});
33+
34+
it('returns default string when abbreviations is not found', () => {
35+
expect(pipe.transform('weight_kilograms', { pounds: 'lb' })).toBe('kilograms');
36+
});
37+
38+
it('returns abbreviation when provided', () => {
39+
expect(pipe.transform('weight_kilograms', { kilograms: 'kg' })).toBe('kg');
40+
});
41+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright 2024 Google LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { DistanceLimitPipe } from './distance-limit.pipe';
18+
19+
describe('DistanceLimitPipe', () => {
20+
const pipe = new DistanceLimitPipe();
21+
22+
it('returns undefined when fed a null value', () => {
23+
expect(pipe.transform()).toBeUndefined();
24+
expect(pipe.transform(null)).toBeUndefined();
25+
});
26+
27+
it('returns null values when fed null values', () => {
28+
expect(pipe.transform({})).toEqual({
29+
maxMeters: null,
30+
maxSoftMeters: null,
31+
costPerKilometerAfterSoftMax: null,
32+
});
33+
});
34+
35+
it('returns numbers when fed numbers', () => {
36+
expect(
37+
pipe.transform({
38+
maxMeters: 100,
39+
softMaxMeters: 10,
40+
costPerKilometerBelowSoftMax: 5,
41+
costPerKilometerAboveSoftMax: 8,
42+
})
43+
).toEqual({
44+
maxMeters: 100,
45+
maxSoftMeters: 10,
46+
costPerKilometerAfterSoftMax: 8,
47+
});
48+
});
49+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Copyright 2024 Google LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { DurationLimitPipe } from './duration-limit.pipe';
18+
19+
describe('DurationLimitPipe', () => {
20+
const pipe = new DurationLimitPipe();
21+
22+
it('returns undefined when fed a null value', () => {
23+
expect(pipe.transform()).toBeUndefined();
24+
expect(pipe.transform(null)).toBeUndefined();
25+
});
26+
27+
it('returns undefined values when fed undefined values', () => {
28+
expect(pipe.transform({})).toEqual({
29+
maxDuration: undefined,
30+
softMaxDuration: undefined,
31+
costPerHourAfterSoftMax: undefined,
32+
});
33+
});
34+
35+
it('returns numbers when fed numbers', () => {
36+
expect(
37+
pipe.transform({
38+
maxDuration: { seconds: 100, nanos: 500 },
39+
softMaxDuration: { seconds: 10, nanos: 20 },
40+
costPerHourAfterSoftMax: 10,
41+
})
42+
).toEqual({
43+
maxDuration: { seconds: 100, nanos: 500 },
44+
softMaxDuration: { seconds: 10, nanos: 20 },
45+
costPerHourAfterSoftMax: 10,
46+
});
47+
});
48+
});

0 commit comments

Comments
 (0)