All files IocTests.tsx

96% Statements 24/25
100% Branches 6/6
100% Functions 5/5
95% Lines 19/20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 691x 1x   1x                         1x 1x     1x 1x         1x   1x     1x 1x     1x     1x     1x         1x 2x   2x             1x                     1x  
import * as React from 'react';
import styles from './IocTests.module.scss';
import IListsService, { IList } from '../../../common/services/Lists/IListsService';
import ICacheProvider, { CacheTimeout } from '../../../common/providers/Cache/ICacheProvider';
import ILogProvider from '../../../common/providers/Log/ILogProvider';
 
export interface IocTestsProps {
  cacheProvider: ICacheProvider;
  logProvider: ILogProvider;
  listsService: IListsService;
}
 
export interface IocTestsState {
  lists: IList[];
}
 
export default class IocTests extends React.Component<IocTestsProps, IocTestsState> {
  private className: string = "IocTests";
 
  constructor(props: IocTestsProps) {
    super(props);
    this.state = {
      lists: null
    };
  }
 
  public async componentDidMount(): Promise<void> {
    // LOG PROVIDER
    await this.props.logProvider.Debug(this.className, "componentDidMount", null);
 
    // CACHE PROVIDER
    const cacheKey = "IocTestsGetLists";
    let lists: IList[] = await this.props.cacheProvider.Get(cacheKey);
    if (!lists) {
      // LISTS SERVICE
      lists = await this.props.listsService.GetLists();
 
      // CACHE PROVIDER
      await this.props.cacheProvider.Set(cacheKey, lists, CacheTimeout.default);
    }
 
    this.setState({
      lists: lists
    });
  }
 
  public render(): React.ReactElement<IocTestsProps> {
    this.props.logProvider.Debug(this.className, "render", null);
 
    return (
      <div id={ styles.iocTests } className={ styles.iocTests }>
        <div className={ styles.container }>
          { !this.state.lists &&
            <span> Loading... </span>
          }
          { !!this.state.lists && this.state.lists.map(l => {
              return (
                <div key={l.Title}>
                  <a href={l.DefaultViewUrl} target={"_blank"}>{l.Title}</a>
                </div>
              );
            })
          }
        </div>
      </div>
    );
  }
}