@testgorilla/tgo-coding-test 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +45 -0
- package/README.md +257 -0
- package/jest.config.ts +21 -0
- package/ng-package.json +14 -0
- package/package.json +33 -0
- package/project.json +36 -0
- package/src/assets/i18n/en.json +124 -0
- package/src/index.ts +30 -0
- package/src/lib/components/.gitkeep +0 -0
- package/src/lib/components/code-editor/code-editor.component.html +10 -0
- package/src/lib/components/code-editor/code-editor.component.scss +21 -0
- package/src/lib/components/code-editor/code-editor.component.spec.ts +136 -0
- package/src/lib/components/code-editor/code-editor.component.ts +369 -0
- package/src/lib/components/code-editor/code-editor.mocks.ts +28 -0
- package/src/lib/components/code-editor/code-editor.service.spec.ts +160 -0
- package/src/lib/components/code-editor/code-editor.service.ts +94 -0
- package/src/lib/components/code-editor/helpers/c-helper.spec.ts +39 -0
- package/src/lib/components/code-editor/helpers/c-helper.ts +51 -0
- package/src/lib/components/code-editor/helpers/code-editor-helper.base.spec.ts +30 -0
- package/src/lib/components/code-editor/helpers/code-editor-helper.base.ts +16 -0
- package/src/lib/components/code-editor/helpers/code-editor-helper.mocks.ts +24 -0
- package/src/lib/components/code-editor/helpers/code-editor-helper.model.ts +67 -0
- package/src/lib/components/code-editor/helpers/cpp-helper.spec.ts +40 -0
- package/src/lib/components/code-editor/helpers/cpp-helper.ts +52 -0
- package/src/lib/components/code-editor/helpers/csharp-helper.spec.ts +42 -0
- package/src/lib/components/code-editor/helpers/csharp-helper.ts +55 -0
- package/src/lib/components/code-editor/helpers/go-helper.spec.ts +41 -0
- package/src/lib/components/code-editor/helpers/go-helper.ts +54 -0
- package/src/lib/components/code-editor/helpers/index.ts +15 -0
- package/src/lib/components/code-editor/helpers/java-helper.spec.ts +41 -0
- package/src/lib/components/code-editor/helpers/java-helper.ts +54 -0
- package/src/lib/components/code-editor/helpers/javascript-helper.spec.ts +39 -0
- package/src/lib/components/code-editor/helpers/javascript-helper.ts +32 -0
- package/src/lib/components/code-editor/helpers/kotlin-helper.spec.ts +41 -0
- package/src/lib/components/code-editor/helpers/kotlin-helper.ts +54 -0
- package/src/lib/components/code-editor/helpers/php-helper.spec.ts +39 -0
- package/src/lib/components/code-editor/helpers/php-helper.ts +32 -0
- package/src/lib/components/code-editor/helpers/python-helper.spec.ts +39 -0
- package/src/lib/components/code-editor/helpers/python-helper.ts +32 -0
- package/src/lib/components/code-editor/helpers/r-helper.spec.ts +39 -0
- package/src/lib/components/code-editor/helpers/r-helper.ts +32 -0
- package/src/lib/components/code-editor/helpers/ruby-helper.spec.ts +39 -0
- package/src/lib/components/code-editor/helpers/ruby-helper.ts +32 -0
- package/src/lib/components/code-editor/helpers/scala-helper.spec.ts +41 -0
- package/src/lib/components/code-editor/helpers/scala-helper.ts +53 -0
- package/src/lib/components/code-editor/helpers/sql-helper.spec.ts +87 -0
- package/src/lib/components/code-editor/helpers/sql-helper.ts +44 -0
- package/src/lib/components/code-editor/helpers/swift-helper.spec.ts +40 -0
- package/src/lib/components/code-editor/helpers/swift-helper.ts +51 -0
- package/src/lib/components/code-editor/helpers/typescript-helper.spec.ts +40 -0
- package/src/lib/components/code-editor/helpers/typescript-helper.ts +52 -0
- package/src/lib/components/code-editor/models/code-editor.model.ts +9 -0
- package/src/lib/components/code-editor/models/coding-snapshot.model.ts +4 -0
- package/src/lib/components/coding-question/coding-question.component.html +78 -0
- package/src/lib/components/coding-question/coding-question.component.scss +76 -0
- package/src/lib/components/coding-question/coding-question.component.spec.ts +85 -0
- package/src/lib/components/coding-question/coding-question.component.ts +102 -0
- package/src/lib/components/coding-section/coding-section.component.html +82 -0
- package/src/lib/components/coding-section/coding-section.component.scss +64 -0
- package/src/lib/components/coding-section/coding-section.component.spec.ts +257 -0
- package/src/lib/components/coding-section/coding-section.component.ts +187 -0
- package/src/lib/components/coding-test.module.ts +124 -0
- package/src/lib/components/common/truncated-text/truncated-text.component.html +6 -0
- package/src/lib/components/common/truncated-text/truncated-text.component.scss +18 -0
- package/src/lib/components/common/truncated-text/truncated-text.component.spec.ts +84 -0
- package/src/lib/components/common/truncated-text/truncated-text.component.ts +37 -0
- package/src/lib/components/configurations/configurations.component.html +57 -0
- package/src/lib/components/configurations/configurations.component.scss +42 -0
- package/src/lib/components/configurations/configurations.component.spec.ts +186 -0
- package/src/lib/components/configurations/configurations.component.ts +98 -0
- package/src/lib/components/instructions/instructions.component.html +41 -0
- package/src/lib/components/instructions/instructions.component.scss +167 -0
- package/src/lib/components/instructions/instructions.component.spec.ts +106 -0
- package/src/lib/components/instructions/instructions.component.ts +138 -0
- package/src/lib/components/panel/panel.component.html +19 -0
- package/src/lib/components/panel/panel.component.scss +41 -0
- package/src/lib/components/panel/panel.component.spec.ts +40 -0
- package/src/lib/components/panel/panel.component.ts +34 -0
- package/src/lib/components/runnable-editor/runnable-editor.component.html +75 -0
- package/src/lib/components/runnable-editor/runnable-editor.component.scss +55 -0
- package/src/lib/components/runnable-editor/runnable-editor.component.spec.ts +124 -0
- package/src/lib/components/runnable-editor/runnable-editor.component.ts +155 -0
- package/src/lib/components/tests/test-cases/test-cases.component.html +135 -0
- package/src/lib/components/tests/test-cases/test-cases.component.scss +220 -0
- package/src/lib/components/tests/test-cases/test-cases.component.spec.ts +401 -0
- package/src/lib/components/tests/test-cases/test-cases.component.ts +205 -0
- package/src/lib/components/tests/test-cases-content/test-cases-content.component.html +94 -0
- package/src/lib/components/tests/test-cases-content/test-cases-content.component.scss +103 -0
- package/src/lib/components/tests/test-cases-content/test-cases-content.component.spec.ts +122 -0
- package/src/lib/components/tests/test-cases-content/test-cases-content.component.ts +102 -0
- package/src/lib/components/tests/test-cases-status/test-cases-status.component.html +16 -0
- package/src/lib/components/tests/test-cases-status/test-cases-status.component.scss +49 -0
- package/src/lib/components/tests/test-cases-status/test-cases-status.component.spec.ts +22 -0
- package/src/lib/components/tests/test-cases-status/test-cases-status.component.ts +18 -0
- package/src/lib/components/tests/test-results.component.html +119 -0
- package/src/lib/components/tests/test-results.component.scss +189 -0
- package/src/lib/components/tests/test-results.component.spec.ts +140 -0
- package/src/lib/components/tests/test-results.component.ts +98 -0
- package/src/lib/components/tgo-coding-test/tgo-coding-test.component.html +96 -0
- package/src/lib/components/tgo-coding-test/tgo-coding-test.component.scss +6 -0
- package/src/lib/components/tgo-coding-test/tgo-coding-test.component.spec.ts +599 -0
- package/src/lib/components/tgo-coding-test/tgo-coding-test.component.ts +279 -0
- package/src/lib/components/tgo-coding-test-candidate-view/tgo-coding-test-candidate-view.component.html +36 -0
- package/src/lib/components/tgo-coding-test-candidate-view/tgo-coding-test-candidate-view.component.scss +183 -0
- package/src/lib/components/tgo-coding-test-candidate-view/tgo-coding-test-candidate-view.component.spec.ts +883 -0
- package/src/lib/components/tgo-coding-test-candidate-view/tgo-coding-test-candidate-view.component.ts +575 -0
- package/src/lib/config/index.ts +3 -0
- package/src/lib/config/tgo-coding-test.config.ts +26 -0
- package/src/lib/config/tgo-coding-test.provider.ts +38 -0
- package/src/lib/config/tgo-coding-test.token.ts +21 -0
- package/src/lib/models/.gitkeep +0 -0
- package/src/lib/models/auto-saved-data.ts +51 -0
- package/src/lib/models/code-event.ts +17 -0
- package/src/lib/models/coderunner-execution-results.ts +58 -0
- package/src/lib/models/coding-lib.mocks.ts +246 -0
- package/src/lib/models/configs.ts +18 -0
- package/src/lib/models/language-change-action.ts +4 -0
- package/src/lib/models/lat-languages.ts +12 -0
- package/src/lib/models/mixpanel-events.ts +3 -0
- package/src/lib/models/mode.ts +5 -0
- package/src/lib/models/paste-data.ts +4 -0
- package/src/lib/models/programming-language.ts +9 -0
- package/src/lib/models/test-cases.ts +74 -0
- package/src/lib/models/theme.ts +5 -0
- package/src/lib/models/translations.ts +1 -0
- package/src/lib/models/view-mode.ts +6 -0
- package/src/lib/pipes/memoize-func.pipe.ts +34 -0
- package/src/lib/services/.gitkeep +0 -0
- package/src/lib/services/candidate-coding-test-services/candidature-api.service.spec.ts +40 -0
- package/src/lib/services/candidate-coding-test-services/candidature-api.service.ts +15 -0
- package/src/lib/services/candidate-coding-test-services/coderunner-api.service.spec.ts +134 -0
- package/src/lib/services/candidate-coding-test-services/coderunner-api.service.ts +105 -0
- package/src/lib/services/candidate-coding-test-services/coding-test-tour.service.spec.ts +161 -0
- package/src/lib/services/candidate-coding-test-services/coding-test-tour.service.ts +100 -0
- package/src/lib/services/candidate-coding-test-services/coding-test.service.spec.ts +1524 -0
- package/src/lib/services/candidate-coding-test-services/coding-test.service.ts +843 -0
- package/src/lib/services/candidate-coding-test-services/index.ts +4 -0
- package/src/lib/services/coding-test-config.service.ts +48 -0
- package/src/lib/services/configurations.service.mocks.ts +77 -0
- package/src/lib/services/configurations.service.spec.ts +79 -0
- package/src/lib/services/configurations.service.ts +111 -0
- package/src/lib/services/index.ts +0 -0
- package/src/lib/services/lib-coding-test.service.spec.ts +265 -0
- package/src/lib/services/lib-coding-test.service.ts +157 -0
- package/src/lib/services/local-storage.service.mocks.ts +22 -0
- package/src/lib/services/storage.service.spec.ts +1120 -0
- package/src/lib/services/storage.service.ts +729 -0
- package/src/lib/services/test-cases.service.spec.ts +53 -0
- package/src/lib/services/test-cases.service.ts +29 -0
- package/src/lib/services/theme.service.spec.ts +76 -0
- package/src/lib/services/theme.service.ts +34 -0
- package/src/lib/styles/mixins.scss +86 -0
- package/src/lib/styles/styles.scss +112 -0
- package/src/lib/styles/variables.scss +105 -0
- package/src/lib/utils/.gitkeep +0 -0
- package/src/lib/utils/additional-languages/erlang.ts +115 -0
- package/src/lib/utils/resize-element.ts +15 -0
- package/src/lib/utils/time-to-ms.util.ts +10 -0
- package/src/test-setup.ts +1 -0
- package/tsconfig.json +16 -0
- package/tsconfig.lib.json +12 -0
- package/tsconfig.lib.prod.json +9 -0
- package/tsconfig.spec.json +13 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { inject, Injectable } from '@angular/core';
|
|
2
|
+
import { TGO_CODING_TEST_CONFIG } from '../config/tgo-coding-test.token';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Service for accessing TGO Coding Test library configuration.
|
|
6
|
+
*
|
|
7
|
+
* This service provides a clean abstraction layer over the configuration
|
|
8
|
+
* injection token, allowing services to access configuration values
|
|
9
|
+
* without directly injecting the token.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* @Injectable()
|
|
14
|
+
* export class MyService {
|
|
15
|
+
* private readonly configService = inject(CodingTestConfigService);
|
|
16
|
+
*
|
|
17
|
+
* doSomething() {
|
|
18
|
+
* const endpoint = this.configService.getCoderunnerV2Endpoint();
|
|
19
|
+
* // Use endpoint...
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
@Injectable({
|
|
25
|
+
providedIn: 'root',
|
|
26
|
+
})
|
|
27
|
+
export class CodingTestConfigService {
|
|
28
|
+
private readonly config = inject(TGO_CODING_TEST_CONFIG);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Gets the main API endpoint URL.
|
|
32
|
+
*
|
|
33
|
+
* @returns The base URL for the main API endpoint
|
|
34
|
+
*/
|
|
35
|
+
getApiUrl(): string {
|
|
36
|
+
return this.config.apiUrl;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Gets the CodeRunner V2 API endpoint URL.
|
|
41
|
+
*
|
|
42
|
+
* @returns The base URL for the CodeRunner V2 API endpoint
|
|
43
|
+
*/
|
|
44
|
+
getCoderunnerV2Endpoint(): string {
|
|
45
|
+
return this.config.coderunnerV2Endpoint;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { BehaviorSubject } from 'rxjs';
|
|
2
|
+
import { CodingAssistanceOptions, Config, FormattingOptions } from '../models/configs';
|
|
3
|
+
import { Themes } from '../models/theme';
|
|
4
|
+
|
|
5
|
+
const defaultConfigs = {
|
|
6
|
+
[FormattingOptions.ColorTheme]: Themes.Default,
|
|
7
|
+
[FormattingOptions.TabSize]: 4,
|
|
8
|
+
[FormattingOptions.FontSize]: 14,
|
|
9
|
+
[CodingAssistanceOptions.AutoComplete]: true,
|
|
10
|
+
[CodingAssistanceOptions.ErrorHighlighting]: true,
|
|
11
|
+
[CodingAssistanceOptions.AutoBrackets]: true,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const CONFIGURATIONS_SERVICE_MOCK = {
|
|
15
|
+
defaultConfigs,
|
|
16
|
+
|
|
17
|
+
formattingOptions: {
|
|
18
|
+
[FormattingOptions.ColorTheme]: [
|
|
19
|
+
{ label: 'Light', value: Themes.Default },
|
|
20
|
+
{ label: 'Dark', value: Themes.Dark },
|
|
21
|
+
],
|
|
22
|
+
[FormattingOptions.TabSize]: [
|
|
23
|
+
{ label: '4 (default)', value: 4 },
|
|
24
|
+
{ label: '2', value: 2 },
|
|
25
|
+
{ label: '3', value: 3 },
|
|
26
|
+
{ label: '5', value: 5 },
|
|
27
|
+
{ label: '8', value: 8 },
|
|
28
|
+
],
|
|
29
|
+
[FormattingOptions.FontSize]: [
|
|
30
|
+
{ label: '10px', value: 10 },
|
|
31
|
+
{ label: '12px', value: 12 },
|
|
32
|
+
{ label: '14px (default)', value: 14 },
|
|
33
|
+
{ label: '16px', value: 16 },
|
|
34
|
+
{ label: '18px', value: 18 },
|
|
35
|
+
{ label: '20px', value: 20 },
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
codingAssistanceOptions: {
|
|
40
|
+
[CodingAssistanceOptions.AutoComplete]: true,
|
|
41
|
+
[CodingAssistanceOptions.ErrorHighlighting]: true,
|
|
42
|
+
[CodingAssistanceOptions.AutoBrackets]: true,
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
codeComponentDestroyed: true,
|
|
46
|
+
config$: new BehaviorSubject(defaultConfigs),
|
|
47
|
+
colorTheme$: new BehaviorSubject(defaultConfigs[FormattingOptions.ColorTheme]),
|
|
48
|
+
|
|
49
|
+
getInitialConfig(): Config {
|
|
50
|
+
return { ...this.defaultConfigs };
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
getFormattingOptions(): {
|
|
54
|
+
[key: string]: {
|
|
55
|
+
label: string;
|
|
56
|
+
value: Themes | number;
|
|
57
|
+
}[];
|
|
58
|
+
} {
|
|
59
|
+
return { ...this.formattingOptions };
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
getCodingAssistanceOptions(): { [key: string]: boolean } {
|
|
63
|
+
return { ...this.codingAssistanceOptions };
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
setConfig(config: Config) {
|
|
67
|
+
this.config$.next({ ...config });
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
getCodeComponentDestroyed(): boolean {
|
|
71
|
+
return this.codeComponentDestroyed;
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
setCodeComponentDestroyed(value: boolean) {
|
|
75
|
+
this.codeComponentDestroyed = value;
|
|
76
|
+
},
|
|
77
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { skip } from 'rxjs';
|
|
2
|
+
import { CodingAssistanceOptions, Config, FormattingOptions } from '../models/configs';
|
|
3
|
+
import { Themes } from '../models/theme';
|
|
4
|
+
import { ConfigurationsService } from './configurations.service';
|
|
5
|
+
|
|
6
|
+
describe('ConfigurationsService', () => {
|
|
7
|
+
let service: ConfigurationsService;
|
|
8
|
+
let config: Config;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
service = new ConfigurationsService();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe('when updating the color theme', () => {
|
|
15
|
+
it('should update config$ with updated theme value', done => {
|
|
16
|
+
const theme = Themes.Dark;
|
|
17
|
+
service.config$.subscribe((val: Config) => {
|
|
18
|
+
expect(val[FormattingOptions.ColorTheme]).toEqual(theme);
|
|
19
|
+
done();
|
|
20
|
+
});
|
|
21
|
+
service.setColorTheme(theme);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('when config panel is opened', () => {
|
|
26
|
+
it('should publish true to configurationsPanelOpen$', done => {
|
|
27
|
+
service.configurationsPanelOpen$.subscribe(val => {
|
|
28
|
+
expect(val).toBeTruthy();
|
|
29
|
+
done();
|
|
30
|
+
});
|
|
31
|
+
service.openConfigPanel();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('when config panel is closed', () => {
|
|
36
|
+
it('should publish false to configurationsPanelOpen$', done => {
|
|
37
|
+
service.configurationsPanelOpen$.pipe(skip(1)).subscribe(val => {
|
|
38
|
+
expect(val).toBeFalsy();
|
|
39
|
+
done();
|
|
40
|
+
});
|
|
41
|
+
service.closeConfigPanel();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('when config is set', () => {
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
config = service.getInitialConfig();
|
|
48
|
+
config[FormattingOptions.ColorTheme] = Themes.Dark;
|
|
49
|
+
config[CodingAssistanceOptions.ErrorHighlighting] = false;
|
|
50
|
+
});
|
|
51
|
+
it('should publish value to config$', done => {
|
|
52
|
+
service.config$.subscribe(val => {
|
|
53
|
+
expect(val).toEqual(config);
|
|
54
|
+
done();
|
|
55
|
+
});
|
|
56
|
+
service.setConfig(config);
|
|
57
|
+
});
|
|
58
|
+
it('should publish updated theme value to colorTheme$', done => {
|
|
59
|
+
service.colorTheme$.subscribe(val => {
|
|
60
|
+
expect(val).toEqual(config[FormattingOptions.ColorTheme]);
|
|
61
|
+
done();
|
|
62
|
+
});
|
|
63
|
+
service.setConfig(config);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('when track config changed is called', () => {
|
|
68
|
+
it('should publish value to configFieldChanged$', done => {
|
|
69
|
+
const change = { [CodingAssistanceOptions.ErrorHighlighting]: false };
|
|
70
|
+
|
|
71
|
+
service.configFieldChanged$.subscribe(val => {
|
|
72
|
+
expect(val).toEqual(change);
|
|
73
|
+
done();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
service.trackConfigChanged(change);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { BehaviorSubject, distinctUntilChanged, map, Observable, Subject } from 'rxjs';
|
|
3
|
+
import { CodingAssistanceOptions, Config, FormattingOptions } from '../models/configs';
|
|
4
|
+
import { Themes } from '../models/theme';
|
|
5
|
+
|
|
6
|
+
@Injectable({
|
|
7
|
+
providedIn: 'root',
|
|
8
|
+
})
|
|
9
|
+
export class ConfigurationsService {
|
|
10
|
+
private defaultConfigs: Config = {
|
|
11
|
+
[FormattingOptions.ColorTheme]: Themes.Default,
|
|
12
|
+
[FormattingOptions.TabSize]: 4,
|
|
13
|
+
[FormattingOptions.FontSize]: 14,
|
|
14
|
+
[CodingAssistanceOptions.AutoComplete]: true,
|
|
15
|
+
[CodingAssistanceOptions.ErrorHighlighting]: true,
|
|
16
|
+
[CodingAssistanceOptions.AutoBrackets]: true,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
private formattingOptions = {
|
|
20
|
+
[FormattingOptions.ColorTheme]: [
|
|
21
|
+
{ label: 'Light', value: Themes.Default },
|
|
22
|
+
{ label: 'Dark', value: Themes.Dark },
|
|
23
|
+
],
|
|
24
|
+
[FormattingOptions.TabSize]: [
|
|
25
|
+
{ label: '2', value: 2 },
|
|
26
|
+
{ label: '3', value: 3 },
|
|
27
|
+
{ label: '4 (default)', value: 4 },
|
|
28
|
+
{ label: '5', value: 5 },
|
|
29
|
+
{ label: '8', value: 8 },
|
|
30
|
+
],
|
|
31
|
+
[FormattingOptions.FontSize]: [
|
|
32
|
+
{ label: '10px', value: 10 },
|
|
33
|
+
{ label: '12px', value: 12 },
|
|
34
|
+
{ label: '14px (default)', value: 14 },
|
|
35
|
+
{ label: '16px', value: 16 },
|
|
36
|
+
{ label: '18px', value: 18 },
|
|
37
|
+
{ label: '20px', value: 20 },
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
private codingAssistanceOptions = {
|
|
42
|
+
[CodingAssistanceOptions.AutoComplete]: true,
|
|
43
|
+
[CodingAssistanceOptions.ErrorHighlighting]: true,
|
|
44
|
+
[CodingAssistanceOptions.AutoBrackets]: true,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
private configSubj$ = new BehaviorSubject<Config>(this.defaultConfigs);
|
|
48
|
+
config$: Observable<Config> = this.configSubj$.asObservable();
|
|
49
|
+
|
|
50
|
+
private configFieldChangedSubj$ = new Subject<Partial<Config>>();
|
|
51
|
+
configFieldChanged$ = this.configFieldChangedSubj$.asObservable();
|
|
52
|
+
|
|
53
|
+
private currentConfig = { ...this.defaultConfigs };
|
|
54
|
+
|
|
55
|
+
colorTheme$: Observable<Themes> = this.config$.pipe(
|
|
56
|
+
map(config => config[FormattingOptions.ColorTheme] as Themes),
|
|
57
|
+
distinctUntilChanged()
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
private codeComponentDestroyed = true;
|
|
61
|
+
|
|
62
|
+
private configurationsPanelOpenSubj$ = new BehaviorSubject<boolean>(false);
|
|
63
|
+
configurationsPanelOpen$ = this.configurationsPanelOpenSubj$.asObservable();
|
|
64
|
+
|
|
65
|
+
setColorTheme(value: Themes): void {
|
|
66
|
+
this.currentConfig[FormattingOptions.ColorTheme] = value;
|
|
67
|
+
this.setConfig(this.currentConfig);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
setConfig(config: Config) {
|
|
71
|
+
this.configSubj$.next(config);
|
|
72
|
+
this.currentConfig = config;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
trackConfigChanged(changedField: Partial<Config>): void {
|
|
76
|
+
this.configFieldChangedSubj$.next(changedField);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
getInitialConfig(): Config {
|
|
80
|
+
return { ...this.currentConfig };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
openConfigPanel(): void {
|
|
84
|
+
this.configurationsPanelOpenSubj$.next(true);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
closeConfigPanel() {
|
|
88
|
+
this.configurationsPanelOpenSubj$.next(false);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
getFormattingOptions(): {
|
|
92
|
+
[key: string]: {
|
|
93
|
+
label: string;
|
|
94
|
+
value: Themes | number;
|
|
95
|
+
}[];
|
|
96
|
+
} {
|
|
97
|
+
return { ...this.formattingOptions };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
getCodingAssistanceOptions(): { [key: string]: boolean } {
|
|
101
|
+
return { ...this.codingAssistanceOptions };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
getCodeComponentDestroyed(): boolean {
|
|
105
|
+
return this.codeComponentDestroyed;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
setCodeComponentDestroyed(value: boolean) {
|
|
109
|
+
this.codeComponentDestroyed = value;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
import { MockProvider } from 'ng-mocks';
|
|
3
|
+
import { Subject } from 'rxjs';
|
|
4
|
+
import { CodeEditorLanguages } from '../components/code-editor/helpers/code-editor-helper.model';
|
|
5
|
+
import { LanguageChangeAction } from '../models/language-change-action';
|
|
6
|
+
import { Themes } from '../models/theme';
|
|
7
|
+
import { ConfigurationsService } from './configurations.service';
|
|
8
|
+
import { LibCodingTestService, ResetCodeAction } from './lib-coding-test.service';
|
|
9
|
+
import { TestCaseDeletionAction } from '../models/test-cases';
|
|
10
|
+
|
|
11
|
+
describe('LibCodingTestService', () => {
|
|
12
|
+
let service: LibCodingTestService;
|
|
13
|
+
const colorThemeSubject = new Subject<Themes>();
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
TestBed.configureTestingModule({
|
|
17
|
+
providers: [
|
|
18
|
+
LibCodingTestService,
|
|
19
|
+
MockProvider(ConfigurationsService, {
|
|
20
|
+
colorTheme$: colorThemeSubject,
|
|
21
|
+
configFieldChanged$: new Subject(),
|
|
22
|
+
}),
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
service = TestBed.inject(LibCodingTestService);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('when resetting the code', () => {
|
|
30
|
+
it('should publish ResetCodeAction.Try to codeReset$', done => {
|
|
31
|
+
service.codeReset$.subscribe(val => {
|
|
32
|
+
expect(val).toEqual(ResetCodeAction.Try);
|
|
33
|
+
done();
|
|
34
|
+
});
|
|
35
|
+
service.resetCode();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('when triggering the guided tour', () => {
|
|
40
|
+
it('should emit to startGuidedTour$', done => {
|
|
41
|
+
service.startGuidedTour$.subscribe(val => {
|
|
42
|
+
expect(val).toBeUndefined();
|
|
43
|
+
done();
|
|
44
|
+
});
|
|
45
|
+
service.startGuidedTour();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('when confirm resetting the code', () => {
|
|
50
|
+
it('should publish ResetCodeAction.Confirm to codeReset$', done => {
|
|
51
|
+
service.codeReset$.subscribe(val => {
|
|
52
|
+
expect(val).toEqual(ResetCodeAction.Confirm);
|
|
53
|
+
done();
|
|
54
|
+
});
|
|
55
|
+
service.confirmReset();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('when language change is cancelled', () => {
|
|
60
|
+
it('should publish LanguageChangeAction.Cancel to languageChange$', done => {
|
|
61
|
+
service.languageChange$.subscribe(val => {
|
|
62
|
+
expect(val).toEqual(LanguageChangeAction.Cancel);
|
|
63
|
+
done();
|
|
64
|
+
});
|
|
65
|
+
service.cancelLanguageChange();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('when language change is confirmed', () => {
|
|
70
|
+
it('should publish LanguageChangeAction.Confirm to languageChange$', done => {
|
|
71
|
+
service.languageChange$.subscribe(val => {
|
|
72
|
+
expect(val).toEqual(LanguageChangeAction.Confirm);
|
|
73
|
+
done();
|
|
74
|
+
});
|
|
75
|
+
service.confirmLanguageChange();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('when language is updated', () => {
|
|
80
|
+
it('should publish updated language to currentLanguage$', done => {
|
|
81
|
+
const language = CodeEditorLanguages.Java;
|
|
82
|
+
service.currentLanguage$.subscribe(val => {
|
|
83
|
+
expect(val).toEqual(language);
|
|
84
|
+
done();
|
|
85
|
+
});
|
|
86
|
+
service.changeCurrentLanguage(language);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('when handleTestCaseDeletion is called', () => {
|
|
91
|
+
it('should publish Try action to testCaseDeletionSub$', done => {
|
|
92
|
+
const index = 3;
|
|
93
|
+
|
|
94
|
+
service.testCaseDeletion$.subscribe(val => {
|
|
95
|
+
expect(val).toEqual({ action: TestCaseDeletionAction.Try, index });
|
|
96
|
+
done();
|
|
97
|
+
});
|
|
98
|
+
service.handleTestCaseDeletion(index);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('when confirmTestCaseDeletion is called', () => {
|
|
103
|
+
it('should publish Confirm action to testCaseDeletionSub$', done => {
|
|
104
|
+
const index = 3;
|
|
105
|
+
|
|
106
|
+
service.testCaseDeletion$.subscribe(val => {
|
|
107
|
+
expect(val).toEqual({ action: TestCaseDeletionAction.Confirm, index });
|
|
108
|
+
done();
|
|
109
|
+
});
|
|
110
|
+
service.confirmTestCaseDeletion(index);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('when updateTestCases is called', () => {
|
|
115
|
+
it('should set new value to testCases', () => {
|
|
116
|
+
const newTestCases = [
|
|
117
|
+
{
|
|
118
|
+
localId: 1,
|
|
119
|
+
name: 'name',
|
|
120
|
+
input: 'input',
|
|
121
|
+
expectedOutput: 'expectedOutput',
|
|
122
|
+
preloaded: false,
|
|
123
|
+
},
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
service.updateTestCases(newTestCases);
|
|
127
|
+
expect(service.getTestCases()).toEqual(newTestCases);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('when getValidTestCases is called', () => {
|
|
132
|
+
it('should return testCases with both filled input & expectedOutput', () => {
|
|
133
|
+
const newTestCases = [
|
|
134
|
+
{
|
|
135
|
+
localId: 1,
|
|
136
|
+
name: 'name',
|
|
137
|
+
input: 'input',
|
|
138
|
+
expectedOutput: 'expectedOutput',
|
|
139
|
+
preloaded: false,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
localId: 2,
|
|
143
|
+
name: 'name 1',
|
|
144
|
+
input: '',
|
|
145
|
+
expectedOutput: 'expectedOutput',
|
|
146
|
+
preloaded: false,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
localId: 3,
|
|
150
|
+
name: 'name 2',
|
|
151
|
+
input: 'input',
|
|
152
|
+
expectedOutput: '',
|
|
153
|
+
preloaded: false,
|
|
154
|
+
},
|
|
155
|
+
];
|
|
156
|
+
|
|
157
|
+
service.updateTestCases(newTestCases);
|
|
158
|
+
expect(service.getValidTestCases()).toEqual([newTestCases[0]]);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe('when getTestCasesCount is called', () => {
|
|
163
|
+
it('should return number of all testCases', () => {
|
|
164
|
+
const newTestCases = [
|
|
165
|
+
{
|
|
166
|
+
localId: 1,
|
|
167
|
+
name: 'name',
|
|
168
|
+
input: 'input',
|
|
169
|
+
expectedOutput: 'expectedOutput',
|
|
170
|
+
preloaded: false,
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
localId: 2,
|
|
174
|
+
name: 'name 1',
|
|
175
|
+
input: '',
|
|
176
|
+
expectedOutput: 'expectedOutput',
|
|
177
|
+
preloaded: false,
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
localId: 3,
|
|
181
|
+
name: 'name 2',
|
|
182
|
+
input: 'input',
|
|
183
|
+
expectedOutput: '',
|
|
184
|
+
preloaded: false,
|
|
185
|
+
},
|
|
186
|
+
];
|
|
187
|
+
|
|
188
|
+
service.updateTestCases(newTestCases);
|
|
189
|
+
expect(service.getTestCasesCount()).toEqual(newTestCases.length);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
describe('when get/setVersion is called', () => {
|
|
194
|
+
it('should set version with passed value', () => {
|
|
195
|
+
const version = '123';
|
|
196
|
+
|
|
197
|
+
service.setVersion(version);
|
|
198
|
+
expect(service.getVersion()).toEqual(version);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe('when get/setInitCode is called', () => {
|
|
203
|
+
it('should set initCode with passed value', () => {
|
|
204
|
+
const initCode = 'function test() { console.log(); }';
|
|
205
|
+
|
|
206
|
+
service.setInitCode(initCode);
|
|
207
|
+
expect(service.getInitCode()).toEqual(initCode);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
describe('when setting fullscreen', () => {
|
|
212
|
+
it('should publish value to isFullscreen', done => {
|
|
213
|
+
const isFullscreen = true;
|
|
214
|
+
|
|
215
|
+
service.isFullscreen$.subscribe(val => {
|
|
216
|
+
expect(val).toEqual(isFullscreen);
|
|
217
|
+
done();
|
|
218
|
+
});
|
|
219
|
+
service.setFullscreen(isFullscreen);
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
describe('when code value is updated', () => {
|
|
224
|
+
it('should publish updated code to codeChange$', done => {
|
|
225
|
+
const code = `def lucky_8( a, b ) :
|
|
226
|
+
#Insert your code here python`;
|
|
227
|
+
service.codeChange$.subscribe(val => {
|
|
228
|
+
expect(val).toEqual(code);
|
|
229
|
+
done();
|
|
230
|
+
});
|
|
231
|
+
service.changeCurrentCode(code);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
describe('when configurations color theme is updated', () => {
|
|
236
|
+
it('should publish updated theme to themeChanged$', done => {
|
|
237
|
+
const theme = Themes.Dark;
|
|
238
|
+
service.themeChanged$.subscribe(val => {
|
|
239
|
+
expect(val).toEqual(theme);
|
|
240
|
+
done();
|
|
241
|
+
});
|
|
242
|
+
colorThemeSubject.next(theme);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
describe('when triggerClearSavedCode() is called', () => {
|
|
247
|
+
it('should publish to clearSavedCode$', done => {
|
|
248
|
+
service.clearSavedCode$.subscribe(val => {
|
|
249
|
+
expect(val).toEqual(true);
|
|
250
|
+
done();
|
|
251
|
+
});
|
|
252
|
+
service.triggerClearSavedCode();
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
describe('when setBoilerplateLoadingStatus() is called', () => {
|
|
257
|
+
it('should publish to isBoilerplateLoading$', done => {
|
|
258
|
+
service.isBoilerplateLoading$.subscribe(val => {
|
|
259
|
+
expect(val).toEqual(false);
|
|
260
|
+
done();
|
|
261
|
+
});
|
|
262
|
+
service.setBoilerplateLoadingStatus(false);
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
});
|