Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEAB-5117: Display formatted notebook #1747

Closed
Closed
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
0be8a50
scaffold
svonworl Mar 22, 2023
0527038
refactor into MarkdownWrapperService, add proof of concept code
svonworl Mar 22, 2023
faa38c5
develop further
svonworl Mar 23, 2023
456ab9e
develop
svonworl Mar 23, 2023
3f9f4dc
refactor lightly
svonworl Mar 23, 2023
b01d978
generalize formatting by type
svonworl Mar 23, 2023
dcf22f6
insert TODOs for further work, clean up
svonworl Mar 23, 2023
3298777
add mime bundle, baseUrl input
svonworl Mar 23, 2023
d2a9289
remove unused file
svonworl Mar 23, 2023
9530cb0
remove unused file #2
svonworl Mar 23, 2023
758eb83
add baseUrl input setting, adjust test
svonworl Mar 23, 2023
fdde446
style notebook divs, add exception handling on failure
svonworl Mar 24, 2023
121549f
make notebook css more scss-ey
svonworl Mar 24, 2023
fd6e4f2
correct execution count, lighten count label
svonworl Mar 24, 2023
d9bf2dd
add support for img alt and title attrs
svonworl Mar 24, 2023
2c5001b
refactor mime bundle processor
svonworl Mar 24, 2023
ce2c56b
rename method
svonworl Mar 24, 2023
9e94ed5
add math support
svonworl Mar 25, 2023
e5617bc
add syntax highlighting
svonworl Mar 25, 2023
c96564f
set language type of code cells, misc improvements
svonworl Mar 27, 2023
7f3c173
refactor escaping code
svonworl Mar 27, 2023
eb5113f
refactor
svonworl Mar 27, 2023
9f57869
honor source/outputs_hidden, add syntax highlighting styles, refactor
svonworl Mar 27, 2023
fdce41c
simplify, fix css problem
svonworl Mar 27, 2023
227980b
add test skeleton
svonworl Mar 28, 2023
4e9ea22
improve template html
svonworl Mar 28, 2023
133cc4c
restructure loop
svonworl Mar 28, 2023
0188552
complete basic unit tests, fix bugs
svonworl Mar 28, 2023
e7c8bc2
fix intermittent syntax highlighting
svonworl Mar 28, 2023
a389da8
fix misc bugs
svonworl Mar 29, 2023
a7bdc2a
improve escape
svonworl Mar 29, 2023
78e063b
refactor
svonworl Mar 29, 2023
d669962
add return type
svonworl Mar 29, 2023
e082dc3
refactor lightly
svonworl Mar 29, 2023
c034925
generate formatted notebook in detached element, add light sanitize
svonworl Mar 29, 2023
559ed62
fix license file, comment, tweak syntax highlighting
svonworl Mar 29, 2023
f169ee7
tweak license file
svonworl Mar 29, 2023
46c23d3
fix license file
svonworl Mar 29, 2023
5d8835e
fix bugs, make first grid column collapse to fit content
svonworl Mar 30, 2023
3f5f638
fix missing error
svonworl Mar 30, 2023
6e1c4cb
cancel old request subscription before launching new request
svonworl Mar 30, 2023
f8f4fda
rejigger attached image support
svonworl Mar 30, 2023
bb3f2dd
tweak styles, do not encode html output
svonworl Mar 30, 2023
2610a19
basic mathjax configurations
svonworl Mar 30, 2023
aef9135
escape trailing double backslashes in equations
svonworl Mar 31, 2023
90b6e3c
add mathjax font files, remove light sanitize
svonworl Mar 31, 2023
283b04d
add mathjax config file, configure ui/safe module, remove katex load
svonworl Apr 3, 2023
c5f6805
remove katex from package json
svonworl Apr 3, 2023
36b22a2
add spam removal
svonworl Apr 3, 2023
38eedba
disable mathjax automatic formatting
svonworl Apr 3, 2023
b43e9ac
use WorkflowService, comment, remove cruft
svonworl Apr 3, 2023
7fe9b3f
update license file
svonworl Apr 3, 2023
ca95810
add mathjax license, correctly this time
svonworl Apr 3, 2023
d951a0b
fix unit tests, address code robot suggestions
svonworl Apr 3, 2023
76b3f95
Merge branch 'develop' into feature/seab-5117/display-formatted-notebook
svonworl Apr 3, 2023
0d69931
remove commented code
svonworl Apr 3, 2023
d4d5577
remove unused stuff
svonworl Apr 4, 2023
c27419e
improve backslashed dollar handling
svonworl Apr 4, 2023
66e292d
improve regexps
svonworl Apr 4, 2023
96afbcb
improve regexps, add light sanitize of prism outputs
svonworl Apr 4, 2023
67e967d
refactor unit test
svonworl Apr 4, 2023
0212b63
clean up unit test
svonworl Apr 4, 2023
4ce9395
add comments, refactor lightly, fix regexp bug
svonworl Apr 4, 2023
d042404
fix spelling error
svonworl Apr 4, 2023
44389b3
change notebook Code tab to Preview tab
svonworl Apr 4, 2023
05a5cde
fix test oopsie
svonworl Apr 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clean up unit test
  • Loading branch information
