File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
app/javascript/Components Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,10 @@ export class TextViewer extends React.PureComponent {
3737 componentDidMount ( ) {
3838 this . highlight_root = this . raw_content . current . parentNode ;
3939
40+ if ( localStorage . getItem ( "text_viewer_font_size" ) != null ) {
41+ this . setState ( { font_size : Number ( localStorage . getItem ( "text_viewer_font_size" ) ) } ) ;
42+ }
43+
4044 // Fetch content from a URL if it is passed as a prop. The URL should point to plaintext data.
4145 if ( this . props . url ) {
4246 this . props . setLoadingCallback ( true ) ;
@@ -106,10 +110,6 @@ export class TextViewer extends React.PureComponent {
106110 if ( content && ( content !== prevContent || this . props . annotations !== prevProps . annotations ) ) {
107111 this . ready_annotations ( ) ;
108112 this . setState ( { copy_success : false } ) ;
109-
110- if ( localStorage . getItem ( "text_viewer_font_size" ) != null ) {
111- this . setState ( { font_size : Number ( localStorage . getItem ( "text_viewer_font_size" ) ) } ) ;
112- }
113113 } else if ( this . props . focusLine !== prevProps . focusLine ) {
114114 this . scrollToLine ( this . props . focusLine ) ;
115115 }
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ import React from "react";
22import { render , screen , waitFor } from "@testing-library/react" ;
33import { TextViewer } from "../Result/text_viewer" ;
44import fetchMock from "jest-fetch-mock" ;
5+ import userEvent from "@testing-library/user-event" ;
6+
57import { BinaryViewer } from "../Result/binary_viewer" ;
68
79describe ( "TextViewer" , ( ) => {
@@ -21,6 +23,17 @@ describe("TextViewer", () => {
2123 fetchMock . resetMocks ( ) ;
2224 } ) ;
2325
26+ it ( "should save font size to localStorage when font size change" , async ( ) => {
27+ jest . spyOn ( Storage . prototype , "getItem" ) ;
28+
29+ render ( < TextViewer { ...props } /> ) ;
30+ userEvent . click ( screen . getByText ( "+A" ) ) ;
31+
32+ await waitFor ( ( ) => {
33+ expect ( localStorage . getItem ( "text_viewer_font_size" ) ) . toBe ( "1.25" ) ;
34+ } ) ;
35+ } ) ;
36+
2437 it ( "should render its text content when the content ends with a new line" , ( ) => {
2538 render ( < TextViewer { ...props } content = { "def f(n: int) -> int:\n return n + 1\n" } /> ) ;
2639
You can’t perform that action at this time.
0 commit comments