Skip to content

Commit ff9a9cf

Browse files
committed
Merge branch 'master' into #53-If-a-trainer-refresh-F5-it-should-rerequest-the-content-from-the-server
2 parents 90d27a8 + 1eebdd9 commit ff9a9cf

14 files changed

Lines changed: 327 additions & 21 deletions

File tree

‎README.md‎

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,77 @@
1-
# code-paster
1+
<!-- PROJECT SHIELDS -->
2+
<!--
3+
*** I'm using markdown "reference style" links for readability.
4+
*** Reference links are enclosed in brackets [ ] instead of parentheses ( ).
5+
*** See the bottom of this document for the declaration of the reference variables
6+
*** for contributors-url, forks-url, etc. This is an optional, concise syntax you may use.
7+
*** https://www.markdownguide.org/basic-syntax/#reference-style-links
8+
-->
9+
10+
[![Contributors][contributors-shield]][contributors-url]
11+
[![Forks][forks-shield]][forks-url]
12+
[![Stargazers][stars-shield]][stars-url]
13+
[![Issues][issues-shield]][issues-url]
14+
[![MIT License][license-shield]][license-url]
15+
16+
<!-- PROJECT LOGO -->
17+
<br />
18+
<p align="center">
19+
<a href="https://github.com/Lemoncode/code-paster">
20+
<img src="images/logo.png" alt="Logo" width="800" height="330">
21+
</a>
22+
<p align="center">
23+
Code Paster is a Teacher-to-Student communication tool for online programming lessons. Create a new session and easily share your code with all students connected so they can follow along with your examples.
24+
</p>
25+
</p>
26+
<br />
27+
28+
<!-- TABLE OF CONTENTS -->
29+
30+
## Table of Contents
31+
32+
- [About the Project](#about-the-project)
33+
- [Built With](#built-with)
34+
- [Roadmap](#roadmap)
35+
- [License](#license)
36+
37+
<!-- ABOUT THE PROJECT -->
38+
39+
## About The Project
40+
41+
During your programming online lessons you will write hundreds of lines of code and dozens of snippets. For students following along with the code there's nothing more annoying than falling behind the explanation because of a small typo or a missed variable. With Code Paster you can simply copy your code examples and share it in real time with your classroom.
42+
43+
This project was developed by Lemoncode Frontend Master students:
44+
45+
<!-- Include collaborators -->
46+
47+
### Built With
48+
49+
- [React](https://github.com/facebook/react/)
50+
- [Material-UI](https://material-ui.com/)
51+
- [Socket.io](https://socket.io/)
52+
53+
<!-- ROADMAP -->
54+
55+
## Roadmap
56+
57+
See the [open issues](https://github.com/Lemoncode/code-paster/issues) for a list of proposed features (and known issues).
58+
59+
<!-- LICENSE -->
60+
61+
## License
62+
63+
Distributed under the MIT License. See `LICENSE` for more information.
64+
65+
<!-- MARKDOWN LINKS & IMAGES -->
66+
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
67+
68+
[contributors-shield]: https://img.shields.io/github/contributors/Lemoncode/code-paster.svg?style=flat-square
69+
[contributors-url]: https://github.com/Lemoncode/code-paster/graphs/contributors
70+
[forks-shield]: https://img.shields.io/github/forks/Lemoncode/code-paster.svg?style=flat-square
71+
[forks-url]: https://github.com/Lemoncode/code-paster/network/members
72+
[stars-shield]: https://img.shields.io/github/stars/Lemoncode/code-paster.svg?style=flat-square
73+
[stars-url]: https://github.com/Lemoncode/code-paster/stargazers
74+
[issues-shield]: https://img.shields.io/github/issues/Lemoncode/code-paster.svg?style=flat-square
75+
[issues-url]: https://github.com/Lemoncode/code-paster/issues
76+
[license-shield]: https://img.shields.io/github/license/Lemoncode/code-paster.svg?style=flat-square
77+
[license-url]: https://github.com/Lemoncode/code-paster/blob/master/LICENSE.txt

‎front/config/test/jest.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ module.exports = {
44
restoreMocks: true,
55
moduleDirectories: ['<rootDir>/src', 'node_modules'],
66
setupFilesAfterEnv: ['<rootDir>/config/test/setup.ts'],
7+
modulePathIgnorePatterns: ['cypress'],
78
};

‎front/dev.env‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
NODE_ENV=development
2-
API_URL=http://localhost:8081
2+
BASE_API_URL=http://localhost:8081
33
BASE_SOCKET_URL=http://localhost:3001

‎front/prod.env‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
NODE_ENV=production
2-
API_URL=http://localhost:8080
2+
BASE_API_URL=http://localhost:8080
33
BASE_SOCKET_URL=http://localhost:3001

‎front/src/core/api.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as ioClient from 'socket.io-client';
22
import { Socket } from 'socket.io';
3+
import { baseSocketUrl } from './const';
34

45
export interface ConnectionSetup {
56
room: string;
@@ -9,7 +10,7 @@ export interface ConnectionSetup {
910
export const createSocket = (connectionSetup: ConnectionSetup): Socket => {
1011
const { room, trainertoken } = connectionSetup;
1112
const socketParams = {
12-
url: process.env.BASE_SOCKET_URL,
13+
url: baseSocketUrl,
1314
options: {
1415
query: { room, trainertoken },
1516
timeout: 60000,

‎front/src/core/const.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
export const baseApiUrl = process.env.BASE_API_URL;
2+
export const baseSocketUrl = process.env.BASE_SOCKET_URL;
3+
14
export const SocketOuputMessageLiteral = {
25
MESSAGE: 'message',
36
};
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { routes, switchRoutes } from './routes';
2+
3+
describe('routes spec', () => {
4+
it('"switchRoutes" should have expected value by default', () => {
5+
// Arrange
6+
interface SwitchRoutes {
7+
root: string;
8+
student: string;
9+
trainer: string;
10+
}
11+
12+
const expectedValue: SwitchRoutes = {
13+
root: '/',
14+
student: '/student/:room',
15+
trainer: '/trainer/:room/:token',
16+
};
17+
18+
// Act
19+
20+
// Assert
21+
expect(switchRoutes).toEqual<SwitchRoutes>(expectedValue);
22+
});
23+
24+
it('"routes.student" & "routes.trainer" should be functions by default', () => {
25+
// Arrange
26+
27+
// Act
28+
29+
// Assert
30+
expect(routes.student).toEqual(expect.any(Function));
31+
expect(routes.trainer).toEqual(expect.any(Function));
32+
});
33+
34+
it('"routes.student" should return switchRoutes.student path with room name when called', () => {
35+
// Arrange
36+
const expectedResult: string = '/student/new-room';
37+
38+
// Act
39+
const result: string = routes.student('new-room');
40+
41+
// Assert
42+
expect(result).toEqual(expectedResult);
43+
});
44+
45+
it('"routes.trainer" should return switchRoutes.trainer path with room name when called', () => {
46+
// Arrange
47+
const expectedResult: string = '/trainer/new-room/new-token';
48+
49+
// Act
50+
const result: string = routes.trainer('new-room', 'new-token');
51+
52+
// Assert
53+
expect(result).toEqual(expectedResult);
54+
});
55+
});
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
import { renderHook, act } from '@testing-library/react-hooks';
2+
import { useLog } from './use-log.hook';
3+
4+
describe('use-log hook spec', () => {
5+
it('"log" state should be an empty string by default', () => {
6+
// Arrange
7+
8+
// Act
9+
const { result } = renderHook(() => useLog());
10+
11+
// Assert
12+
expect(result.current.log).toEqual<string>('');
13+
});
14+
15+
it('"logRef.current" should be an empty string by default', () => {
16+
// Arrange
17+
18+
// Act
19+
const { result } = renderHook(() => useLog());
20+
21+
// Assert
22+
expect(result.current.logRef.current).toEqual<string>('');
23+
});
24+
25+
it('"appendToLog" & "setLog" should be functions by default', () => {
26+
// Arrange
27+
28+
// Act
29+
const { result } = renderHook(() => useLog());
30+
31+
// Assert
32+
expect(result.current.appendToLog).toEqual(expect.any(Function));
33+
expect(result.current.setLog).toEqual(expect.any(Function));
34+
});
35+
36+
it('"log" & "logRef.current" should return new content when calling "setLog"', () => {
37+
// Arrange
38+
const expectedResult: string = 'new-value';
39+
40+
// Act
41+
const { result } = renderHook(() => useLog());
42+
act(() => {
43+
result.current.setLog('new-value');
44+
});
45+
46+
// Assert
47+
expect(result.current.log).toEqual<string>(expectedResult);
48+
expect(result.current.logRef.current).toEqual<string>(expectedResult);
49+
});
50+
51+
it('"log" & "logRef.current" should return old value when feed "setLog" with "undefined" parameter', () => {
52+
// Arrange
53+
const expectedResult: string = 'old-value';
54+
55+
// Act
56+
const { result } = renderHook(() => useLog());
57+
58+
act(() => {
59+
result.current.setLog('old-value');
60+
});
61+
62+
act(() => {
63+
result.current.setLog(undefined);
64+
});
65+
66+
// Assert
67+
expect(result.current.log).toEqual<string>(expectedResult);
68+
expect(result.current.logRef.current).toEqual<string>(expectedResult);
69+
});
70+
71+
it('"log" & "logRef.current" should return old value when feed "setLog" with "null" parameter', () => {
72+
// Arrange
73+
const expectedResult: string = 'old-value';
74+
75+
// Act
76+
const { result } = renderHook(() => useLog());
77+
78+
act(() => {
79+
result.current.setLog('old-value');
80+
});
81+
82+
act(() => {
83+
result.current.setLog(null);
84+
});
85+
86+
// Assert
87+
expect(result.current.log).toEqual<string>(expectedResult);
88+
expect(result.current.logRef.current).toEqual<string>(expectedResult);
89+
});
90+
91+
it('"log" & "logRef.current" should return new value with one space when calling "appendToLog" for the first time', () => {
92+
// Arrange
93+
const expectedResult: string = `new-value `;
94+
95+
// Act
96+
const { result } = renderHook(() => useLog());
97+
98+
act(() => {
99+
result.current.appendToLog('new-value');
100+
});
101+
102+
// Assert
103+
expect(result.current.log).toEqual<string>(expectedResult);
104+
expect(result.current.logRef.current).toEqual<string>(expectedResult);
105+
});
106+
107+
it('"log" & "logRef.current" should return log value with one space and new value with one space in a new line when calling "appendToLog" after first time', () => {
108+
// Arrange
109+
const expectedResult: string = `old-value \nnew-value `;
110+
111+
// Act
112+
const { result } = renderHook(() => useLog());
113+
114+
act(() => {
115+
result.current.appendToLog('old-value');
116+
});
117+
118+
act(() => {
119+
result.current.appendToLog('new-value');
120+
});
121+
122+
// Assert
123+
expect(result.current.log).toEqual<string>(expectedResult);
124+
expect(result.current.logRef.current).toEqual<string>(expectedResult);
125+
});
126+
127+
it('"log" & "logRef.current" should return the same text after calling "setLog" with that text', () => {
128+
// Arrange
129+
const sessionLog: string = `first line
130+
131+
*********************************
132+
133+
second line
134+
135+
*********************************
136+
137+
third line
138+
139+
*********************************`;
140+
141+
// Act
142+
const { result } = renderHook(() => useLog());
143+
144+
act(() => {
145+
result.current.setLog(sessionLog);
146+
});
147+
148+
// Assert
149+
expect(result.current.log).toEqual<string>(sessionLog);
150+
expect(result.current.logRef.current).toEqual<string>(sessionLog);
151+
});
152+
});

‎front/src/core/use-log.hook.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ export const useLog = () => {
55
const logRef = React.useRef('');
66

77
const appendToLog = (value: string) => {
8-
const newText = `${logRef.current}\n${value} `;
8+
const newText = logRef.current
9+
? `${logRef.current}\n${value} `
10+
: `${value} `;
911
setLog(newText);
1012
};
1113

1214
const setLog = (content: string) => {
13-
internalSetLog(content);
14-
logRef.current = content;
15+
if (content !== undefined && content !== null) {
16+
internalSetLog(content);
17+
logRef.current = content;
18+
}
1519
};
1620

1721
return { log, appendToLog, logRef, setLog };

‎front/src/pods/create-session/api/create-session.api.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Axios from 'axios';
2+
import { baseApiUrl } from 'core';
23

3-
const getRoomUrl = `${process.env.API_URL}/api/create-room`;
4+
const getRoomUrl = `${baseApiUrl}/api/create-room`;
45

56
interface SessionInfo {
67
room: string;

0 commit comments

Comments
 (0)