Skip to content

action button is working! #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import NavBar from "./containers/NavBar";
import LeftPanel from "./containers/LeftPanel";
import { library } from "@fortawesome/fontawesome-svg-core";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faPlus, faMinus, faTimes } from "@fortawesome/free-solid-svg-icons";
import {
faPlus,
faMinus,
faTimes,
faQuestionCircle
} from "@fortawesome/free-solid-svg-icons";

library.add(faPlus, faMinus, faTimes);
library.add(faPlus, faMinus, faTimes, faQuestionCircle);

const styles = {
fontFamily: "sans=",
Expand Down
28 changes: 12 additions & 16 deletions src/components/LeftPanel/TestFile/TestCase.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,16 @@ const TestCase = () => {
dispatchMockData(addMockData());
};

const mockDataJSX = mockData.mockData
.map(mockDatum => {
if (mockDatum.type === "mockData") {
return (
<MockData
key={mockDatum.id}
mockDatumId={mockDatum.id}
dispatchMockData={dispatchMockData}
fieldKeys={mockDatum.fieldKeys}
/>
);
}
})
.filter(Boolean);
const mockDataJSX = mockData.mockData.map(mockDatum => {
return (
<MockData
key={mockDatum.id}
mockDatumId={mockDatum.id}
dispatchMockData={dispatchMockData}
fieldKeys={mockDatum.fieldKeys}
/>
);
});

const statementsJSX = testCase.statements.map(statement => {
switch (statement.type) {
Expand All @@ -78,17 +74,17 @@ const TestCase = () => {
key={statement.id}
id={statement.id}
dispatchTestCase={dispatchTestCase}
props={statement.props}
/>
);
default:
return;
}
});

console.log(statementsJSX);
return (
<div>
<TestMenu />
<TestMenu dispatchTestCase={dispatchTestCase} />
<section>
<label htmlFor="test-statement">test:</label>
<input
Expand Down
153 changes: 141 additions & 12 deletions src/components/LeftPanel/TestFile/TestCase/Action.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,149 @@
import React from "react";
// import { deleteAction } from "./testCaseReducer";
import React, { useState } from "react";
import { deleteAction, updateAction } from "./testCaseActions";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";

const Action = ({ dispatchTestCase }) => {
// const handleClickDelete = e => {
// e.stopPropagation();
// dispatch(deleteAction());
// };
const Action = ({ id, dispatchTestCase }) => {
const [eventType, setEventType] = useState("");
const [eventValue, setEventValue] = useState("");
const [queryVariant, setQueryVariant] = useState("");
const [querySelector, setQuerySelector] = useState("");
const [queryValue, setQueryValue] = useState("");

const handleClickDelete = e => {
dispatchTestCase(deleteAction(id));
};

const handleChangeEventType = e => {
setEventType(e.target.value);
dispatchTestCase(
updateAction(
id,
e.target.value,
eventValue,
queryVariant,
querySelector,
queryValue
)
);
};

const handleChangeEventValue = e => {
setEventValue(e.target.value);
dispatchTestCase(
updateAction(
id,
eventType,
e.target.value,
queryVariant,
querySelector,
queryValue
)
);
};

const handleChangeQueryVariant = e => {
setQueryVariant(e.target.value);
dispatchTestCase(
updateAction(
id,
eventType,
eventValue,
e.target.value,
querySelector,
queryValue
)
);
};

const handleChangeQuerySelector = e => {
setQuerySelector(e.target.value);
dispatchTestCase(
updateAction(
id,
eventType,
eventValue,
queryVariant,
e.target.value,
queryValue
)
);
};

const handleChangeQueryValue = e => {
setQueryValue(e.target.value);
dispatchTestCase(
updateAction(
id,
eventType,
eventValue,
queryVariant,
querySelector,
e.target.value
)
);
};

const needsEventValue = eventType => {
const eventsWithValues = [
"keyDown",
"keyPress",
"keyUp",
"change",
"input",
"invalid",
"submit"
];
return eventsWithValues.includes(eventType);
};

return (
<>
<div>
<h3>Action</h3>
<FontAwesomeIcon id="delete-action" icon="times" />
<label htmlFor="action-name">Event Type</label>
<input type="text" id="action-name" />
</>
<FontAwesomeIcon
id="delete-action"
icon="times"
onClick={handleClickDelete}
/>
<label htmlFor="event-type">Event Type</label>
<input type="text" id="event-type" onChange={handleChangeEventType} />
{needsEventValue(eventType) && (
<span>
<label htmlFor="event-value" />
<input
type="text"
id="event-type"
onChange={handleChangeEventValue}
/>
</span>
)}

<label htmlFor="queryVariant">Query Selector</label>
<FontAwesomeIcon className="query" icon="question-circle" />
<select id="queryVariant" onChange={handleChangeQueryVariant}>
<option value="" />
<option value="getBy">getBy</option>
<option value="getAllBy">getAllBy</option>
<option value="queryBy">queryBy</option>
<option value="queryAllBy">queryAllBy</option>
<option value="findBy">findBy</option>
<option value="findAllBy">findAllBy</option>
</select>
<FontAwesomeIcon className="query" icon="question-circle" />
<select id="queries" onChange={handleChangeQuerySelector}>
<option value="" />
<option value="LabelText">LabelText</option>
<option value="PlaceholderText">PlaceholderText</option>
<option value="ByText">Text</option>
<option value="AltText">AltText</option>
<option value="Title">Title</option>
<option value="DisplayValue">DisplayValue</option>
<option value="Role">Role</option>
<option value="TestId">TestId</option>
{/* TextMatch Precision & Normalization will be added */}
</select>
<label>Query</label>
<input type="text" onChange={handleChangeQueryValue} />
</div>
);
};

Expand Down
90 changes: 90 additions & 0 deletions src/components/LeftPanel/TestFile/TestCase/Assertion.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import React, { useState } from "react";
import { deleteAssertion, updateAssertion } from "./testCaseActions";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";

const Assertion = ({ id, dispatchTestCase }) => {
const [queryVariant, setQueryVariant] = useState("");
const [querySelector, setQuerySelector] = useState("");
const [assertionValue, setAssertionValue] = useState("");
const [matcher, setMatcher] = useState("");

const handleClickDelete = e => {
dispatchTestCase(deleteAssertion(id));
};

const handleChangeQueryVariant = e => {
setQueryVariant(e.target.value);
dispatchTestCase(
updateAssertion(
id,
e.target.value,
querySelector,
assertionValue,
matcher
)
);
};
const handleChangeQuerySelector = e => {
setQuerySelector(e.target.value);
dispatchTestCase(
updateAssertion(id, queryVariant, e.target.value, assertionValue, matcher)
);
};
const handleChangeAssertionValue = e => {
setAssertionValue(e.target.value);
dispatchTestCase(
updateAssertion(id, queryVariant, querySelector, e.target.value, matcher)
);
};
const handleChangeMatcher = e => {
setMatcher(e.target.value);
dispatchTestCase(
updateAssertion(
id,
queryVariant,
querySelector,
assertionValue,
e.target.value
)
);
};
return (
<div>
<h3>Assertion</h3>
<FontAwesomeIcon
id="delete-action"
icon="times"
onClick={handleClickDelete}
/>
<label htmlFor="queryVariant">Query Selector</label>
<FontAwesomeIcon className="query" icon="question-circle" />
<select id="queryVariant" onChange={handleChangeQueryVariant}>
<option value="" />
<option value="getBy">getBy</option>
<option value="getAllBy">getAllBy</option>
<option value="queryBy">queryBy</option>
<option value="queryAllBy">queryAllBy</option>
<option value="findBy">findBy</option>
<option value="findAllBy">findAllBy</option>
</select>
<FontAwesomeIcon className="query" icon="question-circle" />
<select id="queries" onChange={handleChangeQuerySelector}>
<option value="" />
<option value="LabelText">LabelText</option>
<option value="PlaceholderText">PlaceholderText</option>
<option value="ByText">Text</option>
<option value="AltText">AltText</option>
<option value="Title">Title</option>
<option value="DisplayValue">DisplayValue</option>
<option value="Role">Role</option>
<option value="TestId">TestId</option>
{/* TextMatch Precision & Normalization will be added */}
</select>
<input type="text" onChange={handleChangeAssertionValue} />
<p>Matcher</p>
<input type="text" onChange={handleChangeMatcher} />
</div>
);
};

export default Assertion;
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,39 @@ export const mockDataState = {
mockDataCheckBox: false
};

let mockDatumId = 0;
let mockDatumKeyId = 0;

const createMockDatum = id => ({
id,
id: mockDatumId++,
name: "",
fieldKeys: [],
content: "",
type: "mockData"
});

const createFieldKeys = id => ({
id,
id: mockDatumKeyId,
fieldKey: "",
fieldType: ""
});

const createAction = () => ({
event: {},
varient: "",
option: "",
query: ""
});

let mockDatumId = 0;
let mockDatumKeyId = 0;

export const mockDataReducer = (state, action) => {
Object.freeze(state);
let mockData = state.mockData;

switch (action.type) {
case actionTypes.TOGGLE_MOCK_DATA:
if (!state.mockDataCheckBox) {
mockData.push(createMockDatum(mockDatumId++));
mockData.push(createMockDatum());
}
return {
...state,
mockData,
mockDataCheckBox: !state.mockDataCheckBox
};
case actionTypes.ADD_MOCK_DATA:
mockData.push(createMockDatum(mockDatumId++));
mockData.push(createMockDatum());
return {
...state,
mockData
Expand All @@ -69,7 +62,7 @@ export const mockDataReducer = (state, action) => {
case actionTypes.ADD_MOCK_DATA_KEY:
mockData = mockData.map(mockDatum => {
if (mockDatum.id === action.id) {
mockDatum.fieldKeys.push(createFieldKeys(mockDatumKeyId++));
mockDatum.fieldKeys.push(createFieldKeys());
}
return mockDatum;
});
Expand All @@ -95,9 +88,6 @@ export const mockDataReducer = (state, action) => {
if (mockDatum.id === action.mockDatumId) {
mockDatum.fieldKeys.map(fieldKey => {
if (fieldKey.id === action.mockDatumKeyId) {
// console.log(fieldKey);
// console.log(`fieldKey: ${fieldKey.fieldKey}`);
// console.log(`action: ${action.fieldKey}`)
fieldKey.fieldKey = action.fieldKey;
fieldKey.fieldType = action.fieldType;
}
Expand Down
Loading