Skip to content

Commit

Permalink
feat(project): Excluye OAs duplicados de variantes
Browse files Browse the repository at this point in the history
  • Loading branch information
lupomontero committed May 22, 2024
1 parent 850bb34 commit 7d7718b
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# A project

## Índice

Blah blah blah

***

## 1. Preámbulo

Blah blah blah

## 2. Resumen del proyecto

Blah blah blah
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
track: web-dev
tracks:
- web-dev
learningObjectives:
- html/semantics
- css/selectors
- name: react
optional: true
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ learningObjectives:
variants:
- name: node
learningObjectives:
- html/semantics
- node
- id: react
optional: true
Expand Down
132 changes: 132 additions & 0 deletions lib/__tests__/__snapshots__/project.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,137 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`parseProject > does not duplicate optional lo if its present in both normal and variant los 1`] = `
[
{
"id": "html/semantics",
},
{
"id": "css/selectors",
},
{
"id": "dom/selectors",
},
{
"id": "dom/events",
},
{
"id": "dom/manipulation",
},
{
"id": "js/data-types/primitive-vs-non-primitive",
},
{
"id": "js/data-types/strings",
},
{
"id": "js/variables/declaration",
},
{
"id": "js/conditionals",
},
{
"id": "js/functions",
},
{
"id": "js/semantics",
},
{
"id": "ux/user-understanding",
},
{
"id": "ux/prototyping",
},
{
"id": "react/jsx",
"optional": true,
},
{
"id": "react/components",
"optional": true,
},
{
"id": "react/events",
"optional": true,
},
{
"id": "react/lists-and-keys",
"optional": true,
},
{
"id": "react/conditional-rendering",
"optional": true,
},
{
"id": "react/lifting-up-state",
"optional": true,
},
{
"id": "react/hooks",
"optional": true,
},
{
"id": "react/css-modules",
"optional": true,
},
{
"id": "react/routing",
"optional": true,
},
]
`;

exports[`parseProject > does not duplicate optional lo if its present in both normal and variant los 2`] = `
[
{
"id": "node/npm-install",
},
{
"id": "node/package.json",
},
{
"id": "node/npm-scripts",
},
{
"id": "node/process",
},
{
"id": "node/filesystem",
},
{
"id": "angular/components-and-templates",
"optional": true,
},
{
"id": "angular/structural-directives",
"optional": true,
},
{
"id": "angular/input-output",
"optional": true,
},
{
"id": "angular/services",
"optional": true,
},
{
"id": "angular/routing",
"optional": true,
},
{
"id": "angular/observables",
"optional": true,
},
{
"id": "angular/http-client",
"optional": true,
},
{
"id": "angular/styles",
"optional": true,
},
]
`;

exports[`parseProject > expands learning objectives children when only parent is mentioned 1`] = `
[
{
Expand Down
19 changes: 16 additions & 3 deletions lib/__tests__/project.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe('parseProject', () => {
});
});

it.skip('does not duplicate optional lo if its present in both normal and variant los', () => {
it('does not duplicate optional lo if its present in both normal and variant los', () => {
const p = resolveFixturePath('01-a-project-with-variant-learning-objectives-duplicated');
return parseProject(p, {
repo: 'Laboratoria/bootcamp',
Expand All @@ -218,8 +218,21 @@ describe('parseProject', () => {
}, pkg)
.then((result) => {
const [variant] = result.variants;
console.log(variant);
// expect(result.optionalLearningObjectives).toMatchSnapshot();
expect(result.learningObjectives).toMatchSnapshot();
expect(variant.learningObjectives).toMatchSnapshot();
});
});

it('throws when LO does not have an id', () => {
const p = resolveFixturePath('01-a-project-with-invalid-learning-objectives');
expect.assertions(1);
return parseProject(p, {
repo: 'Laboratoria/bootcamp',
version: '1.0.0',
lo: path.join(__dirname, '__fixtures__', 'learning-objectives'),
}, pkg)
.catch((err) => {
expect(err.message).toBe('Invalid learning objective: { name: \'react\', optional: true }');
});
});

Expand Down
13 changes: 11 additions & 2 deletions lib/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,20 @@ export const transformLearningObjectives = async (dir, opts, meta = {}) => {
).expanded;
};

const parsedLearningObjectives = parseLearningObjectives(learningObjectives);

return {
learningObjectives: parseLearningObjectives(learningObjectives),
learningObjectives: parsedLearningObjectives,
variants: variants?.map(variant => ({
...variant,
learningObjectives: parseLearningObjectives(variant.learningObjectives, true),
learningObjectives: parseLearningObjectives(variant.learningObjectives, true)
.filter(({ id, optional, exclude }) => !parsedLearningObjectives.some(
lo => (
lo.id === id
&& !!optional === !!lo.optional
&& !!exclude === !!lo.exclude
),
)),
})),
};
};
Expand Down

0 comments on commit 7d7718b

Please sign in to comment.