From 1d8d7a0c8c522c8c24997fc429fcd2c67bc20d6c Mon Sep 17 00:00:00 2001 From: Dave Star Date: Fri, 13 May 2022 15:38:32 +0100 Subject: [PATCH 1/2] valid catalog values not required --- .../src/course/__test__/load-course.test.ts | 19 +++++++++++ compiler/src/course/load-course.ts | 32 +++++++++---------- compiler/src/course/types.ts | 4 +-- compiler/src/html/wrapper/main.ts | 26 ++++++++------- compiler/src/knitr/knitr.ts | 11 +++++++ compiler/src/test-utils/has-message.ts | 7 ++++ compiler/src/test-utils/test-processor.ts | 5 ++- fixtures/basic-no-catalog/course.yaml | 7 ++++ fixtures/basic-no-catalog/test/test.Rmd | 1 + fixtures/basic-no-catalog/test/test.yaml | 5 +++ 10 files changed, 86 insertions(+), 31 deletions(-) create mode 100755 fixtures/basic-no-catalog/course.yaml create mode 100644 fixtures/basic-no-catalog/test/test.Rmd create mode 100644 fixtures/basic-no-catalog/test/test.yaml diff --git a/compiler/src/course/__test__/load-course.test.ts b/compiler/src/course/__test__/load-course.test.ts index 5c138487..3e156d46 100644 --- a/compiler/src/course/__test__/load-course.test.ts +++ b/compiler/src/course/__test__/load-course.test.ts @@ -1,6 +1,7 @@ import path from 'path'; import { fixtureTestProcessor } from '../../test-utils/fixture-test-processor'; +import { ignoreWhitespace } from '../../test-utils/test-processor'; describe('loadCourse', () => { it('should output a course', async () => { @@ -22,4 +23,22 @@ describe('loadCourse', () => { await fixtureTestProcessor('basic', { noPdf: false }); expect(true).toBe(true); }, 60000); + + it('should output a highlighted hexagon for course', async () => { + const html = await fixtureTestProcessor('basic', { + output: 'html', + noDoc: false, + }); + + expect(ignoreWhitespace(html)).toContain(''); + }); + + it.only('should have no highlighted hexagons', async () => { + const html = await fixtureTestProcessor('basic-no-catalog', { + output: 'html', + noDoc: false, + }); + + expect(ignoreWhitespace(html)).not.toContain(''); + }); }); diff --git a/compiler/src/course/load-course.ts b/compiler/src/course/load-course.ts index d7868a12..54370e59 100644 --- a/compiler/src/course/load-course.ts +++ b/compiler/src/course/load-course.ts @@ -6,21 +6,21 @@ import * as yup from 'yup'; import { checkLocalFileExists, readFile } from '../utils/utils'; import { CourseYaml } from './types'; -export const validCatalogValues = [ - 'STATS5077', - 'STATS5078', - 'STATS5075', - 'STATS5084', - 'STATS5074', - 'STATS5081', - 'STATS5080', - 'STATS5073', - 'STATS5076', - 'STATS5079', - 'STATS5082', - 'STATS5094', - 'STATS5083', -]; +// export const validCatalogValues = [ +// 'STATS5077', +// 'STATS5078', +// 'STATS5075', +// 'STATS5084', +// 'STATS5074', +// 'STATS5081', +// 'STATS5080', +// 'STATS5073', +// 'STATS5076', +// 'STATS5079', +// 'STATS5082', +// 'STATS5094', +// 'STATS5083', +// ]; const courseSchema = yup.object().shape({ title: yup.string().required(), @@ -29,7 +29,7 @@ const courseSchema = yup.object().shape({ src: yup.string().required(), }) ), - catalog: yup.string().oneOf(validCatalogValues).required(), + catalog: yup.string(), authors: yup.string().required(), academic_year: yup.string().required(), }); diff --git a/compiler/src/course/types.ts b/compiler/src/course/types.ts index 6ff7ab8f..f2f002d7 100644 --- a/compiler/src/course/types.ts +++ b/compiler/src/course/types.ts @@ -2,7 +2,7 @@ import { VFile } from 'vfile'; export type CourseYaml = { title: string; - catalog: string; + catalog?: string; authors: string; academic_year: string; units: FileRef[]; @@ -25,7 +25,7 @@ export type Unit = { export type Course = { title: string; - catalog: string; + catalog?: string; authors: string; academic_year: string; coursePath: string; diff --git a/compiler/src/html/wrapper/main.ts b/compiler/src/html/wrapper/main.ts index 102fe701..44f8e026 100644 --- a/compiler/src/html/wrapper/main.ts +++ b/compiler/src/html/wrapper/main.ts @@ -43,7 +43,7 @@ function createCover(titles: UnitTitles, course: Course) { className: 'logos', }, children: [ - createCoverHexagons(course.catalog), + createCoverHexagons(course.catalog || ''), getAssetHast(dagLogoSvg), ], }, @@ -80,18 +80,20 @@ function createH1(titles: UnitTitles) { function createCoverHexagons(catalog: string) { const hexagons = getAssetHast(coverSvg); - visit(hexagons, 'element', (node) => { - if (node.tagName === 'g') { - const properties = node.properties || {}; - const [className] = (properties.className || []) as string[]; - if (catalog === className) { - properties.className = ['active']; - } else { - properties.className = []; + if (catalog !== '') { + visit(hexagons, 'element', (node) => { + if (node.tagName === 'g') { + const properties = node.properties || {}; + const [className] = (properties.className || []) as string[]; + if (catalog === className) { + properties.className = ['active']; + } else { + properties.className = []; + } + node.properties = properties; } - node.properties = properties; - } - }); + }); + } return hexagons; } diff --git a/compiler/src/knitr/knitr.ts b/compiler/src/knitr/knitr.ts index f22f18dc..631a0c9e 100644 --- a/compiler/src/knitr/knitr.ts +++ b/compiler/src/knitr/knitr.ts @@ -12,6 +12,17 @@ import { Unit } from '../course/types'; import { warnMessage } from '../utils/message'; import { mkdir, rmFile, writeFile } from '../utils/utils'; +// bypass knitr for debugging +// export async function knitr(unit: Unit, ctx: Context) { +// const file = new VFile(); + +// file.value = unit.files.reduce((acc, o) => { +// return acc + EOL + EOL + o.value; +// }, ''); + +// return file; +// } + export async function knitr(unit: Unit, ctx: Context) { const parentFile = await createParentFile(unit, ctx); // console.log(parentFile.value); diff --git a/compiler/src/test-utils/has-message.ts b/compiler/src/test-utils/has-message.ts index 3a2c8df9..0b4853ad 100644 --- a/compiler/src/test-utils/has-message.ts +++ b/compiler/src/test-utils/has-message.ts @@ -54,3 +54,10 @@ export function createHasWarningMessage(ctx: Context, files: VFile[]) { return reportHasWarnings(files, ctx); }; } + +export function createMessageReasons(files: VFile[]) { + return files.reduce((acc: string[], o) => { + const reasons = o.messages.map((m) => m.reason); + return [...acc, ...reasons]; + }, []); +} diff --git a/compiler/src/test-utils/test-processor.ts b/compiler/src/test-utils/test-processor.ts index 92a7fb3f..4fd45258 100644 --- a/compiler/src/test-utils/test-processor.ts +++ b/compiler/src/test-utils/test-processor.ts @@ -13,6 +13,7 @@ import { writeFile } from '../utils/utils'; import { createHasFailingMessage, createHasWarningMessage, + createMessageReasons, } from './has-message'; export async function testProcessor(md: string, options: Options = {}) { @@ -46,7 +47,9 @@ export async function testProcessor(md: string, options: Options = {}) { const hasFailingMessage = createHasFailingMessage(ctx, unit.files); const hasWarningMessage = createHasWarningMessage(ctx, unit.files); - return { file, hasFailingMessage, hasWarningMessage, ...unit }; + const messages = createMessageReasons(unit.files); + + return { file, hasFailingMessage, hasWarningMessage, messages, ...unit }; } async function createTestContext(md: string, options: Options = {}) { diff --git a/fixtures/basic-no-catalog/course.yaml b/fixtures/basic-no-catalog/course.yaml new file mode 100755 index 00000000..7d469178 --- /dev/null +++ b/fixtures/basic-no-catalog/course.yaml @@ -0,0 +1,7 @@ +title: Basic No Catalog +type: course +catalog: blabla +authors: David McArthur +academic_year: 2021-22 +units: + - src: test/test.yaml diff --git a/fixtures/basic-no-catalog/test/test.Rmd b/fixtures/basic-no-catalog/test/test.Rmd new file mode 100644 index 00000000..e965047a --- /dev/null +++ b/fixtures/basic-no-catalog/test/test.Rmd @@ -0,0 +1 @@ +Hello diff --git a/fixtures/basic-no-catalog/test/test.yaml b/fixtures/basic-no-catalog/test/test.yaml new file mode 100644 index 00000000..2a730ca3 --- /dev/null +++ b/fixtures/basic-no-catalog/test/test.yaml @@ -0,0 +1,5 @@ +name: 'Test' +title: 'Basic' +content: + - type: text + src: test.Rmd From e67b855b9cb1e2309faafe766d3cd0bc38beb157 Mon Sep 17 00:00:00 2001 From: Dave Star Date: Fri, 13 May 2022 15:55:36 +0100 Subject: [PATCH 2/2] fix ci --- compiler/src/course/__test__/load-course.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/course/__test__/load-course.test.ts b/compiler/src/course/__test__/load-course.test.ts index 3e156d46..c5662d9b 100644 --- a/compiler/src/course/__test__/load-course.test.ts +++ b/compiler/src/course/__test__/load-course.test.ts @@ -33,7 +33,7 @@ describe('loadCourse', () => { expect(ignoreWhitespace(html)).toContain(''); }); - it.only('should have no highlighted hexagons', async () => { + it('should have no highlighted hexagons', async () => { const html = await fixtureTestProcessor('basic-no-catalog', { output: 'html', noDoc: false,