@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,883 @@
|
|
|
1
|
+
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
|
2
|
+
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
|
3
|
+
import {
|
|
4
|
+
ComponentFixture,
|
|
5
|
+
fakeAsync,
|
|
6
|
+
flush,
|
|
7
|
+
TestBed,
|
|
8
|
+
tick,
|
|
9
|
+
discardPeriodicTasks,
|
|
10
|
+
} from '@angular/core/testing';
|
|
11
|
+
import { ActivatedRoute } from '@angular/router';
|
|
12
|
+
import { RouterTestingModule } from '@angular/router/testing';
|
|
13
|
+
import { TranslocoService } from '@ngneat/transloco';
|
|
14
|
+
import {
|
|
15
|
+
ApiService,
|
|
16
|
+
getTranslocoModule,
|
|
17
|
+
Question,
|
|
18
|
+
TestResultRead,
|
|
19
|
+
ThemeService,
|
|
20
|
+
EnvironmentService,
|
|
21
|
+
} from '@testgorilla/tgo-test-shared';
|
|
22
|
+
import { DialogService } from '@testgorilla/tgo-ui';
|
|
23
|
+
import { of, Subject } from 'rxjs';
|
|
24
|
+
|
|
25
|
+
import {
|
|
26
|
+
mockAssessment,
|
|
27
|
+
mockQuestion,
|
|
28
|
+
mockSQLTestCases,
|
|
29
|
+
mockTestCases,
|
|
30
|
+
mockTestResultRead,
|
|
31
|
+
} from '@testgorilla/tgo-test-shared';
|
|
32
|
+
import en from '../../../assets/i18n/en.json';
|
|
33
|
+
import { ProgrammingLanguage, ProgrammingLanguageVersioned } from '../../models/programming-language';
|
|
34
|
+
import { TgoCodingTestCandidateViewComponent } from './tgo-coding-test-candidate-view.component';
|
|
35
|
+
import { CandidatureApiService } from '../../services/candidate-coding-test-services/candidature-api.service';
|
|
36
|
+
import { CoderunnerApiService } from '../../services/candidate-coding-test-services/coderunner-api.service';
|
|
37
|
+
import { CodingTestTourService } from '../../services/candidate-coding-test-services/coding-test-tour.service';
|
|
38
|
+
import { CodingTestService } from '../../services/candidate-coding-test-services/coding-test.service';
|
|
39
|
+
import { PasteData } from '../../models/paste-data';
|
|
40
|
+
import { LibCodingTestService } from '../../services/lib-coding-test.service';
|
|
41
|
+
import { TestCaseDeletionAction } from '../../models/test-cases';
|
|
42
|
+
import { Modes } from '../../models/mode';
|
|
43
|
+
import { CodeEditorLanguages } from '../code-editor/helpers/code-editor-helper.model';
|
|
44
|
+
import { CodingTestConfigService } from '../../services/coding-test-config.service';
|
|
45
|
+
import { TGO_CODING_TEST_CONFIG } from '../../config/tgo-coding-test.token';
|
|
46
|
+
|
|
47
|
+
describe('TgoCodingTestCandidateViewComponent', () => {
|
|
48
|
+
let component: TgoCodingTestCandidateViewComponent;
|
|
49
|
+
let fixture: ComponentFixture<TgoCodingTestCandidateViewComponent>;
|
|
50
|
+
let codingTestServiceMock: Partial<jest.Mocked<CodingTestService>>;
|
|
51
|
+
let codingTestTourServiceMock: Partial<jest.Mocked<CodingTestTourService>>;
|
|
52
|
+
let candidatureApiServiceMock: Partial<jest.Mocked<CandidatureApiService>>;
|
|
53
|
+
let apiServiceMock: Partial<jest.Mocked<ApiService>>;
|
|
54
|
+
let transLocoServiceMock: Partial<jest.Mocked<TranslocoService>>;
|
|
55
|
+
let libCodingTestServiceMock: Partial<jest.Mocked<LibCodingTestService>>;
|
|
56
|
+
let environmentServiceMock: Partial<jest.Mocked<EnvironmentService>>;
|
|
57
|
+
let dialogServiceMock: Partial<jest.Mocked<DialogService>>;
|
|
58
|
+
let codingTestConfigServiceMock: Partial<jest.Mocked<CodingTestConfigService>>;
|
|
59
|
+
const companyColor = '#D410AA';
|
|
60
|
+
const mockApiUrl = 'http://localhost:4100/api/';
|
|
61
|
+
|
|
62
|
+
beforeEach(async () => {
|
|
63
|
+
apiServiceMock = {
|
|
64
|
+
setParams: jest.fn(),
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
codingTestServiceMock = {
|
|
68
|
+
runTest: jest.fn(),
|
|
69
|
+
handleLanguageChangeModal: jest.fn(),
|
|
70
|
+
handleDeleteTestCaseModal: jest.fn(),
|
|
71
|
+
getCurrentLanguageLAT: jest.fn(),
|
|
72
|
+
setCurrentLanguageLAT: jest.fn(),
|
|
73
|
+
setSqlTestCases: jest.fn(),
|
|
74
|
+
setTest: jest.fn(),
|
|
75
|
+
setIsSQLTest: jest.fn(),
|
|
76
|
+
listenCodingTestChanges: jest.fn().mockReturnValue(of()),
|
|
77
|
+
trackConfigChanged: jest.fn(),
|
|
78
|
+
listenDeleteCustomTestCases: jest.fn().mockReturnValue(
|
|
79
|
+
of({ index: 1, action: TestCaseDeletionAction.Try })
|
|
80
|
+
),
|
|
81
|
+
transformToExampleLATtestCase: jest.fn(),
|
|
82
|
+
transformToExampleSQLTestCase: jest.fn(),
|
|
83
|
+
codingTestResults$: of({
|
|
84
|
+
listResponse: [],
|
|
85
|
+
resume: { ok: 0, error: 0, total: 0 },
|
|
86
|
+
}),
|
|
87
|
+
sendCopypasteEvent$: jest.fn().mockReturnValue(of(null)),
|
|
88
|
+
sendAutosaveEvent$: jest.fn().mockReturnValue(of({} as any)),
|
|
89
|
+
isTestResultsLoading: jest.fn().mockReturnValue(false),
|
|
90
|
+
handleResetCodeModal: jest.fn(),
|
|
91
|
+
} as unknown as Partial<jest.Mocked<CodingTestService>>;
|
|
92
|
+
|
|
93
|
+
codingTestTourServiceMock = {
|
|
94
|
+
init: jest.fn(),
|
|
95
|
+
activeGuidedTourId$: of('fake-id'),
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
candidatureApiServiceMock = {
|
|
99
|
+
getAvailableLanguages$: jest.fn().mockReturnValue(of([])),
|
|
100
|
+
} as Partial<jest.Mocked<CandidatureApiService>>;
|
|
101
|
+
|
|
102
|
+
libCodingTestServiceMock = {
|
|
103
|
+
currentLanguage$: of(CodeEditorLanguages.Javascript),
|
|
104
|
+
startGuidedTour$: new Subject(),
|
|
105
|
+
themeChanged$: of('light' as any),
|
|
106
|
+
isFullscreen$: of(false),
|
|
107
|
+
setBoilerplateLoadingStatus: jest.fn(),
|
|
108
|
+
triggerClearSavedCode: jest.fn(),
|
|
109
|
+
clearLastLanguageSelected: jest.fn(),
|
|
110
|
+
getVersion: jest.fn().mockReturnValue('1.0.0'),
|
|
111
|
+
} as Partial<jest.Mocked<LibCodingTestService>>;
|
|
112
|
+
|
|
113
|
+
environmentServiceMock = {} as Partial<jest.Mocked<EnvironmentService>>;
|
|
114
|
+
Object.defineProperty(environmentServiceMock, 'isMobile', {
|
|
115
|
+
writable: true,
|
|
116
|
+
value: false
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
transLocoServiceMock = {
|
|
120
|
+
selectTranslateObject: jest
|
|
121
|
+
.fn()
|
|
122
|
+
.mockReturnValue(of({ testTranslationKey: 'test-translation' })),
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
dialogServiceMock = {
|
|
126
|
+
open: jest.fn().mockReturnValue({
|
|
127
|
+
afterClosed: jest.fn().mockReturnValue(of(true))
|
|
128
|
+
})
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
codingTestConfigServiceMock = {
|
|
132
|
+
getApiUrl: jest.fn().mockReturnValue(mockApiUrl),
|
|
133
|
+
getCoderunnerV2Endpoint: jest.fn().mockReturnValue('https://cr-v2-staging.testgorilla.com'),
|
|
134
|
+
} as Partial<jest.Mocked<CodingTestConfigService>>;
|
|
135
|
+
|
|
136
|
+
await TestBed.configureTestingModule({
|
|
137
|
+
declarations: [],
|
|
138
|
+
imports: [
|
|
139
|
+
TgoCodingTestCandidateViewComponent,
|
|
140
|
+
RouterTestingModule,
|
|
141
|
+
HttpClientTestingModule,
|
|
142
|
+
getTranslocoModule({ langs: { en } }),
|
|
143
|
+
],
|
|
144
|
+
schemas: [NO_ERRORS_SCHEMA],
|
|
145
|
+
})
|
|
146
|
+
.overrideComponent(TgoCodingTestCandidateViewComponent, {
|
|
147
|
+
add: {
|
|
148
|
+
providers: [
|
|
149
|
+
{
|
|
150
|
+
provide: ActivatedRoute,
|
|
151
|
+
useValue: {
|
|
152
|
+
snapshot: { firstChild: { url: [{ path: 'test-id' }] } },
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
{ provide: CodingTestService, useValue: codingTestServiceMock },
|
|
156
|
+
{
|
|
157
|
+
provide: CodingTestTourService,
|
|
158
|
+
useValue: codingTestTourServiceMock,
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
provide: ThemeService,
|
|
162
|
+
useValue: {
|
|
163
|
+
uiTheme: 'dark',
|
|
164
|
+
getCompanyColor: jest.fn().mockReturnValue(companyColor),
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
{ provide: CoderunnerApiService },
|
|
168
|
+
{
|
|
169
|
+
provide: CandidatureApiService,
|
|
170
|
+
useValue: candidatureApiServiceMock,
|
|
171
|
+
},
|
|
172
|
+
{ provide: ApiService, useValue: apiServiceMock },
|
|
173
|
+
{ provide: TranslocoService, useValue: transLocoServiceMock },
|
|
174
|
+
{ provide: LibCodingTestService, useValue: libCodingTestServiceMock },
|
|
175
|
+
{ provide: EnvironmentService, useValue: environmentServiceMock },
|
|
176
|
+
{ provide: DialogService, useValue: dialogServiceMock },
|
|
177
|
+
{ provide: CodingTestConfigService, useValue: codingTestConfigServiceMock },
|
|
178
|
+
{
|
|
179
|
+
provide: TGO_CODING_TEST_CONFIG,
|
|
180
|
+
useValue: {
|
|
181
|
+
apiUrl: mockApiUrl,
|
|
182
|
+
coderunnerV2Endpoint: 'https://cr-v2-staging.testgorilla.com',
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
},
|
|
187
|
+
})
|
|
188
|
+
.compileComponents();
|
|
189
|
+
|
|
190
|
+
fixture = TestBed.createComponent(TgoCodingTestCandidateViewComponent);
|
|
191
|
+
component = fixture.componentInstance;
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe('when component is initialized', () => {
|
|
195
|
+
it('should create and initialize default values', () => {
|
|
196
|
+
expect(component).toBeTruthy();
|
|
197
|
+
expect(component.hostClass).toBe('micro-question-code');
|
|
198
|
+
expect(component.isSQL).toBe(false);
|
|
199
|
+
expect(component.isLAT).toBe(true);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe('when ngOnInit is called', () => {
|
|
204
|
+
describe('and test is not SQL', () => {
|
|
205
|
+
it('should setup no SQL test state', fakeAsync(() => {
|
|
206
|
+
component.test = mockTestResultRead;
|
|
207
|
+
component.question = mockQuestion;
|
|
208
|
+
component.question.context.testcases = mockTestCases;
|
|
209
|
+
jest.spyOn(apiServiceMock, 'setParams');
|
|
210
|
+
jest
|
|
211
|
+
.spyOn(codingTestServiceMock, 'listenCodingTestChanges')
|
|
212
|
+
.mockReturnValue(of());
|
|
213
|
+
jest.spyOn(codingTestServiceMock, 'trackConfigChanged');
|
|
214
|
+
jest
|
|
215
|
+
.spyOn(codingTestServiceMock, 'listenDeleteCustomTestCases')
|
|
216
|
+
.mockReturnValue(
|
|
217
|
+
of({ index: 1, action: TestCaseDeletionAction.Try })
|
|
218
|
+
);
|
|
219
|
+
jest.spyOn(transLocoServiceMock, 'selectTranslateObject');
|
|
220
|
+
|
|
221
|
+
component.ngOnInit();
|
|
222
|
+
expect(apiServiceMock.setParams).toHaveBeenCalledWith(
|
|
223
|
+
'test-id',
|
|
224
|
+
mockAssessment.locale,
|
|
225
|
+
'CODING_QUESTION',
|
|
226
|
+
mockApiUrl
|
|
227
|
+
);
|
|
228
|
+
expect(component.isSQL).toBe(false);
|
|
229
|
+
expect(component.isLAT).toBe(true);
|
|
230
|
+
expect(component.mode).toBe(Modes.Preview);
|
|
231
|
+
expect(
|
|
232
|
+
codingTestServiceMock.listenCodingTestChanges
|
|
233
|
+
).toHaveBeenCalled();
|
|
234
|
+
expect(codingTestServiceMock.trackConfigChanged).toHaveBeenCalled();
|
|
235
|
+
expect(
|
|
236
|
+
codingTestServiceMock.listenDeleteCustomTestCases
|
|
237
|
+
).toHaveBeenCalled();
|
|
238
|
+
expect(transLocoServiceMock.selectTranslateObject).toHaveBeenCalled();
|
|
239
|
+
expect(component.codingLibTranslations()).toEqual({
|
|
240
|
+
testTranslationKey: 'test-translation',
|
|
241
|
+
});
|
|
242
|
+
flush();
|
|
243
|
+
}));
|
|
244
|
+
|
|
245
|
+
it('should setup autosave when not in preview mode', fakeAsync(() => {
|
|
246
|
+
component.test = { ...mockTestResultRead, is_preview_mode: false };
|
|
247
|
+
component.question = mockQuestion;
|
|
248
|
+
component.question.context.testcases = mockTestCases;
|
|
249
|
+
jest.spyOn(codingTestServiceMock, 'sendAutosaveEvent$').mockReturnValue(of({} as any));
|
|
250
|
+
|
|
251
|
+
component.ngOnInit();
|
|
252
|
+
|
|
253
|
+
// Fast forward 5 seconds to trigger autosave
|
|
254
|
+
tick(5000);
|
|
255
|
+
|
|
256
|
+
expect(codingTestServiceMock.sendAutosaveEvent$).toHaveBeenCalledWith(
|
|
257
|
+
component.code,
|
|
258
|
+
component.question.id
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
// Clean up any remaining periodic timers
|
|
262
|
+
discardPeriodicTasks();
|
|
263
|
+
flush();
|
|
264
|
+
}));
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
describe('and test is SQL', () => {
|
|
268
|
+
it('should setup the SQL test state', fakeAsync(() => {
|
|
269
|
+
component.test = mockTestResultRead;
|
|
270
|
+
component.test.is_preview_mode = false;
|
|
271
|
+
component.question = mockQuestion;
|
|
272
|
+
component.question.context.code_language = 'sql';
|
|
273
|
+
component.question.context.sql_testcases = mockSQLTestCases;
|
|
274
|
+
component.question.context.initial_sql =
|
|
275
|
+
mockSQLTestCases[0].initial_sql;
|
|
276
|
+
jest.spyOn(apiServiceMock, 'setParams');
|
|
277
|
+
jest.spyOn(codingTestServiceMock, 'setSqlTestCases');
|
|
278
|
+
jest.spyOn(codingTestServiceMock, 'listenCodingTestChanges');
|
|
279
|
+
jest.spyOn(codingTestServiceMock, 'trackConfigChanged');
|
|
280
|
+
jest.spyOn(transLocoServiceMock, 'selectTranslateObject');
|
|
281
|
+
|
|
282
|
+
component.ngOnInit();
|
|
283
|
+
expect(component.isSQL).toBe(true);
|
|
284
|
+
expect(component.isLAT).toBe(false);
|
|
285
|
+
expect(component.mode).toBe(Modes.Running);
|
|
286
|
+
expect(apiServiceMock.setParams).toHaveBeenCalledWith(
|
|
287
|
+
'test-id',
|
|
288
|
+
mockAssessment.locale,
|
|
289
|
+
'CODING_QUESTION',
|
|
290
|
+
mockApiUrl
|
|
291
|
+
);
|
|
292
|
+
expect(codingTestServiceMock.setSqlTestCases).toHaveBeenCalledWith(
|
|
293
|
+
mockSQLTestCases
|
|
294
|
+
);
|
|
295
|
+
expect(
|
|
296
|
+
codingTestServiceMock.listenCodingTestChanges
|
|
297
|
+
).toHaveBeenCalled();
|
|
298
|
+
expect(codingTestServiceMock.trackConfigChanged).toHaveBeenCalled();
|
|
299
|
+
expect(transLocoServiceMock.selectTranslateObject).toHaveBeenCalled();
|
|
300
|
+
tick();
|
|
301
|
+
flush();
|
|
302
|
+
expect(component.codingLibTranslations()).toEqual({
|
|
303
|
+
testTranslationKey: 'test-translation',
|
|
304
|
+
});
|
|
305
|
+
component.ngOnDestroy();
|
|
306
|
+
}));
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
describe('additional edge cases', () => {
|
|
310
|
+
it('should handle expiration observable when provided', fakeAsync(() => {
|
|
311
|
+
const expirationSubject = new Subject<void>();
|
|
312
|
+
component.expirationObservable = expirationSubject.asObservable();
|
|
313
|
+
component.test = { ...mockTestResultRead, is_preview_mode: false };
|
|
314
|
+
component.question = {
|
|
315
|
+
...mockQuestion,
|
|
316
|
+
context: { ...mockQuestion.context, code_language: 'javascript' }
|
|
317
|
+
};
|
|
318
|
+
component.code = 'test code';
|
|
319
|
+
component.currentLanguage = 'javascript';
|
|
320
|
+
component.isSQL = false;
|
|
321
|
+
jest.spyOn(libCodingTestServiceMock, 'triggerClearSavedCode');
|
|
322
|
+
jest.spyOn(libCodingTestServiceMock, 'clearLastLanguageSelected');
|
|
323
|
+
jest.spyOn(component.submissionStateChanged, 'emit');
|
|
324
|
+
jest.spyOn(component.configurationStateChanged, 'emit');
|
|
325
|
+
|
|
326
|
+
component.ngOnInit();
|
|
327
|
+
|
|
328
|
+
// Trigger expiration
|
|
329
|
+
expirationSubject.next();
|
|
330
|
+
tick();
|
|
331
|
+
|
|
332
|
+
expect(libCodingTestServiceMock.triggerClearSavedCode).toHaveBeenCalled();
|
|
333
|
+
expect(libCodingTestServiceMock.clearLastLanguageSelected).toHaveBeenCalled();
|
|
334
|
+
expect(component.submissionStateChanged.emit).toHaveBeenCalledWith({
|
|
335
|
+
text: 'test code',
|
|
336
|
+
language: 'javascript-1.0.0',
|
|
337
|
+
});
|
|
338
|
+
expect(component.configurationStateChanged.emit).toHaveBeenCalledWith({
|
|
339
|
+
isSavingQuestionDisabled: false,
|
|
340
|
+
});
|
|
341
|
+
discardPeriodicTasks();
|
|
342
|
+
flush();
|
|
343
|
+
}));
|
|
344
|
+
|
|
345
|
+
it('should handle complete observable when provided', fakeAsync(() => {
|
|
346
|
+
const completeSubject = new Subject<void>();
|
|
347
|
+
component.completeObservable = completeSubject.asObservable();
|
|
348
|
+
component.test = { ...mockTestResultRead, is_preview_mode: false };
|
|
349
|
+
component.question = mockQuestion;
|
|
350
|
+
|
|
351
|
+
component.ngOnInit();
|
|
352
|
+
|
|
353
|
+
// Trigger completion
|
|
354
|
+
completeSubject.next();
|
|
355
|
+
tick();
|
|
356
|
+
|
|
357
|
+
expect(dialogServiceMock.open).toHaveBeenCalled();
|
|
358
|
+
discardPeriodicTasks();
|
|
359
|
+
flush();
|
|
360
|
+
}));
|
|
361
|
+
|
|
362
|
+
it('should handle complete observable in preview mode', fakeAsync(() => {
|
|
363
|
+
const completeSubject = new Subject<void>();
|
|
364
|
+
component.completeObservable = completeSubject.asObservable();
|
|
365
|
+
component.test = { ...mockTestResultRead, is_preview_mode: true };
|
|
366
|
+
component.question = mockQuestion;
|
|
367
|
+
jest.spyOn(libCodingTestServiceMock, 'triggerClearSavedCode');
|
|
368
|
+
|
|
369
|
+
component.ngOnInit();
|
|
370
|
+
|
|
371
|
+
// Trigger completion
|
|
372
|
+
completeSubject.next();
|
|
373
|
+
tick();
|
|
374
|
+
|
|
375
|
+
expect(libCodingTestServiceMock.triggerClearSavedCode).toHaveBeenCalled();
|
|
376
|
+
flush();
|
|
377
|
+
}));
|
|
378
|
+
|
|
379
|
+
it('should handle language change without current language found', fakeAsync(() => {
|
|
380
|
+
component.question = {
|
|
381
|
+
...mockQuestion,
|
|
382
|
+
context: {
|
|
383
|
+
...mockQuestion.context,
|
|
384
|
+
boilerplates: [
|
|
385
|
+
{
|
|
386
|
+
programming_language: { id: 1, name: 'javascript', version: '1.0' },
|
|
387
|
+
code: 'console.log("hello");'
|
|
388
|
+
}
|
|
389
|
+
]
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
candidatureApiServiceMock.getAvailableLanguages$ = jest.fn().mockReturnValue(of([]));
|
|
393
|
+
libCodingTestServiceMock.currentLanguage$ = of('python' as any); // Language not in rawLanguages
|
|
394
|
+
jest.spyOn(codingTestServiceMock, 'setCurrentLanguageLAT');
|
|
395
|
+
|
|
396
|
+
component['loadAvailableLanguages']();
|
|
397
|
+
tick();
|
|
398
|
+
|
|
399
|
+
expect(codingTestServiceMock.setCurrentLanguageLAT).not.toHaveBeenCalled();
|
|
400
|
+
flush();
|
|
401
|
+
}));
|
|
402
|
+
|
|
403
|
+
it('should handle language change without init code', fakeAsync(() => {
|
|
404
|
+
component.question = {
|
|
405
|
+
...mockQuestion,
|
|
406
|
+
context: {
|
|
407
|
+
...mockQuestion.context,
|
|
408
|
+
boilerplates: [
|
|
409
|
+
{
|
|
410
|
+
programming_language: { id: 1, name: 'javascript', version: '1.0' },
|
|
411
|
+
code: 'console.log("hello");'
|
|
412
|
+
}
|
|
413
|
+
]
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
candidatureApiServiceMock.getAvailableLanguages$ = jest.fn().mockReturnValue(of([]));
|
|
417
|
+
libCodingTestServiceMock.currentLanguage$ = of('python' as any); // Language not in initCodesMap
|
|
418
|
+
jest.spyOn(component, 'updateCode');
|
|
419
|
+
|
|
420
|
+
component['loadAvailableLanguages']();
|
|
421
|
+
tick();
|
|
422
|
+
|
|
423
|
+
expect(component.updateCode).not.toHaveBeenCalled();
|
|
424
|
+
flush();
|
|
425
|
+
}));
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
describe('when loadAvailableLanguages is called', () => {
|
|
430
|
+
beforeEach(() => {
|
|
431
|
+
component.question = {
|
|
432
|
+
...mockQuestion,
|
|
433
|
+
context: {
|
|
434
|
+
...mockQuestion.context,
|
|
435
|
+
boilerplates: [
|
|
436
|
+
{
|
|
437
|
+
programming_language: { id: 1, name: 'javascript', version: '1.0' },
|
|
438
|
+
code: 'console.log("hello");'
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
programming_language: { id: 2, name: 'python', version: '3.8' },
|
|
442
|
+
code: 'print("hello")'
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
programming_language: { id: 3, name: '', version: '1.0' }, // Test edge case with empty name
|
|
446
|
+
code: 'test code'
|
|
447
|
+
}
|
|
448
|
+
]
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
it('should load all languages when no restrictions', fakeAsync(() => {
|
|
454
|
+
candidatureApiServiceMock.getAvailableLanguages$ = jest.fn().mockReturnValue(of([]));
|
|
455
|
+
jest.spyOn(component.loadingStateChanged, 'emit');
|
|
456
|
+
jest.spyOn(libCodingTestServiceMock, 'setBoilerplateLoadingStatus');
|
|
457
|
+
|
|
458
|
+
component['loadAvailableLanguages']();
|
|
459
|
+
tick();
|
|
460
|
+
|
|
461
|
+
expect(component.rawLanguages).toHaveLength(3);
|
|
462
|
+
expect(component.languages()).toEqual([
|
|
463
|
+
{ label: 'Javascript', value: 'javascript', version: '1.0' },
|
|
464
|
+
{ label: 'Python', value: 'python', version: '3.8' },
|
|
465
|
+
{ label: 'Unknown', value: '', version: '1.0' }
|
|
466
|
+
]);
|
|
467
|
+
expect(component.loadingStateChanged.emit).toHaveBeenCalledWith(false);
|
|
468
|
+
expect(libCodingTestServiceMock.setBoilerplateLoadingStatus).toHaveBeenCalledWith(false);
|
|
469
|
+
expect(component.initCodesMap.get('javascript' as CodeEditorLanguages)).toBe('console.log("hello");');
|
|
470
|
+
expect(component.initCodesMap.get('python' as CodeEditorLanguages)).toBe('print("hello")');
|
|
471
|
+
flush();
|
|
472
|
+
}));
|
|
473
|
+
|
|
474
|
+
it('should filter languages based on available language ids', fakeAsync(() => {
|
|
475
|
+
candidatureApiServiceMock.getAvailableLanguages$ = jest.fn().mockReturnValue(of([1]));
|
|
476
|
+
jest.spyOn(codingTestServiceMock, 'setCurrentLanguageLAT');
|
|
477
|
+
|
|
478
|
+
component['loadAvailableLanguages']();
|
|
479
|
+
tick();
|
|
480
|
+
|
|
481
|
+
expect(component.rawLanguages).toHaveLength(1);
|
|
482
|
+
expect(component.rawLanguages[0].name).toBe('javascript');
|
|
483
|
+
expect(codingTestServiceMock.setCurrentLanguageLAT).toHaveBeenCalledWith(
|
|
484
|
+
component.rawLanguages[0]
|
|
485
|
+
);
|
|
486
|
+
flush();
|
|
487
|
+
}));
|
|
488
|
+
|
|
489
|
+
it('should handle language change and update init code', fakeAsync(() => {
|
|
490
|
+
candidatureApiServiceMock.getAvailableLanguages$ = jest.fn().mockReturnValue(of([]));
|
|
491
|
+
jest.spyOn(component, 'updateCode');
|
|
492
|
+
|
|
493
|
+
component['loadAvailableLanguages']();
|
|
494
|
+
tick();
|
|
495
|
+
|
|
496
|
+
expect(component.initCode).toBe('console.log("hello");');
|
|
497
|
+
expect(component.updateCode).toHaveBeenCalledWith('console.log("hello");');
|
|
498
|
+
flush();
|
|
499
|
+
}));
|
|
500
|
+
|
|
501
|
+
it('should skip boilerplates without programming language name', fakeAsync(() => {
|
|
502
|
+
component.question.context.boilerplates = [
|
|
503
|
+
{
|
|
504
|
+
programming_language: { id: 1, name: null as any, version: '1.0' },
|
|
505
|
+
code: 'test code'
|
|
506
|
+
}
|
|
507
|
+
];
|
|
508
|
+
candidatureApiServiceMock.getAvailableLanguages$ = jest.fn().mockReturnValue(of([]));
|
|
509
|
+
|
|
510
|
+
component['loadAvailableLanguages']();
|
|
511
|
+
tick();
|
|
512
|
+
|
|
513
|
+
expect(component.initCodesMap.size).toBe(0);
|
|
514
|
+
flush();
|
|
515
|
+
}));
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
describe('when languageChange method is called', () => {
|
|
519
|
+
it('should call the handleLanguageChangeModal method with right theme and language', () => {
|
|
520
|
+
component.rawLanguages = [
|
|
521
|
+
{ name: 'javascript' },
|
|
522
|
+
] as ProgrammingLanguage[];
|
|
523
|
+
const resultId = 1;
|
|
524
|
+
const questionId = 2;
|
|
525
|
+
component.question = {
|
|
526
|
+
id: resultId,
|
|
527
|
+
question_id: questionId,
|
|
528
|
+
} as Question;
|
|
529
|
+
jest.spyOn(codingTestServiceMock, 'handleLanguageChangeModal');
|
|
530
|
+
component.languageChange(CodeEditorLanguages.Javascript);
|
|
531
|
+
expect(
|
|
532
|
+
codingTestServiceMock.handleLanguageChangeModal
|
|
533
|
+
).toHaveBeenCalledWith(resultId, { name: 'javascript' }, 'light', companyColor);
|
|
534
|
+
});
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
describe('when updateCode method is called', () => {
|
|
538
|
+
it('should set new code value', () => {
|
|
539
|
+
const code = 'sample new code';
|
|
540
|
+
component.updateCode(code);
|
|
541
|
+
expect(component.code).toEqual(code);
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
describe('when runTest method is called', () => {
|
|
546
|
+
describe('and test is language agnostic', () => {
|
|
547
|
+
it('should emit LATRunTestClicked and call runTest method of CodingTestService', () => {
|
|
548
|
+
const resultId = 1;
|
|
549
|
+
const questionId = 2;
|
|
550
|
+
const testResultId = 3;
|
|
551
|
+
|
|
552
|
+
component.isLAT = true;
|
|
553
|
+
component.isSQL = false;
|
|
554
|
+
component.code = 'test code';
|
|
555
|
+
component.test = {
|
|
556
|
+
id: testResultId,
|
|
557
|
+
is_preview_mode: false,
|
|
558
|
+
} as TestResultRead;
|
|
559
|
+
component.question = {
|
|
560
|
+
id: resultId,
|
|
561
|
+
question_id: questionId,
|
|
562
|
+
} as Question;
|
|
563
|
+
jest.spyOn(component.navigationButtonStateChanged, 'emit');
|
|
564
|
+
|
|
565
|
+
component.runTest();
|
|
566
|
+
|
|
567
|
+
expect(codingTestServiceMock.runTest).toHaveBeenCalledWith(
|
|
568
|
+
resultId,
|
|
569
|
+
'test code',
|
|
570
|
+
true,
|
|
571
|
+
false,
|
|
572
|
+
false,
|
|
573
|
+
false,
|
|
574
|
+
questionId,
|
|
575
|
+
testResultId,
|
|
576
|
+
component.test
|
|
577
|
+
);
|
|
578
|
+
expect(component.navigationButtonStateChanged.emit).toHaveBeenCalledWith({
|
|
579
|
+
disabled: false,
|
|
580
|
+
});
|
|
581
|
+
expect(component.firstTestRunComplete).toBe(true);
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
it('should not emit navigation button state change if first test run already complete', () => {
|
|
585
|
+
component.firstTestRunComplete = true;
|
|
586
|
+
component.isLAT = true;
|
|
587
|
+
component.isSQL = false;
|
|
588
|
+
component.code = 'test code';
|
|
589
|
+
component.test = { id: 1, is_preview_mode: false } as TestResultRead;
|
|
590
|
+
component.question = { id: 1, question_id: 2 } as Question;
|
|
591
|
+
jest.spyOn(component.navigationButtonStateChanged, 'emit');
|
|
592
|
+
|
|
593
|
+
component.runTest();
|
|
594
|
+
|
|
595
|
+
expect(component.navigationButtonStateChanged.emit).not.toHaveBeenCalled();
|
|
596
|
+
});
|
|
597
|
+
});
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
describe('when screenshotPaste method is called', () => {
|
|
601
|
+
const code = 'existing code';
|
|
602
|
+
const pastedData = 'pasted text';
|
|
603
|
+
const pasteEvent = { type: 'paste', data: pastedData };
|
|
604
|
+
|
|
605
|
+
describe('and event type is paste', () => {
|
|
606
|
+
it('should call sendCopypasteEvent$', () => {
|
|
607
|
+
component.isLAT = true;
|
|
608
|
+
component.code = code;
|
|
609
|
+
component.question = mockQuestion;
|
|
610
|
+
component.screenshotPaste(pasteEvent);
|
|
611
|
+
expect(codingTestServiceMock.sendCopypasteEvent$).toHaveBeenCalledWith(
|
|
612
|
+
code,
|
|
613
|
+
pastedData,
|
|
614
|
+
mockQuestion.id
|
|
615
|
+
);
|
|
616
|
+
});
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
describe('and type is NOT paste', () => {
|
|
620
|
+
it('should NOT call sendCopypasteEvent$', () => {
|
|
621
|
+
component.screenshotPaste({ type: 'any' } as PasteData);
|
|
622
|
+
expect(
|
|
623
|
+
codingTestServiceMock.sendCopypasteEvent$
|
|
624
|
+
).not.toHaveBeenCalled();
|
|
625
|
+
});
|
|
626
|
+
});
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
describe('when openSaveDialog is called', () => {
|
|
630
|
+
it('should open confirm dialog and handle confirmation', () => {
|
|
631
|
+
jest.spyOn(component.configurationStateChanged, 'emit');
|
|
632
|
+
jest.spyOn(libCodingTestServiceMock, 'triggerClearSavedCode');
|
|
633
|
+
jest.spyOn(libCodingTestServiceMock, 'clearLastLanguageSelected');
|
|
634
|
+
jest.spyOn(component.submissionStateChanged, 'emit');
|
|
635
|
+
|
|
636
|
+
component.code = 'test code';
|
|
637
|
+
component.currentLanguage = 'javascript';
|
|
638
|
+
component.isSQL = false;
|
|
639
|
+
component.openSaveDialog();
|
|
640
|
+
|
|
641
|
+
expect(dialogServiceMock.open).toHaveBeenCalled();
|
|
642
|
+
expect(libCodingTestServiceMock.triggerClearSavedCode).toHaveBeenCalled();
|
|
643
|
+
expect(libCodingTestServiceMock.clearLastLanguageSelected).toHaveBeenCalled();
|
|
644
|
+
expect(component.submissionStateChanged.emit).toHaveBeenCalledWith({
|
|
645
|
+
text: 'test code',
|
|
646
|
+
language: 'javascript-1.0.0',
|
|
647
|
+
});
|
|
648
|
+
expect(component.configurationStateChanged.emit).toHaveBeenCalledWith({
|
|
649
|
+
isSavingQuestionDisabled: false,
|
|
650
|
+
});
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
it('should not submit if dialog is cancelled', () => {
|
|
654
|
+
dialogServiceMock.open = jest.fn().mockReturnValue({
|
|
655
|
+
afterClosed: jest.fn().mockReturnValue(of(false))
|
|
656
|
+
});
|
|
657
|
+
jest.spyOn(component.submissionStateChanged, 'emit');
|
|
658
|
+
|
|
659
|
+
component.openSaveDialog();
|
|
660
|
+
|
|
661
|
+
expect(component.submissionStateChanged.emit).not.toHaveBeenCalled();
|
|
662
|
+
});
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
describe('ngOnDestroy', () => {
|
|
666
|
+
it('should emit anti-cheating configuration when not in preview mode', () => {
|
|
667
|
+
component.test = { is_preview_mode: false } as TestResultRead;
|
|
668
|
+
jest.spyOn(component.antiCheatingConfigurationChanged, 'emit');
|
|
669
|
+
|
|
670
|
+
component.ngOnDestroy();
|
|
671
|
+
|
|
672
|
+
expect(component.antiCheatingConfigurationChanged.emit).toHaveBeenCalledWith({
|
|
673
|
+
fullscreenTracking: false,
|
|
674
|
+
mouseEventTracking: false,
|
|
675
|
+
snapshotsTracking: false,
|
|
676
|
+
});
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
it('should not emit anti-cheating configuration when in preview mode', () => {
|
|
680
|
+
component.test = { is_preview_mode: true } as TestResultRead;
|
|
681
|
+
jest.spyOn(component.antiCheatingConfigurationChanged, 'emit');
|
|
682
|
+
|
|
683
|
+
component.ngOnDestroy();
|
|
684
|
+
|
|
685
|
+
expect(component.antiCheatingConfigurationChanged.emit).not.toHaveBeenCalled();
|
|
686
|
+
});
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
describe('private methods', () => {
|
|
690
|
+
describe('getAllLanguages', () => {
|
|
691
|
+
it('should return programming languages from boilerplates', () => {
|
|
692
|
+
component.question = {
|
|
693
|
+
context: {
|
|
694
|
+
boilerplates: [
|
|
695
|
+
{ programming_language: { name: 'javascript' } },
|
|
696
|
+
{ programming_language: { name: 'python' } }
|
|
697
|
+
]
|
|
698
|
+
}
|
|
699
|
+
} as any;
|
|
700
|
+
|
|
701
|
+
const result = component['getAllLanguages']();
|
|
702
|
+
|
|
703
|
+
expect(result).toEqual([
|
|
704
|
+
{ name: 'javascript' },
|
|
705
|
+
{ name: 'python' }
|
|
706
|
+
]);
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
it('should return empty array when no boilerplates', () => {
|
|
710
|
+
component.question = { context: {} } as any;
|
|
711
|
+
|
|
712
|
+
const result = component['getAllLanguages']();
|
|
713
|
+
|
|
714
|
+
expect(result).toEqual([]);
|
|
715
|
+
});
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
describe('setupState', () => {
|
|
719
|
+
it('should call all setup methods', () => {
|
|
720
|
+
component.test = mockTestResultRead;
|
|
721
|
+
component.question = { ...mockQuestion, context: { ...mockQuestion.context, code_language: 'javascript' } };
|
|
722
|
+
component.assessment = mockAssessment;
|
|
723
|
+
jest.spyOn(apiServiceMock, 'setParams');
|
|
724
|
+
jest.spyOn(transLocoServiceMock, 'selectTranslateObject');
|
|
725
|
+
jest.spyOn(codingTestServiceMock, 'setIsSQLTest');
|
|
726
|
+
|
|
727
|
+
component['setupState']();
|
|
728
|
+
|
|
729
|
+
expect(apiServiceMock.setParams).toHaveBeenCalled();
|
|
730
|
+
expect(transLocoServiceMock.selectTranslateObject).toHaveBeenCalled();
|
|
731
|
+
expect(codingTestServiceMock.setIsSQLTest).toHaveBeenCalledWith(false);
|
|
732
|
+
});
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
describe('handleGuidedTour', () => {
|
|
736
|
+
it('should initialize guided tour for preview mode on desktop', fakeAsync(() => {
|
|
737
|
+
Object.defineProperty(environmentServiceMock, 'isMobile', { value: false });
|
|
738
|
+
component.test = { is_preview_mode: true } as TestResultRead;
|
|
739
|
+
jest.spyOn(codingTestTourServiceMock, 'init');
|
|
740
|
+
|
|
741
|
+
component['handleGuidedTour']();
|
|
742
|
+
tick(1500);
|
|
743
|
+
|
|
744
|
+
expect(codingTestTourServiceMock.init).toHaveBeenCalled();
|
|
745
|
+
expect(component['wasTourShown']).toBe(true);
|
|
746
|
+
}));
|
|
747
|
+
|
|
748
|
+
it('should not initialize guided tour on mobile', fakeAsync(() => {
|
|
749
|
+
Object.defineProperty(environmentServiceMock, 'isMobile', { value: true });
|
|
750
|
+
component.test = { is_preview_mode: true } as TestResultRead;
|
|
751
|
+
jest.spyOn(codingTestTourServiceMock, 'init');
|
|
752
|
+
|
|
753
|
+
component['handleGuidedTour']();
|
|
754
|
+
tick(1500);
|
|
755
|
+
|
|
756
|
+
expect(codingTestTourServiceMock.init).not.toHaveBeenCalled();
|
|
757
|
+
}));
|
|
758
|
+
|
|
759
|
+
it('should not initialize guided tour when already shown', fakeAsync(() => {
|
|
760
|
+
Object.defineProperty(environmentServiceMock, 'isMobile', { value: false });
|
|
761
|
+
component.test = { is_preview_mode: true } as TestResultRead;
|
|
762
|
+
component['wasTourShown'] = true;
|
|
763
|
+
jest.spyOn(codingTestTourServiceMock, 'init');
|
|
764
|
+
|
|
765
|
+
component['handleGuidedTour']();
|
|
766
|
+
tick(1500);
|
|
767
|
+
|
|
768
|
+
expect(codingTestTourServiceMock.init).not.toHaveBeenCalled();
|
|
769
|
+
}));
|
|
770
|
+
});
|
|
771
|
+
});
|
|
772
|
+
|
|
773
|
+
describe('getVersionedLanguage', () => {
|
|
774
|
+
beforeEach(() => {
|
|
775
|
+
component.test = mockTestResultRead;
|
|
776
|
+
component.question = mockQuestion;
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
it('should return language with version for LAT tests', () => {
|
|
780
|
+
component.isSQL = false;
|
|
781
|
+
component.currentLanguage = 'javascript';
|
|
782
|
+
|
|
783
|
+
const result = component['getVersionedLanguage']();
|
|
784
|
+
|
|
785
|
+
expect(result).toBe('javascript-1.0.0');
|
|
786
|
+
});
|
|
787
|
+
|
|
788
|
+
it('should return SQLite for SQL tests', () => {
|
|
789
|
+
component.isSQL = true;
|
|
790
|
+
component.currentLanguage = 'sql';
|
|
791
|
+
|
|
792
|
+
const result = component['getVersionedLanguage']();
|
|
793
|
+
|
|
794
|
+
expect(result).toBe(ProgrammingLanguageVersioned.SQLite);
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
it('should return undefined when no language is selected', () => {
|
|
798
|
+
component.currentLanguage = undefined;
|
|
799
|
+
|
|
800
|
+
const result = component['getVersionedLanguage']();
|
|
801
|
+
|
|
802
|
+
expect(result).toBeUndefined();
|
|
803
|
+
});
|
|
804
|
+
});
|
|
805
|
+
|
|
806
|
+
describe('submitCode with language', () => {
|
|
807
|
+
beforeEach(() => {
|
|
808
|
+
component.test = mockTestResultRead;
|
|
809
|
+
component.question = mockQuestion;
|
|
810
|
+
jest.spyOn(component.submissionStateChanged, 'emit');
|
|
811
|
+
});
|
|
812
|
+
|
|
813
|
+
it('should emit submission with language for LAT test', () => {
|
|
814
|
+
component.isSQL = false;
|
|
815
|
+
component.code = 'console.log("test");';
|
|
816
|
+
component.currentLanguage = 'javascript';
|
|
817
|
+
|
|
818
|
+
component['submitCode']();
|
|
819
|
+
|
|
820
|
+
expect(component.submissionStateChanged.emit).toHaveBeenCalledWith({
|
|
821
|
+
text: 'console.log("test");',
|
|
822
|
+
language: 'javascript-1.0.0',
|
|
823
|
+
});
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
it('should emit submission with SQLite for SQL test', () => {
|
|
827
|
+
component.isSQL = true;
|
|
828
|
+
component.code = 'SELECT * FROM users;';
|
|
829
|
+
component.currentLanguage = 'sql';
|
|
830
|
+
|
|
831
|
+
component['submitCode']();
|
|
832
|
+
|
|
833
|
+
expect(component.submissionStateChanged.emit).toHaveBeenCalledWith({
|
|
834
|
+
text: 'SELECT * FROM users;',
|
|
835
|
+
language: ProgrammingLanguageVersioned.SQLite,
|
|
836
|
+
});
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
it('should emit submission without language when no language is selected', () => {
|
|
840
|
+
component.code = 'test code';
|
|
841
|
+
component.currentLanguage = undefined;
|
|
842
|
+
|
|
843
|
+
component['submitCode']();
|
|
844
|
+
|
|
845
|
+
expect(component.submissionStateChanged.emit).toHaveBeenCalledWith({
|
|
846
|
+
text: 'test code',
|
|
847
|
+
language: undefined,
|
|
848
|
+
});
|
|
849
|
+
});
|
|
850
|
+
|
|
851
|
+
it('should not emit when code is empty', () => {
|
|
852
|
+
component.code = '';
|
|
853
|
+
component.currentLanguage = 'javascript';
|
|
854
|
+
|
|
855
|
+
component['submitCode']();
|
|
856
|
+
|
|
857
|
+
expect(component.submissionStateChanged.emit).not.toHaveBeenCalled();
|
|
858
|
+
});
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
describe('language initialization', () => {
|
|
862
|
+
it('should set currentLanguage when setSqlLang is called', () => {
|
|
863
|
+
component.question = {
|
|
864
|
+
...mockQuestion,
|
|
865
|
+
context: { ...mockQuestion.context, code_language: 'sql' }
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
component['setSqlLang']();
|
|
869
|
+
|
|
870
|
+
expect(component.currentLanguage).toBe('sql');
|
|
871
|
+
});
|
|
872
|
+
|
|
873
|
+
it('should set currentLanguage when listenLanguageChange receives a language', () => {
|
|
874
|
+
const languageSubject = new Subject<CodeEditorLanguages>();
|
|
875
|
+
libCodingTestServiceMock.currentLanguage$ = languageSubject.asObservable();
|
|
876
|
+
|
|
877
|
+
component['listenLanguageChange']();
|
|
878
|
+
languageSubject.next(CodeEditorLanguages.Python);
|
|
879
|
+
|
|
880
|
+
expect(component.currentLanguage).toBe('python');
|
|
881
|
+
});
|
|
882
|
+
});
|
|
883
|
+
});
|