Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 456fa2b

Browse files
committedApr 3, 2024
tests(project): Adds tests for variants/optional/turn off cases
1 parent 849b50c commit 456fa2b

File tree

10 files changed

+211
-5
lines changed

10 files changed

+211
-5
lines changed
 
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# A project
2+
3+
## Índice
4+
5+
Blah blah blah
6+
7+
***
8+
9+
## 1. Preámbulo
10+
11+
Blah blah blah
12+
13+
## 2. Resumen del proyecto
14+
15+
Blah blah blah
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
track: web-dev
2+
tracks:
3+
- web-dev
4+
learningObjectives:
5+
- html/semantics
6+
- css/selectors
7+
- dom/selectors
8+
- dom/events
9+
- dom/manipulation
10+
- js/data-types/primitive-vs-non-primitive
11+
- js/data-types/strings
12+
- js/variables
13+
- js/conditionals
14+
- js/functions
15+
- js/semantics
16+
- ux/user-understanding
17+
- ux/prototyping
18+
- css: false

‎lib/__tests__/__fixtures__/01-a-project-with-optional-learning-objectives/project.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ learningObjectives:
1515
- js/semantics
1616
- ux/user-understanding
1717
- ux/prototyping
18-
- object-oriented-programming:
18+
- react:
1919
optional: true
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# A project
2+
3+
## Índice
4+
5+
Blah blah blah
6+
7+
***
8+
9+
## 1. Preámbulo
10+
11+
Blah blah blah
12+
13+
## 2. Resumen del proyecto
14+
15+
Blah blah blah
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
track: web-dev
2+
tracks:
3+
- web-dev
4+
learningObjectives:
5+
- html/semantics
6+
- css/selectors
7+
- dom/selectors
8+
- dom/events
9+
- dom/manipulation
10+
- js/data-types/primitive-vs-non-primitive
11+
- js/data-types/strings
12+
- js/variables
13+
- js/conditionals
14+
- js/functions
15+
- js/semantics
16+
- ux/user-understanding
17+
- ux/prototyping
18+
- react:
19+
optional: true
20+
variants:
21+
- name: node
22+
learningObjectives:
23+
- node
24+
- react:
25+
optional: true
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# A project
2+
3+
## Índice
4+
5+
Blah blah blah
6+
7+
***
8+
9+
## 1. Preámbulo
10+
11+
Blah blah blah
12+
13+
## 2. Resumen del proyecto
14+
15+
Blah blah blah
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
track: web-dev
2+
tracks:
3+
- web-dev
4+
learningObjectives:
5+
- html/semantics
6+
- css/selectors
7+
- dom/selectors
8+
- dom/events
9+
- dom/manipulation
10+
- js/data-types/primitive-vs-non-primitive
11+
- js/data-types/strings
12+
- js/variables
13+
- js/conditionals
14+
- js/functions
15+
- js/semantics
16+
- ux/user-understanding
17+
- ux/prototyping
18+
variants:
19+
- name: cli
20+
learningObjectives:
21+
- css: false

