Skip to content

Commit

Permalink
tests(project): Adds tests for variants/optional/turn off cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mfdebian committed Apr 3, 2024
1 parent 849b50c commit 456fa2b
Show file tree
Hide file tree
Showing 10 changed files with 211 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,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
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ learningObjectives:
- js/semantics
- ux/user-understanding
- ux/prototyping
- object-oriented-programming:
- react:
optional: true
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,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
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,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
58 changes: 57 additions & 1 deletion lib/__tests__/__snapshots__/project.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
`;
38 changes: 38 additions & 0 deletions lib/__tests__/project.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions lib/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
);
}

Expand All @@ -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]),
);
}

Expand Down

0 comments on commit 456fa2b

Please sign in to comment.