diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f836200..db1b606 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,4 +63,4 @@ jobs: - name: Install modules run: npm i - name: Run tests - run: npm test + run: npm run test:ci diff --git a/package.json b/package.json index e319fca..c2058f8 100644 --- a/package.json +++ b/package.json @@ -25,11 +25,12 @@ "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", + "test:ci": "react-scripts test --watchAll=false", "eject": "react-scripts eject", "lint": "eslint src/**/*.ts*", "fix": "npm run lint -- --fix", "check-types": "tsc --noEmit", - "ci": "npm run lint && npm run check-types && npm run build" + "ci": "npm run lint && npm run check-types && npm run test:ci && npm run build" }, "browserslist": { "production": [ diff --git a/src/App.test.tsx b/src/App.test.tsx index af01cf3..8e27742 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -3,11 +3,13 @@ import App from './App'; import {IClient} from './client/IClient'; import {ProjectData, CommentData, SectionData, EntityType, FileData} from './types'; import {LocalStorageStore, StoreData} from './store/LocalStorageStore'; -import {MockLocalStorage} from './store/MockLocalStorage'; +import {MockLocalStorageDependency} from './store/MockLocalStorageDependency'; import {LocalStorageClient} from './client/LocalStorageClient'; // import * as testData from './sampleData' +window.alert = () => {}; + const makeTestStore = (): StoreData => { const initialProjects: ProjectData[] = [ { @@ -87,13 +89,30 @@ describe('App', () => { beforeEach(() => { const initialStore = makeTestStore(); - const localStorageDependency = new MockLocalStorage(initialStore); + const localStorageDependency = new MockLocalStorageDependency(initialStore); const store = new LocalStorageStore(localStorageDependency); client = new LocalStorageClient(store); }); - it('initializing', () => { - it('show "Loading"', async () => { + describe('initializing', () => { + it('should show "Loading"', async () => { + // this method is made blocking for this specific test + client.fetchFullDataForProject = (() => new Promise(r => setTimeout(r))); + + render( + + ); + + expect(screen.getByText(/Loading/)).toBeDefined(); + }); + + it('should show client error', async () => { + client.fetchFullDataForProject = jest.fn().mockResolvedValue(new Error('Some error')); + render( { client={client} /> ); + + await waitFor(() => { + expect(screen.queryByText(/Loading/)).toBeNull(); + }); + + expect(screen.getByText(/Some error/)).toBeDefined(); }); - expect(screen.getByText(/Loading/)).toBeDefined(); }); - it('initialized', () => { + describe('initialized', () => { it('should show the section title and description', async () => { render( = ({ chordProgres return (
    - {chordProgression.map((chord, index) =>
  1. {chord}
  2. )} + {chordProgression.map((chord, index) =>
  3. {chord}
  4. )}
); diff --git a/src/Files.tsx b/src/Files.tsx index 748c5be..c87b9f7 100644 --- a/src/Files.tsx +++ b/src/Files.tsx @@ -16,7 +16,10 @@ export const Files: React.FC = ({files}) => { const numComments = globalStore.getCommentsForFile(file.id).length; return ( -
+
{file.title}



{numComments} diff --git a/src/client/IClient.ts b/src/client/IClient.ts index eb7694d..1b7e669 100644 --- a/src/client/IClient.ts +++ b/src/client/IClient.ts @@ -1,4 +1,4 @@ -import {CommentData, FullProjectData, ProjectData, SectionData} from '../types'; +import {CommentData, FullProjectData, SectionData} from '../types'; export interface IClient { fetchFullDataForProject: (projectId: string) => Promise; diff --git a/src/store/IStore.ts b/src/store/IStore.ts deleted file mode 100644 index c0242b9..0000000 --- a/src/store/IStore.ts +++ /dev/null @@ -1,8 +0,0 @@ -import {CommentData, FileData, ProjectData, SectionData} from '../types'; - -export interface IStore { - getAllProjects(): Promise; - getAllSections(): Promise; - getAllFiles(): Promise; - getAllComments(): Promise; -} diff --git a/src/store/LocalStorageStore.ts b/src/store/LocalStorageStore.ts index c5bdb9f..5908afc 100644 --- a/src/store/LocalStorageStore.ts +++ b/src/store/LocalStorageStore.ts @@ -1,5 +1,4 @@ import {CommentData, EntityType, FileData, ProjectData, SectionData} from '../types'; -import {IStore} from './IStore'; export interface LocalStorageDependency { getItem(key: string): string | null; @@ -22,7 +21,7 @@ export type StoreData = { comments: CommentData[]; } -export class LocalStorageStore implements IStore { +export class LocalStorageStore { private ls: LocalStorageDependency; private currentData: StoreData; diff --git a/src/store/MockLocalStorage.ts b/src/store/MockLocalStorageDependency.ts similarity index 82% rename from src/store/MockLocalStorage.ts rename to src/store/MockLocalStorageDependency.ts index a1329c7..cfc9890 100644 --- a/src/store/MockLocalStorage.ts +++ b/src/store/MockLocalStorageDependency.ts @@ -1,6 +1,6 @@ import {LocalStorageDependency} from './LocalStorageStore'; -export class MockLocalStorage> implements LocalStorageDependency { +export class MockLocalStorageDependency> implements LocalStorageDependency { public currentData: T; constructor(data: T) {