Skip to content

Commit 7578178

Browse files
committed
Start preparation
Start setup of code
1 parent 6c1d689 commit 7578178

39 files changed

+13984
-0
lines changed

.babelrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
'presets': ['@babel/preset-env'],
3+
"plugins": [
4+
["@babel/transform-runtime"]
5+
]
6+
}

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
dist
3+
.env
4+

API_JSON EXAMPLE.txt

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"status":{
3+
"code":"0",
4+
"msg":"OK",
5+
"credits":"1",
6+
"remaining_credits":"19975"
7+
},
8+
"model":"general_en",
9+
"score_tag":"NONE",
10+
"agreement":"AGREEMENT",
11+
"subjectivity":"OBJECTIVE",
12+
"confidence":"100",
13+
"irony":"NONIRONIC",
14+
"sentence_list":[
15+
{
16+
"text":"To be or not to be that is the question.",
17+
"inip":"0",
18+
"endp":"39",
19+
"bop":"y",
20+
"confidence":"100",
21+
"score_tag":"NONE",
22+
"agreement":"AGREEMENT",
23+
"segment_list":[
24+
{
25+
"text":"To be",
26+
"segment_type":"secondary",
27+
"inip":"0",
28+
"endp":"4",
29+
"confidence":"100",
30+
"score_tag":"NONE",
31+
"agreement":"AGREEMENT",
32+
"polarity_term_list":[
33+
]
34+
},
35+
{
36+
"text":"not to be that is the question",
37+
"segment_type":"main",
38+
"inip":"9",
39+
"endp":"38",
40+
"confidence":"100",
41+
"score_tag":"NONE",
42+
"agreement":"AGREEMENT",
43+
"polarity_term_list":[
44+
45+
],
46+
"sentimented_concept_list":[
47+
{
48+
"form":"question",
49+
"id":"1b19e12452",
50+
"variant":"question",
51+
"inip":"31",
52+
"endp":"38",
53+
"type":"Top",
54+
"score_tag":"NONE"
55+
}
56+
]
57+
}
58+
],
59+
"sentimented_entity_list":[
60+
],
61+
"sentimented_concept_list":[
62+
{
63+
"form":"question",
64+
"id":"1b19e12452",
65+
"type":"Top",
66+
"score_tag":"NONE"
67+
}
68+
]
69+
}
70+
],
71+
"sentimented_entity_list":[
72+
],
73+
"sentimented_concept_list":[
74+
{
75+
"form":"question",
76+
"id":"1b19e12452",
77+
"type":"Top",
78+
"score_tag":"NONE"
79+
}
80+
]
81+
}

README.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Repository Description
2+
3+
This repo for the 5th project for the Udacity Front End Developer project.
4+
5+
For the project we had to create a simple Travel app where you entered a date and destination and it pulls in some pictures and information of interest such as the weather. In addition a counter of the pending dates until the trips date.
6+
7+
The goal of this project was get additional practice with:
8+
9+
- Setting up Webpack
10+
- Sass styles
11+
- Webpack Loaders and Plugins
12+
- Creating layouts and page design
13+
- Service workers
14+
- Using APIs and creating requests to external urls
15+
16+
## Repository Branches
17+
18+
- Each repository branch reflects the different stages or progress to complete the requirements.
19+
- I reused code from my passed projects such as project 3 and 4 which I incorporated and adapted for this project.
20+
21+
__Notes:__
22+
23+
- During the process of creating these I came to conclude that some of the previously generated code was not needed, so that will find some code that is not existant at later branches.
24+
- In order to run the code you will require node version 11.15.0 and nvm version 1.1.8.
25+
- Also you will have to create a .env file with your API Keys for the different APIs.
26+
27+
## Available Documentation
28+
29+
---
30+
31+
Here you will find detailed information as to the steps and notes from the Udacity course that had to be implemented in addition some commands I hade to use repetitively.
32+
33+
### UDACITY DOCUMENTATION
34+
35+
- [UDACITY_Instructions](documentation/UDACITY_Instructions.md)
36+
- [UDACITY_Project_Rubric](documentation/UDACITY_Project_Rubric)
37+
- [NVM_Commands](documentation/NVM_Commands.md)
38+
39+
### Prior projects steps included for reference:
40+
41+
- [STEPS_Stage01](documentation/STEPS_Stage01.md)
42+
- [STEPS_Stage02](documentation/STEPS_Stage02.md)
43+
- [STEPS_Stage03](documentation/STEPS_Stage03.md)
44+
- [STEPS_Stage04](documentation/STEPS_Stage04.md)
45+
- [STEPS_Stage05](documentation/STEPS_Stage05.md)
46+
- [STEPS_Stage06](documentation/STEPS_Stage06.md)
47+
48+
## Greatest Challenges
49+
50+
1. Understanding async function and promise chaining.
51+
2. Understanding that I had to use the right node.js and npm versions.
52+
3. Understanding that I had to downgrade the different package versions of plugins and loaders and not just install the latest versions which are installed by default.
53+
4. Realizing that we did not have to follow exactly the boiler plate api fetch template from MeaningCloud.
54+
5. Learning to do testing.
55+
6. Incorporating new features.

