Skip to content

Commit

Permalink
Merge pull request #109 from UofGAnalytics/no-required-course-catalog…
Browse files Browse the repository at this point in the history
…-allow-list

valid catalog values not required
  • Loading branch information
dmca-glasgow committed May 13, 2022
2 parents 8e0493c + e67b855 commit 374a7dd
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 31 deletions.
19 changes: 19 additions & 0 deletions compiler/src/course/__test__/load-course.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -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('<!--R--><gclass="active">');
});

it('should have no highlighted hexagons', async () => {
const html = await fixtureTestProcessor('basic-no-catalog', {
output: 'html',
noDoc: false,
});

expect(ignoreWhitespace(html)).not.toContain('<gclass="active">');
});
});
32 changes: 16 additions & 16 deletions compiler/src/course/load-course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
});
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/course/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { VFile } from 'vfile';

export type CourseYaml = {
title: string;
catalog: string;
catalog?: string;
authors: string;
academic_year: string;
units: FileRef[];
Expand All @@ -25,7 +25,7 @@ export type Unit = {

export type Course = {
title: string;
catalog: string;
catalog?: string;
authors: string;
academic_year: string;
coursePath: string;
Expand Down
26 changes: 14 additions & 12 deletions compiler/src/html/wrapper/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function createCover(titles: UnitTitles, course: Course) {
className: 'logos',
},
children: [
createCoverHexagons(course.catalog),
createCoverHexagons(course.catalog || ''),
getAssetHast(dagLogoSvg),
],
},
Expand Down Expand Up @@ -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;
}
11 changes: 11 additions & 0 deletions compiler/src/knitr/knitr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions compiler/src/test-utils/has-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}, []);
}
5 changes: 4 additions & 1 deletion compiler/src/test-utils/test-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { writeFile } from '../utils/utils';
import {
createHasFailingMessage,
createHasWarningMessage,
createMessageReasons,
} from './has-message';

export async function testProcessor(md: string, options: Options = {}) {
Expand Down Expand Up @@ -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 = {}) {
Expand Down
7 changes: 7 additions & 0 deletions fixtures/basic-no-catalog/course.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: Basic No Catalog
type: course
catalog: blabla
authors: David McArthur
academic_year: 2021-22
units:
- src: test/test.yaml
1 change: 1 addition & 0 deletions fixtures/basic-no-catalog/test/test.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello
5 changes: 5 additions & 0 deletions fixtures/basic-no-catalog/test/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: 'Test'
title: 'Basic'
content:
- type: text
src: test.Rmd

0 comments on commit 374a7dd

Please sign in to comment.