beforeEach(() => { store = configureAppStore(); component = renderGithubRepoForm(store); store.dispatch(actions.reposLoaded([])); expect(store.getState().githubRepoForm).toEqual(initialState); });
it('should display list when repos not empty', () => { const repoName = 'testRepo'; store.dispatch(actions.reposLoaded([{ id: 'test', name: repoName }])); expect(component.queryByText(repoName)).toBeInTheDocument(); });
it('should display error when repoError fired', () => { let error = RepoErrorType.USER_NOT_FOUND; store.dispatch(actions.repoError(error)); expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(); error = RepoErrorType.USER_HAS_NO_REPO; store.dispatch(actions.repoError(error)); expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(); error = RepoErrorType.USERNAME_EMPTY; store.dispatch(actions.repoError(error)); expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(); error = RepoErrorType.RESPONSE_ERROR; store.dispatch(actions.repoError(error)); expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(); error = RepoErrorType.GITHUB_RATE_LIMIT; store.dispatch(actions.repoError(error)); expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(); });
it("shouldn't fetch repos on mount if username is empty", () => { store.dispatch(actions.changeUsername('')); store.dispatch(actions.reposLoaded([])); component.unmount(); component = renderGithubRepoForm(store); expect(store.getState().githubRepoForm.loading).toBe(false); });
yield put(actions.repoError(RepoErrorType.USERNAME_EMPTY)); return; yield put(actions.reposLoaded(repos)); } else { yield put(actions.repoError(RepoErrorType.USER_HAS_NO_REPO)); yield put(actions.repoError(RepoErrorType.USER_NOT_FOUND)); } else if (err.message === 'Failed to fetch') { yield put(actions.repoError(RepoErrorType.GITHUB_RATE_LIMIT)); } else { yield put(actions.repoError(RepoErrorType.RESPONSE_ERROR));
expect(slice.reducer(state, slice.actions.changeUsername(text))).toEqual({ ...slice.initialState, username: text, expect(slice.reducer(state, slice.actions.reposLoaded(repos))).toEqual({ ...slice.initialState, loading: false, expect(slice.reducer(state, slice.actions.repoError(repoError))).toEqual({ ...slice.initialState, error: repoError,
dispatch(actions.changeUsername(evt.currentTarget.value)); dispatch(actions.loadRepos()); };
const putDescriptor = getReposIterator.next(username).value; expect(putDescriptor).toEqual( put(slice.actions.repoError(RepoErrorType.USERNAME_EMPTY)), ); expect(putDescriptor).toEqual(put(slice.actions.reposLoaded(repos))); }); .value; expect(putDescriptor).toEqual( put(slice.actions.repoError(RepoErrorType.USER_NOT_FOUND)), ); }); put(slice.actions.repoError(RepoErrorType.USER_HAS_NO_REPO)), ); }); .value; expect(putDescriptor).toEqual( put(slice.actions.repoError(RepoErrorType.GITHUB_RATE_LIMIT)), ); }); put(slice.actions.repoError(RepoErrorType.RESPONSE_ERROR)), ); });
it("shouldn't fetch repos on mount if username is empty", () => { store.dispatch(actions.changeUsername('')); store.dispatch(actions.reposLoaded([])); component.unmount(); component = renderGithubRepoForm(store); expect(store.getState().githubRepoForm.loading).toBe(false); });
it('should display list when repos not empty', () => { const repoName = 'testRepo'; store.dispatch(actions.reposLoaded([{ id: 'test', name: repoName }])); expect(component.queryByText(repoName)).toBeInTheDocument(); });
beforeEach(() => { store = configureAppStore(); component = renderGithubRepoForm(store); store.dispatch(actions.reposLoaded([])); expect(store.getState().githubRepoForm).toEqual(initialState); });
it('should display error when repoError fired', () => { let error = RepoErrorType.USER_NOT_FOUND; store.dispatch(actions.repoError(error)); expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(); error = RepoErrorType.USER_HAS_NO_REPO; store.dispatch(actions.repoError(error)); expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(); error = RepoErrorType.USERNAME_EMPTY; store.dispatch(actions.repoError(error)); expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(); error = RepoErrorType.RESPONSE_ERROR; store.dispatch(actions.repoError(error)); expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(); error = RepoErrorType.GITHUB_RATE_LIMIT; store.dispatch(actions.repoError(error)); expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(); });
yield put(actions.repoError(RepoErrorType.USERNAME_EMPTY)); return; yield put(actions.reposLoaded(repos)); } else { yield put(actions.repoError(RepoErrorType.USER_HAS_NO_REPO)); yield put(actions.repoError(RepoErrorType.USER_NOT_FOUND)); } else if (err.message === 'Failed to fetch') { yield put(actions.repoError(RepoErrorType.GITHUB_RATE_LIMIT)); } else { yield put(actions.repoError(RepoErrorType.RESPONSE_ERROR));
expect(slice.reducer(state, slice.actions.changeUsername(text))).toEqual({ ...slice.initialState, username: text, expect(slice.reducer(state, slice.actions.reposLoaded(repos))).toEqual({ ...slice.initialState, loading: false, expect(slice.reducer(state, slice.actions.repoError(repoError))).toEqual({ ...slice.initialState, error: repoError,
dispatch(actions.changeUsername(evt.currentTarget.value)); dispatch(actions.loadRepos()); };