‎lib/__tests__/__snapshots__/project.spec.js.snap‎

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,62 @@ exports[`parseProject > should include learning objectives from variant if a var
173173

174174
exports[`parseProject > should include optional learning objectives if theyre present 1`] = `
175175
[
176-
"object-oriented-programming",
176+
"react/jsx",
177+
"react/components",
178+
"react/events",
179+
"react/lists-and-keys",
180+
"react/conditional-rendering",
181+
"react/lifting-up-state",
182+
"react/hooks",
183+
"react/css-modules",
184+
"react/routing",
185+
]
186+
`;
187+
188+
exports[`parseProject > should not duplicate optional lo if its present in both normal and variant los 1`] = `
189+
[
190+
"react/jsx",
191+
"react/components",
192+
"react/events",
193+
"react/lists-and-keys",
194+
"react/conditional-rendering",
195+
"react/lifting-up-state",
196+
"react/hooks",
197+
"react/css-modules",
198+
"react/routing",
199+
]
200+
`;
201+
202+
exports[`parseProject > should turn off a learning objective if its value is false 1`] = `
203+
[
204+
"html/semantics",
205+
"dom/selectors",
206+
"dom/events",
207+
"dom/manipulation",
208+
"js/data-types/primitive-vs-non-primitive",
209+
"js/data-types/strings",
210+
"js/variables/declaration",
211+
"js/conditionals",
212+
"js/functions",
213+
"js/semantics",
214+
"ux/user-understanding",
215+
"ux/prototyping",
216+
]
217+
`;
218+
219+
exports[`parseProject > should turn off a variant learning objective if its value is false 1`] = `
220+
[
221+
"html/semantics",
222+
"dom/selectors",
223+
"dom/events",
224+
"dom/manipulation",
225+
"js/data-types/primitive-vs-non-primitive",
226+
"js/data-types/strings",
227+
"js/variables/declaration",
228+
"js/conditionals",
229+
"js/functions",
230+
"js/semantics",
231+
"ux/user-understanding",
232+
"ux/prototyping",
177233
]
178234
`;

‎lib/__tests__/project.spec.js‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,44 @@ describe('parseProject', () => {
184184
});
185185
});
186186

187+
it('should turn off a learning objective if its value is false', () => {
188+
const p = resolveFixturePath('01-a-project-with-learning-objectives-turned-off');
189+
return parseProject(p, {
190+
repo: 'Laboratoria/bootcamp',
191+
version: '1.0.0',
192+
lo: path.join(__dirname, '__fixtures__', 'learning-objectives'),
193+
}, pkg)
194+
.then((result) => {
195+
expect(result.learningObjectives).toMatchSnapshot();
196+
});
197+
});
198+
199+
it('should turn off a variant learning objective if its value is false', () => {
200+
const p = resolveFixturePath('01-a-project-with-variant-learning-objectives-turned-off');
201+
return parseProject(p, {
202+
repo: 'Laboratoria/bootcamp',
203+
version: '1.0.0',
204+
lo: path.join(__dirname, '__fixtures__', 'learning-objectives'),
205+
variants: 'cli',
206+
}, pkg)
207+
.then((result) => {
208+
expect(result.learningObjectives).toMatchSnapshot();
209+
});
210+
});
211+
212+
it('should not duplicate optional lo if its present in both normal and variant los', () => {
213+
const p = resolveFixturePath('01-a-project-with-variant-learning-objectives-duplicated');
214+
return parseProject(p, {
215+
repo: 'Laboratoria/bootcamp',
216+
version: '1.0.0',
217+
lo: path.join(__dirname, '__fixtures__', 'learning-objectives'),
218+
variants: 'node',
219+
}, pkg)
220+
.then((result) => {
221+
expect(result.optionalLearningObjectives).toMatchSnapshot();
222+
});
223+
});
224+
187225
it('extracts first paragraph of _resumen del proyecto_ as summary', () => {
188226
const p = resolveFixturePath('01-a-project-with-summary');
189227
expect.assertions(2);

‎lib/project.js‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,14 @@ export const transformLearningObjectives = async (dir, opts, meta) => {
132132
const variantOptions = opts.variants?.split(',') || [];
133133

134134
learningObjectives.forEach((learningObjective) => {
135-
// console.log(learningObjective);
136135
if (typeof learningObjective === 'object') {
137136
if (!learningObjective[Object.keys(learningObjective)[0]]) {
137+
const index = learningObjectives.indexOf(learningObjective);
138+
if (index > -1) {
139+
learningObjectives.splice(index, 1);
140+
}
138141
learningObjectives = learningObjectives.filter(
139-
item => item !== Object.keys(learningObjective)[0],
142+
item => !item.includes(Object.keys(learningObjective)[0]),
140143
);
141144
}
142145

@@ -161,7 +164,7 @@ export const transformLearningObjectives = async (dir, opts, meta) => {
161164
if (typeof learningObjective === 'object') {
162165
if (!learningObjective[Object.keys(learningObjective)[0]]) {
163166
learningObjectives = learningObjectives.filter(
164-
item => item !== Object.keys(learningObjective)[0],
167+
item => !item.includes(Object.keys(learningObjective)[0]),
165168
);
166169
}
167170

0 commit comments

Comments
 (0)
Please sign in to comment.