svonworl committed Apr 4, 2023
commit 0212b630e2c87b1077072bd67e9016224a9dec59
30 changes: 14 additions & 16 deletions src/app/notebook/formatted-notebook.component.spec.ts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on the solution based on our other discussion, can you please add a test to show arbitrary JS code is not executed? Standard is to verify an alert() doesn't execute, although I don't know how you'd do that in a test.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { of } from 'rxjs';
describe('FormattedNotebookComponent', () => {
let notebookComponent: FormattedNotebookComponent;
let fixture: ComponentFixture<FormattedNotebookComponent>;
let workflowsService: WorkflowsService;
let element: any;
let mockSourceFiles: SourceFile[] = [];

beforeEach(
Expand All @@ -35,6 +35,7 @@ describe('FormattedNotebookComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(FormattedNotebookComponent);
notebookComponent = fixture.debugElement.componentInstance;
element = fixture.nativeElement;
fixture.detectChanges();
});

Expand Down Expand Up @@ -128,51 +129,48 @@ describe('FormattedNotebookComponent', () => {

it('should format a notebook with one markdown cell', () => {
format('{ "cells": [ { "cell_type": "markdown", "source": ["a block of markdown"] } ] }');
expect(fixture.nativeElement.querySelector('.markdown').textContent).toContain('a block of markdown');
expect(element.querySelector('.markdown').textContent).toContain('a block of markdown');
confirmSuccess();
});

it('should format a notebook with one code cell with a stream output', () => {
format(makeNotebook([makeCodeCell('some source code', [makeStreamOutput('some output')])]));
expect(fixture.nativeElement.querySelector('.count').textContent).not.toBeUndefined();
expect(fixture.nativeElement.querySelector('.source').textContent).toContain('some source code');
expect(fixture.nativeElement.querySelector('.output').textContent).toContain('some output');
expect(element.querySelector('.count').textContent).not.toBeUndefined();
expect(element.querySelector('.source').textContent).toContain('some source code');
expect(element.querySelector('.output').textContent).toContain('some output');
confirmSuccess();
});

it('should format a notebook with one code cell with a display_data output with image/jpeg available', () => {
const jpegMimeBundle = { 'image/foo': toBase64('foo'), 'image/jpeg': toBase64('jpeg content'), 'text/plain': ['some plain text'] };
format(makeNotebook([makeCodeCell('some source code', [makeDisplayDataOutput(jpegMimeBundle)])]));
console.log(fixture.nativeElement.querySelector('.output img'));
expect(fixture.nativeElement.querySelector('.source').textContent).toContain('some source code');
expect(fixture.nativeElement.querySelector('.output img').getAttribute('src')).toContain(
`data:image/jpeg;base64,${toBase64('jpeg content')}`
);
expect(element.querySelector('.source').textContent).toContain('some source code');
expect(element.querySelector('.output img').getAttribute('src')).toContain(`data:image/jpeg;base64,${toBase64('jpeg content')}`);
confirmSuccess();
});

it('should format a notebook with one code cell with a display_data output with text/plain available', () => {
const textMimeBundle = { 'image/foo': toBase64('foo'), 'application/root': 'foo', 'text/plain': ['some plain text'] };
format(makeNotebook([makeCodeCell('some source code', [makeDisplayDataOutput(textMimeBundle)])]));
expect(fixture.nativeElement.querySelector('.source').textContent).toContain('some source code');
expect(fixture.nativeElement.querySelector('.output').innerHTML).toContain('some plain text');
expect(element.querySelector('.source').textContent).toContain('some source code');
expect(element.querySelector('.output').innerHTML).toContain('some plain text');
confirmSuccess();
});

it('should gracefully handle a code cell display_data output with no suitable mime types', () => {
const unsuitableMimeBundle = { 'image/foo': toBase64('foo'), 'application/foo': 'foo' };
format(makeNotebook([makeCodeCell('some source code', [makeDisplayDataOutput(unsuitableMimeBundle)])]));
expect(fixture.nativeElement.querySelector('.source').textContent).toContain('some source code');
expect(fixture.nativeElement.querySelector('.output')).toBeNull();
expect(element.querySelector('.source').textContent).toContain('some source code');
expect(element.querySelector('.output')).toBeNull();
confirmSuccess();
});

it('should read the img width and height for a display_data output if the metadata is present', () => {
const jpegMimeBundle = { 'image/foo': toBase64('foo'), 'image/jpeg': toBase64('jpeg content'), 'text/plain': ['some plain text'] };
const metadataMimeBundle = { 'image/jpeg': { width: 640, height: 480 } };
format(makeNotebook([makeCodeCell('some source code', [makeDisplayDataOutput(jpegMimeBundle, metadataMimeBundle)])]));
expect(fixture.nativeElement.querySelector('.output img').getAttribute('width')).toBe('640');
expect(fixture.nativeElement.querySelector('.output img').getAttribute('height')).toBe('480');
expect(element.querySelector('.output img').getAttribute('width')).toBe('640');
expect(element.querySelector('.output img').getAttribute('height')).toBe('480');
confirmSuccess();
});
});