__test__/testcontentChecker.spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Import the js file to test
2+
import { contentCheck } from "../src/client/js/contentChecker"
3+
4+
describe("Testing whether the submitted text from the form is not empty", () => {
5+
test("Testing the contentCheck() function", () => {
6+
// Define the input for the function, if any, in the form of variables/array
7+
const input = "";
8+
// Define the expected output, if any, in the form of variables/array
9+
// The expect() function, in combination with a Jest matcher, is used to check if the function produces the expected output
10+
// The general syntax is `expect(myFunction(arg1, arg2, ...)).toEqual(expectedValue);`, where `toEqual()` is a matcher
11+
expect(contentCheck(input)).toBeTruthy();
12+
})});
+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Import the js files to test
2+
import { handleSubmitApi } from "../src/client/js/formHandlerApi"
3+
import { contentCheck } from "../src/client/js/contentChecker"
4+
import { postData } from "../src/client/js/postData"
5+
import { serverApiResults } from "../src/client/js/results"
6+
7+
const mockResponse = {
8+
"status":{
9+
"code":"0",
10+
"msg":"OK",
11+
"credits":"1",
12+
"remaining_credits":"19975"
13+
},
14+
"model":"general_en",
15+
"score_tag":"NONE",
16+
"agreement":"AGREEMENT",
17+
"subjectivity":"OBJECTIVE",
18+
"confidence":"100",
19+
"irony":"NONIRONIC",
20+
"sentence_list":[
21+
{
22+
"text":"To be or not to be that is the question.",
23+
"inip":"0",
24+
"endp":"39",
25+
"bop":"y",
26+
"confidence":"100",
27+
"score_tag":"NONE",
28+
"agreement":"AGREEMENT",
29+
"segment_list":[
30+
{
31+
"text":"To be",
32+
"segment_type":"secondary",
33+
"inip":"0",
34+
"endp":"4",
35+
"confidence":"100",
36+
"score_tag":"NONE",
37+
"agreement":"AGREEMENT",
38+
"polarity_term_list":[
39+
]
40+
},
41+
{
42+
"text":"not to be that is the question",
43+
"segment_type":"main",
44+
"inip":"9",
45+
"endp":"38",
46+
"confidence":"100",
47+
"score_tag":"NONE",
48+
"agreement":"AGREEMENT",
49+
"polarity_term_list":[
50+
51+
],
52+
"sentimented_concept_list":[
53+
{
54+
"form":"question",
55+
"id":"1b19e12452",
56+
"variant":"question",
57+
"inip":"31",
58+
"endp":"38",
59+
"type":"Top",
60+
"score_tag":"NONE"
61+
}
62+
]
63+
}
64+
],
65+
"sentimented_entity_list":[
66+
],
67+
"sentimented_concept_list":[
68+
{
69+
"form":"question",
70+
"id":"1b19e12452",
71+
"type":"Top",
72+
"score_tag":"NONE"
73+
}
74+
]
75+
}
76+
],
77+
"sentimented_entity_list":[
78+
],
79+
"sentimented_concept_list":[
80+
{
81+
"form":"question",
82+
"id":"1b19e12452",
83+
"type":"Top",
84+
"score_tag":"NONE"
85+
}
86+
]
87+
};
88+
89+
90+
const myMock = jest.fn()
91+
92+
describe("Testing formHandlerApi step sequence", () => {
93+
94+
const result = handleSubmitApi;
95+
96+
it('contentChecker should return true and proceed to the next function', () => {
97+
const contentCheck = jest.fn().mockReturnValue(true);
98+
expect(contentCheck()).toBe(true);
99+
});
100+
101+
it('postData should send the text and respond with the mockResponse and proceed to the next function', () => {
102+
const postData = jest.fn().mockReturnValue(mockResponse);
103+
expect(postData()).toBe(mockResponse);
104+
});
105+
106+
expect(result).toBeDefined();
107+
108+
});

