Skip to content

Commit

Permalink
#25: Test for settings checkbox
Browse files Browse the repository at this point in the history
Plus fixed old settings because of new checkbox
  • Loading branch information
Igor Poplavsky committed Jun 4, 2020
1 parent 52e3344 commit 67af35a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
15 changes: 14 additions & 1 deletion src/__tests__/integration/app.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { integrationTest } from './index';
import { integrationTest, toggleSettingsCheckbox } from './index';
import Loading from '../../components/layouts/pages/loading/Loading';

const { REACT_APP_VERSION } = process.env;
Expand All @@ -24,4 +24,17 @@ describe('App', () => {
}
)
);

it(
'Turn settings on and off',
integrationTest((store, component) => {
expect(component.find('.MuiStepLabel-root')).toHaveLength(3);

toggleSettingsCheckbox(component, true);
expect(component.find('.MuiStepLabel-root')).toHaveLength(4);

toggleSettingsCheckbox(component, false);
expect(component.find('.MuiStepLabel-root')).toHaveLength(3);
})
);
});
11 changes: 11 additions & 0 deletions src/__tests__/integration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import fs from 'mz/fs';

import App from '../../components/App';
import configureStore from '../../store/rootStore';
import Checkbox from '@material-ui/core/Checkbox';
import { getInfo as getFileServiceInfo, uploadFile, getFileContent } from '../../services/fileService';
import { getInfo as getJobServiceInfo, createJob, updateJob, executeJob, getJob } from '../../services/jobService';
import { getList as getProfilesList } from '../../services/profiles';
Expand Down Expand Up @@ -262,3 +263,13 @@ export const skipLoadingPage = async (store, component) => {

export const isFileStored = state => state.pdfFiles.length;
export const stepFinished = key => state => getProgress(state).steps.find(({ stepKey }) => stepKey === key)?.completed;

export const toggleSettingsCheckbox = (component, checked) => {
expect(component.find(Checkbox)).toHaveLength(1);
component
.find(Checkbox)
.props()
.onChange({ target: { checked } });
component.update();
expect(component.find(Checkbox).props().checked).toBe(checked);
};
13 changes: 12 additions & 1 deletion src/__tests__/integration/settings.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { DEFAULT_STARTUP_RESPONSES, TEST_FILE, integrationTest, storeFile, moveNext } from './index';
import {
DEFAULT_STARTUP_RESPONSES,
TEST_FILE,
integrationTest,
storeFile,
moveNext,
toggleSettingsCheckbox,
} from './index';
import MaterialSelect from '@material-ui/core/Select';
import Settings from '../../components/layouts/pages/settings/Settings';

Expand All @@ -20,6 +27,7 @@ describe('Settings', () => {
integrationTest(
async (store, component) => {
await storeFile(component, store);
toggleSettingsCheckbox(component, true);
moveNext(component);

expect(component.find(Settings)).toHaveLength(1);
Expand All @@ -39,6 +47,7 @@ describe('Settings', () => {
'Profiles list loaded',
integrationTest(async (store, component) => {
await storeFile(component, store);
toggleSettingsCheckbox(component, true);
moveNext(component);

expect(component.find(Settings)).toHaveLength(1);
Expand All @@ -57,6 +66,7 @@ describe('Settings', () => {
integrationTest(
async (store, component) => {
await storeFile(component, store);
toggleSettingsCheckbox(component, true);
moveNext(component);
expect(component.find(Settings)).toHaveLength(1);
expect(getProfileSelectError(component).text()).toBe(
Expand All @@ -76,6 +86,7 @@ describe('Settings', () => {
'Profile changed',
integrationTest(async (store, component) => {
await storeFile(component, store, TEST_FILE);
toggleSettingsCheckbox(component, true);
moveNext(component);

expect(getProfileValue(store)).toEqual(PROFILE_VALUES[0]);
Expand Down
11 changes: 10 additions & 1 deletion src/__tests__/integration/upload.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { TEST_FILE, integrationTest, getNextStepButton, storeFile, moveBack, moveNext } from './index';
import {
TEST_FILE,
integrationTest,
getNextStepButton,
storeFile,
moveBack,
moveNext,
toggleSettingsCheckbox,
} from './index';

const EMPTY_DROPZONE_TEXT = 'Drop a PDF file, or click to select a file';
const FAILED_FILE = {
Expand Down Expand Up @@ -58,6 +66,7 @@ describe('Upload', () => {
'File still attached after going back from next step',
integrationTest(async (store, component) => {
await storeFile(component, store);
toggleSettingsCheckbox(component, true);

moveNext(component);
moveBack(component);
Expand Down
3 changes: 0 additions & 3 deletions src/__tests__/integration/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ describe('Validation', () => {
integrationTest(async (store, component) => {
await storeFile(component, store);

// Move to settings
moveNext(component);

// Click validate button
moveNext(component);
expect(createJob).toHaveBeenCalledTimes(1);
Expand Down

0 comments on commit 67af35a

Please sign in to comment.