Skip to content

Commit 884117b

Browse files
test: add tests for handleChallengeTitle util (#1566)
1 parent 04fd08f commit 884117b

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:freecodecamp/models/learn/challenge_model.dart';
3+
import 'package:freecodecamp/models/learn/curriculum_model.dart';
4+
import 'package:freecodecamp/ui/views/learn/utils/challenge_utils.dart';
5+
6+
void main() {
7+
Challenge createChallenge({
8+
required String id,
9+
required String title,
10+
}) {
11+
return Challenge(
12+
id: id,
13+
block: 'block1',
14+
title: title,
15+
description: '',
16+
instructions: '',
17+
dashedName: 'challenge-$id',
18+
superBlock: 'superblock',
19+
challengeType: 0,
20+
tests: [],
21+
files: [],
22+
helpCategory: HelpCategory.htmlCss,
23+
transcript: '',
24+
hooks: Hooks(beforeAll: '', beforeEach: '', afterEach: ''),
25+
);
26+
}
27+
28+
Block createBlock(List<Challenge> challenges) {
29+
return Block(
30+
superBlock: SuperBlock(dashedName: 'superblock', name: 'Super Block'),
31+
layout: BlockLayout.challengeList,
32+
type: BlockType.lecture,
33+
name: 'Block 1',
34+
dashedName: 'block-1',
35+
description: [],
36+
challenges: challenges
37+
.map((c) => ChallengeOrder(id: c.id, title: c.title))
38+
.toList(),
39+
challengeTiles: [],
40+
);
41+
}
42+
43+
group('handleChallengeTitle', () {
44+
test('should return empty string if the block contains a single challenge',
45+
() {
46+
final challenge = createChallenge(id: '1', title: 'HTML Review');
47+
final block = createBlock([challenge]);
48+
49+
expect(handleChallengeTitle(challenge, block), '');
50+
});
51+
52+
test("should return empty string when challenge title contains 'Dialogue'",
53+
() {
54+
final challenge = createChallenge(id: '1', title: 'Dialogue 1');
55+
final block = createBlock([challenge]);
56+
57+
expect(handleChallengeTitle(challenge, block), '');
58+
});
59+
60+
test("should return empty string when challenge title contains 'Step'", () {
61+
final challenge = createChallenge(id: '1', title: 'Step 1');
62+
final other = createChallenge(id: '2', title: 'Task 1');
63+
final block = createBlock([challenge, other]);
64+
65+
expect(handleChallengeTitle(challenge, block), '');
66+
});
67+
68+
test('should return correct Task title with count', () {
69+
final dialogue = createChallenge(id: '3', title: 'Dialogue 1');
70+
final challenge1 = createChallenge(id: '1', title: 'Task 1');
71+
final challenge2 = createChallenge(id: '2', title: 'Task 2');
72+
final challenge3 = createChallenge(id: '3', title: 'Task 3');
73+
final block = createBlock([dialogue, challenge1, challenge2, challenge3]);
74+
75+
expect(handleChallengeTitle(challenge1, block), 'Task 1 of 3');
76+
expect(handleChallengeTitle(challenge2, block), 'Task 2 of 3');
77+
expect(handleChallengeTitle(challenge3, block), 'Task 3 of 3');
78+
});
79+
80+
test('should return correct Step title with count', () {
81+
final challenge1 = createChallenge(id: '1', title: 'Intro');
82+
final challenge2 = createChallenge(id: '2', title: 'Content');
83+
final block = createBlock([challenge1, challenge2]);
84+
85+
expect(handleChallengeTitle(challenge1, block), 'Step 1 of 2');
86+
expect(handleChallengeTitle(challenge2, block), 'Step 2 of 2');
87+
});
88+
});
89+
}

0 commit comments

Comments
 (0)