__test__/testpostData.spec.js

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Import the js file to test
2+
import { postData } from "../src/client/js/postData"
3+
4+
const mockResponse = {
5+
"status":{
6+
"code":"0",
7+
"msg":"OK",
8+
"credits":"1",
9+
"remaining_credits":"19975"
10+
},
11+
"model":"general_en",
12+
"score_tag":"NONE",
13+
"agreement":"AGREEMENT",
14+
"subjectivity":"OBJECTIVE",
15+
"confidence":"100",
16+
"irony":"NONIRONIC",
17+
"sentence_list":[
18+
{
19+
"text":"To be or not to be that is the question.",
20+
"inip":"0",
21+
"endp":"39",
22+
"bop":"y",
23+
"confidence":"100",
24+
"score_tag":"NONE",
25+
"agreement":"AGREEMENT",
26+
"segment_list":[
27+
{
28+
"text":"To be",
29+
"segment_type":"secondary",
30+
"inip":"0",
31+
"endp":"4",
32+
"confidence":"100",
33+
"score_tag":"NONE",
34+
"agreement":"AGREEMENT",
35+
"polarity_term_list":[
36+
]
37+
},
38+
{
39+
"text":"not to be that is the question",
40+
"segment_type":"main",
41+
"inip":"9",
42+
"endp":"38",
43+
"confidence":"100",
44+
"score_tag":"NONE",
45+
"agreement":"AGREEMENT",
46+
"polarity_term_list":[
47+
48+
],
49+
"sentimented_concept_list":[
50+
{
51+
"form":"question",
52+
"id":"1b19e12452",
53+
"variant":"question",
54+
"inip":"31",
55+
"endp":"38",
56+
"type":"Top",
57+
"score_tag":"NONE"
58+
}
59+
]
60+
}
61+
],
62+
"sentimented_entity_list":[
63+
],
64+
"sentimented_concept_list":[
65+
{
66+
"form":"question",
67+
"id":"1b19e12452",
68+
"type":"Top",
69+
"score_tag":"NONE"
70+
}
71+
]
72+
}
73+
],
74+
"sentimented_entity_list":[
75+
],
76+
"sentimented_concept_list":[
77+
{
78+
"form":"question",
79+
"id":"1b19e12452",
80+
"type":"Top",
81+
"score_tag":"NONE"
82+
}
83+
]
84+
};
85+
86+
const url = 'http://localhost:8081/textToAnalyze';
87+
const testText = "To be or not to be that is the question.";
88+
89+
90+
//Setup adapted from https://medium.com/fernandodof/how-to-mock-fetch-calls-with-jest-a666ae1e7752
91+
92+
global.fetch = jest.fn(() => Promise.resolve({
93+
json: () => Promise.resolve(mockResponse)
94+
}));
95+
96+
describe('Mock postData', () => {
97+
let testpostingData;
98+
99+
describe('When the data is posted to the server for the api call', () => {
100+
beforeEach(async () => {
101+
testpostingData = await postData(url, testText);
102+
});
103+
104+
it('Then the mockResponse JSON object should be returned', () => {
105+
expect(testpostingData).toEqual(mockResponse);
106+
});
107+
});
108+
});

0 commit comments

Comments
 (0)