From 456fa2bddf2e3ee9be1213ed34f6a992b7d339f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alfredo=20Gonz=C3=A1lez?= Date: Wed, 3 Apr 2024 11:31:16 -0300 Subject: [PATCH] tests(project): Adds tests for variants/optional/turn off cases --- .../README.md | 15 +++++ .../project.yml | 18 ++++++ .../project.yml | 2 +- .../README.md | 15 +++++ .../project.yml | 25 ++++++++ .../README.md | 15 +++++ .../project.yml | 21 +++++++ .../__snapshots__/project.spec.js.snap | 58 ++++++++++++++++++- lib/__tests__/project.spec.js | 38 ++++++++++++ lib/project.js | 9 ++- 10 files changed, 211 insertions(+), 5 deletions(-) create mode 100644 lib/__tests__/__fixtures__/01-a-project-with-learning-objectives-turned-off/README.md create mode 100644 lib/__tests__/__fixtures__/01-a-project-with-learning-objectives-turned-off/project.yml create mode 100644 lib/__tests__/__fixtures__/01-a-project-with-variant-learning-objectives-duplicated/README.md create mode 100644 lib/__tests__/__fixtures__/01-a-project-with-variant-learning-objectives-duplicated/project.yml create mode 100644 lib/__tests__/__fixtures__/01-a-project-with-variant-learning-objectives-turned-off/README.md create mode 100644 lib/__tests__/__fixtures__/01-a-project-with-variant-learning-objectives-turned-off/project.yml diff --git a/lib/__tests__/__fixtures__/01-a-project-with-learning-objectives-turned-off/README.md b/lib/__tests__/__fixtures__/01-a-project-with-learning-objectives-turned-off/README.md new file mode 100644 index 0000000..841e5d5 --- /dev/null +++ b/lib/__tests__/__fixtures__/01-a-project-with-learning-objectives-turned-off/README.md @@ -0,0 +1,15 @@ +# A project + +## Índice + +Blah blah blah + +*** + +## 1. Preámbulo + +Blah blah blah + +## 2. Resumen del proyecto + +Blah blah blah diff --git a/lib/__tests__/__fixtures__/01-a-project-with-learning-objectives-turned-off/project.yml b/lib/__tests__/__fixtures__/01-a-project-with-learning-objectives-turned-off/project.yml new file mode 100644 index 0000000..a36f3ba --- /dev/null +++ b/lib/__tests__/__fixtures__/01-a-project-with-learning-objectives-turned-off/project.yml @@ -0,0 +1,18 @@ +track: web-dev +tracks: + - web-dev +learningObjectives: + - html/semantics + - css/selectors + - dom/selectors + - dom/events + - dom/manipulation + - js/data-types/primitive-vs-non-primitive + - js/data-types/strings + - js/variables + - js/conditionals + - js/functions + - js/semantics + - ux/user-understanding + - ux/prototyping + - css: false diff --git a/lib/__tests__/__fixtures__/01-a-project-with-optional-learning-objectives/project.yml b/lib/__tests__/__fixtures__/01-a-project-with-optional-learning-objectives/project.yml index a8b39ec..4b0e3c1 100644 --- a/lib/__tests__/__fixtures__/01-a-project-with-optional-learning-objectives/project.yml +++ b/lib/__tests__/__fixtures__/01-a-project-with-optional-learning-objectives/project.yml @@ -15,5 +15,5 @@ learningObjectives: - js/semantics - ux/user-understanding - ux/prototyping - - object-oriented-programming: + - react: optional: true diff --git a/lib/__tests__/__fixtures__/01-a-project-with-variant-learning-objectives-duplicated/README.md b/lib/__tests__/__fixtures__/01-a-project-with-variant-learning-objectives-duplicated/README.md new file mode 100644 index 0000000..841e5d5 --- /dev/null +++ b/lib/__tests__/__fixtures__/01-a-project-with-variant-learning-objectives-duplicated/README.md @@ -0,0 +1,15 @@ +# A project + +## Índice + +Blah blah blah + +*** + +## 1. Preámbulo + +Blah blah blah + +## 2. Resumen del proyecto + +Blah blah blah diff --git a/lib/__tests__/__fixtures__/01-a-project-with-variant-learning-objectives-duplicated/project.yml b/lib/__tests__/__fixtures__/01-a-project-with-variant-learning-objectives-duplicated/project.yml new file mode 100644 index 0000000..bf8a4e3 --- /dev/null +++ b/lib/__tests__/__fixtures__/01-a-project-with-variant-learning-objectives-duplicated/project.yml @@ -0,0 +1,25 @@ +track: web-dev +tracks: + - web-dev +learningObjectives: + - html/semantics + - css/selectors + - dom/selectors + - dom/events + - dom/manipulation + - js/data-types/primitive-vs-non-primitive + - js/data-types/strings + - js/variables + - js/conditionals + - js/functions + - js/semantics + - ux/user-understanding + - ux/prototyping + - react: + optional: true +variants: + - name: node + learningObjectives: + - node + - react: + optional: true diff --git a/lib/__tests__/__fixtures__/01-a-project-with-variant-learning-objectives-turned-off/README.md b/lib/__tests__/__fixtures__/01-a-project-with-variant-learning-objectives-turned-off/README.md new file mode 100644 index 0000000..841e5d5 --- /dev/null +++ b/lib/__tests__/__fixtures__/01-a-project-with-variant-learning-objectives-turned-off/README.md @@ -0,0 +1,15 @@ +# A project + +## Índice + +Blah blah blah + +*** + +## 1. Preámbulo + +Blah blah blah + +## 2. Resumen del proyecto + +Blah blah blah diff --git a/lib/__tests__/__fixtures__/01-a-project-with-variant-learning-objectives-turned-off/project.yml b/lib/__tests__/__fixtures__/01-a-project-with-variant-learning-objectives-turned-off/project.yml new file mode 100644 index 0000000..5fdee35 --- /dev/null +++ b/lib/__tests__/__fixtures__/01-a-project-with-variant-learning-objectives-turned-off/project.yml @@ -0,0 +1,21 @@ +track: web-dev +tracks: + - web-dev +learningObjectives: + - html/semantics + - css/selectors + - dom/selectors + - dom/events + - dom/manipulation + - js/data-types/primitive-vs-non-primitive + - js/data-types/strings + - js/variables + - js/conditionals + - js/functions + - js/semantics + - ux/user-understanding + - ux/prototyping +variants: + - name: cli + learningObjectives: + - css: false \ No newline at end of file diff --git a/lib/__tests__/__snapshots__/project.spec.js.snap b/lib/__tests__/__snapshots__/project.spec.js.snap index 93fc5c5..e4b88e8 100644 --- a/lib/__tests__/__snapshots__/project.spec.js.snap +++ b/lib/__tests__/__snapshots__/project.spec.js.snap @@ -173,6 +173,62 @@ exports[`parseProject > should include learning objectives from variant if a var exports[`parseProject > should include optional learning objectives if theyre present 1`] = ` [ - "object-oriented-programming", + "react/jsx", + "react/components", + "react/events", + "react/lists-and-keys", + "react/conditional-rendering", + "react/lifting-up-state", + "react/hooks", + "react/css-modules", + "react/routing", +] +`; + +exports[`parseProject > should not duplicate optional lo if its present in both normal and variant los 1`] = ` +[ + "react/jsx", + "react/components", + "react/events", + "react/lists-and-keys", + "react/conditional-rendering", + "react/lifting-up-state", + "react/hooks", + "react/css-modules", + "react/routing", +] +`; + +exports[`parseProject > should turn off a learning objective if its value is false 1`] = ` +[ + "html/semantics", + "dom/selectors", + "dom/events", + "dom/manipulation", + "js/data-types/primitive-vs-non-primitive", + "js/data-types/strings", + "js/variables/declaration", + "js/conditionals", + "js/functions", + "js/semantics", + "ux/user-understanding", + "ux/prototyping", +] +`; + +exports[`parseProject > should turn off a variant learning objective if its value is false 1`] = ` +[ + "html/semantics", + "dom/selectors", + "dom/events", + "dom/manipulation", + "js/data-types/primitive-vs-non-primitive", + "js/data-types/strings", + "js/variables/declaration", + "js/conditionals", + "js/functions", + "js/semantics", + "ux/user-understanding", + "ux/prototyping", ] `; diff --git a/lib/__tests__/project.spec.js b/lib/__tests__/project.spec.js index 308f76d..f9bf1bd 100644 --- a/lib/__tests__/project.spec.js +++ b/lib/__tests__/project.spec.js @@ -184,6 +184,44 @@ describe('parseProject', () => { }); }); + it('should turn off a learning objective if its value is false', () => { + const p = resolveFixturePath('01-a-project-with-learning-objectives-turned-off'); + return parseProject(p, { + repo: 'Laboratoria/bootcamp', + version: '1.0.0', + lo: path.join(__dirname, '__fixtures__', 'learning-objectives'), + }, pkg) + .then((result) => { + expect(result.learningObjectives).toMatchSnapshot(); + }); + }); + + it('should turn off a variant learning objective if its value is false', () => { + const p = resolveFixturePath('01-a-project-with-variant-learning-objectives-turned-off'); + return parseProject(p, { + repo: 'Laboratoria/bootcamp', + version: '1.0.0', + lo: path.join(__dirname, '__fixtures__', 'learning-objectives'), + variants: 'cli', + }, pkg) + .then((result) => { + expect(result.learningObjectives).toMatchSnapshot(); + }); + }); + + it('should 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', + version: '1.0.0', + lo: path.join(__dirname, '__fixtures__', 'learning-objectives'), + variants: 'node', + }, pkg) + .then((result) => { + expect(result.optionalLearningObjectives).toMatchSnapshot(); + }); + }); + it('extracts first paragraph of _resumen del proyecto_ as summary', () => { const p = resolveFixturePath('01-a-project-with-summary'); expect.assertions(2); diff --git a/lib/project.js b/lib/project.js index 08f1fe9..12b2a1f 100644 --- a/lib/project.js +++ b/lib/project.js @@ -132,11 +132,14 @@ export const transformLearningObjectives = async (dir, opts, meta) => { const variantOptions = opts.variants?.split(',') || []; learningObjectives.forEach((learningObjective) => { - // console.log(learningObjective); if (typeof learningObjective === 'object') { if (!learningObjective[Object.keys(learningObjective)[0]]) { + const index = learningObjectives.indexOf(learningObjective); + if (index > -1) { + learningObjectives.splice(index, 1); + } learningObjectives = learningObjectives.filter( - item => item !== Object.keys(learningObjective)[0], + item => !item.includes(Object.keys(learningObjective)[0]), ); } @@ -161,7 +164,7 @@ export const transformLearningObjectives = async (dir, opts, meta) => { if (typeof learningObjective === 'object') { if (!learningObjective[Object.keys(learningObjective)[0]]) { learningObjectives = learningObjectives.filter( - item => item !== Object.keys(learningObjective)[0], + item => !item.includes(Object.keys(learningObjective)[0]), ); }