Skip to content

Commit 3496704

Browse files
authored
Merge pull request #303 from topcoder-platform/fix/GAME-108
Fix/game 108
2 parents fd20e71 + e8b5069 commit 3496704

File tree

51 files changed

+1159
-451
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1159
-451
lines changed

.circleci/config.yml

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ deploy_defaults: &deploy_defaults
88
docker:
99
- image: cimg/python:3.10.2
1010

11+
test_defaults: &test_defaults
12+
docker:
13+
- image: cypress/browsers:node16.14.2-slim-chrome100-ff99-edge
14+
1115
install_build_dependency: &install_build_dependency
1216
name: Installation of build and deployment dependencies.
1317
command: |
@@ -50,6 +54,14 @@ running_yarn_build: &running_yarn_build
5054
yarn install
5155
yarn build
5256
57+
running_yarn_test: &running_yarn_test
58+
name: Running Yarn Test Build
59+
command: |
60+
yarn install
61+
yarn cypress install
62+
yarn build
63+
yarn cy:ci
64+
5365
workspace_persist: &workspace_persist
5466
root: .
5567
paths:
@@ -81,6 +93,27 @@ build_steps: &build_steps
8193
- run: *running_yarn_build
8294
- persist_to_workspace: *workspace_persist
8395

96+
test_steps: &test_steps
97+
# Initialization.
98+
- checkout
99+
- setup_remote_docker
100+
- restore_cache:
101+
key: test-node-modules-{{ checksum "yarn.lock" }}
102+
- run: *running_yarn_test
103+
- save_cache:
104+
key: test-node-modules-{{ checksum "yarn.lock" }}
105+
paths:
106+
- node_modules
107+
- /root/.cache/Cypress
108+
- store_test_results:
109+
path: cypress/test-report
110+
- store_artifacts:
111+
path: cypress/test-report
112+
- store_artifacts:
113+
path: cypress/videos
114+
- store_artifacts:
115+
path: cypress/screenshots
116+
84117
deploy_steps: &deploy_steps
85118
- checkout
86119
- attach_workspace: *workspace_attach
@@ -127,6 +160,14 @@ jobs:
127160
LOGICAL_ENV: "prod"
128161
APPNAME: "platform-ui-mvp"
129162
steps: *build_steps
163+
164+
test-dev:
165+
<<: *test_defaults
166+
environment:
167+
DEPLOY_ENV: "DEV"
168+
LOGICAL_ENV: "dev"
169+
APPNAME: "platform-ui-mvp"
170+
steps: *test_steps
130171

131172
# Just tests commited code.
132173
deployDev:
@@ -147,35 +188,6 @@ jobs:
147188
APPNAME: "platform-ui-mvp"
148189
steps: *deploy_steps
149190

150-
# Test job for the cases when we don not need deployment.
151-
e2e-test:
152-
docker:
153-
- image: cypress/browsers:node16.14.2-slim-chrome100-ff99-edge
154-
steps:
155-
- checkout
156-
- restore_cache:
157-
key: test-node-modules-{{ checksum "yarn.lock" }}
158-
- run:
159-
name: Config Git
160-
command: git config --global url."https://git@".insteadOf git://
161-
- run:
162-
name: Install Dependencies
163-
command: yarn install
164-
no_output_timeout: 20m
165-
- run:
166-
name: Install Cypress Binary
167-
command: yarn cypress install
168-
- run:
169-
name: Build the application
170-
command: yarn build
171-
no_output_timeout: 20m
172-
- save_cache:
173-
key: test-node-modules-{{ checksum "yarn.lock" }}
174-
paths:
175-
- node_modules
176-
- /root/.cache/Cypress
177-
- run: yarn cy:ci
178-
179191
workflows:
180192
version: 2
181193
build:
@@ -201,9 +213,6 @@ workflows:
201213
ignore:
202214
- master
203215

204-
- e2e-test:
205-
context : org-global
206-
207216
- build-prod:
208217
context : org-global
209218
filters:
@@ -215,7 +224,6 @@ workflows:
215224
context : org-global
216225
requires:
217226
- build-dev
218-
- e2e-test
219227
filters:
220228
branches:
221229
only:
@@ -229,3 +237,6 @@ workflows:
229237
branches:
230238
only:
231239
- master
240+
241+
- test-dev:
242+
context : org-global

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
# testing
99
/coverage
1010
.nyc_output
11+
/cypress/screenshots
12+
/cypress/videos
13+
/cypress/test-report
1114

1215
# production
1316
/build

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ See the [Dev Center README](/src-ts/tools/dev-center/README.md) for further inst
155155
| `yarn eslint` | Run eslint against js/x files and outputs report |
156156
| `yarn eslint:fix` | Run eslint against js/x files, fixes auto-fixable issues, and outputs report |
157157
| `yarn test` | Run unit tests, watching for changes and re-running per your specifications |
158-
| `yarn test:no-watch` | Run unit tests once, without watching for changes or re-running |
158+
| `yarn test:no-watch` | Run unit tests once, without watching for changes or re-running |
159+
| `yarn cy:run` | Run e2e tests once in local command with the site is running |
160+
| `yarn cy:ci` | Run e2e tests once by circle ci |
161+
| `yarn report:coverage`| Generate e2e coverage report in html format |
162+
| `yarn report:coverage:text` | Generate e2e coverage report in text format |
159163

160164
## Folder Structure
161165

cypress.config.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1+
// tslint:disable-next-line: no-submodule-imports This is the way cypress does it
2+
import task from '@cypress/code-coverage/task'
13
import { defineConfig } from 'cypress'
24

35
export default defineConfig({
4-
fixturesFolder: false,
5-
video: false,
6-
screenshotOnRunFailure: false,
7-
defaultCommandTimeout: 10000,
8-
e2e: {
9-
baseUrl: 'http://localhost:3000',
10-
specPattern: "cypress/e2e/**/*.spec.{js,jsx,ts,tsx}",
11-
supportFile: "cypress/support/e2e.ts",
12-
viewportHeight: 1000,
13-
viewportWidth: 1280,
14-
setupNodeEvents(on, config) {
15-
require('@cypress/code-coverage/task')(on, config)
16-
return config;
6+
defaultCommandTimeout: 10000,
7+
e2e: {
8+
// baseUrl: 'https://local.topcoder-dev.com',
9+
baseUrl: 'http://localhost:3000',
10+
setupNodeEvents: setUpNodeEvents,
11+
specPattern: 'cypress/e2e/**/*.spec.{js,jsx,ts,tsx}',
12+
supportFile: 'cypress/support/e2e.ts',
13+
viewportHeight: 1000,
14+
viewportWidth: 1280,
1715
},
18-
},
16+
fixturesFolder: false,
17+
reporter: 'junit',
18+
reporterOptions: {
19+
mochaFile: 'cypress/test-report/test-result-[hash].xml',
20+
toConsole: false,
21+
},
22+
screenshotOnRunFailure: true,
23+
video: true,
1924
})
25+
26+
// adds the config to node setup events
27+
function setUpNodeEvents(
28+
on: Cypress.PluginEvents,
29+
config: Cypress.PluginConfigOptions
30+
): Cypress.PluginConfigOptions {
31+
task(on, config)
32+
return config
33+
}

cypress/e2e/home/home.spec.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
describe('Landing Page', () => {
2-
beforeEach(() => cy.visit('/'))
3-
it('loads landing page should be successfully', () => {
4-
cy.get('[data-cy="root"]').should('be.visible')
5-
})
2+
3+
beforeEach(() => cy.visit('/'))
4+
5+
it('loads landing page should be successfully', () => {
6+
cy.get('[data-id="root"]').should('be.visible')
7+
})
8+
9+
it.skip('loads landing page should fail', () => {
10+
cy.get('[data-id="root"]').should('not.be.visible')
11+
})
612
})

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,14 @@
1515
"eslint:fix": "eslint 'src/**/*.{js,jsx}' --fix",
1616
"test": "react-scripts test --watchAll",
1717
"test:no-watch": "react-scripts test --watchAll=false --passWithNoTests",
18-
"cy:run": "cypress run",
18+
"cy:run": "cypress run --reporter junit",
1919
"cy:ci": "start-server-and-test 'serve -s build -n -p 3000' http://localhost:3000 'cy:run'",
2020
"report:coverage": "nyc report --reporter=html",
2121
"report:coverage:text": "nyc report --reporter=text"
2222
},
2323
"dependencies": {
2424
"@datadog/browser-logs": "^4.7.1",
2525
"@heroicons/react": "^1.0.6",
26-
"@types/dompurify": "^2.3.3",
27-
"@types/highlightjs": "^9.12.2",
28-
"@types/marked": "4.0.3",
2926
"apexcharts": "^3.35.3",
3027
"axios": "^0.26.1",
3128
"browser-cookies": "^1.2.0",
@@ -83,8 +80,12 @@
8380
"@testing-library/react": "^12.0.0",
8481
"@testing-library/user-event": "^13.2.1",
8582
"@types/axios": "^0.14.0",
83+
"@types/cypress": "^1.1.3",
84+
"@types/dompurify": "^2.3.3",
85+
"@types/highlightjs": "^9.12.2",
8686
"@types/jest": "^27.0.1",
8787
"@types/lodash": "^4.14.182",
88+
"@types/marked": "4.0.3",
8889
"@types/node": "^18.7.13",
8990
"@types/reach__router": "^1.3.10",
9091
"@types/react": "^18.0.5",
@@ -95,6 +96,7 @@
9596
"@types/segment-analytics": "^0.0.34",
9697
"@types/systemjs": "^6.1.0",
9798
"@types/uuid": "^8.3.4",
99+
"@wdio/junit-reporter": "^7.24.0",
98100
"autoprefixer": "^9.8.6",
99101
"babel-eslint": "^11.0.0-beta.2",
100102
"babel-jest": "^24.9.0",

public/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
<body>
3434
<noscript>You need to enable JavaScript to run this app.</noscript>
35-
<div id="root" data-cy="root"></div>
35+
<div id="root" data-id="root"></div>
3636
<!--
3737
This HTML file is a template.
3838
If you open it directly in the browser, you will see an empty page.
@@ -45,4 +45,4 @@
4545
-->
4646
</body>
4747

48-
</html>
48+
</html>

src-ts/declarations.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
declare module '@cypress/code-coverage/task'
2+
13
declare module '*.html' {
24
const htmlFile: string
35
export = htmlFile

src-ts/lib/form/form-functions/form.functions.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ export function initializeValues<T>(inputs: Array<FormInputModel>, formValues?:
3333
inputs
3434
.filter(input => !input.dirty && !input.touched)
3535
.forEach(input => {
36-
input.value = !!(formValues as any)?.hasOwnProperty(input.name)
37-
? (formValues as any)[input.name]
38-
: undefined
36+
if (input.type === 'checkbox') {
37+
input.value = input.checked || false
38+
} else {
39+
input.value = !!(formValues as any)?.hasOwnProperty(input.name)
40+
? (formValues as any)[input.name]
41+
: undefined
42+
}
3943
})
4044
}
4145

@@ -121,7 +125,13 @@ function handleFieldEvent<T>(input: HTMLInputElement | HTMLTextAreaElement, inpu
121125
inputDef.touched = true
122126

123127
// set the def value
124-
inputDef.value = input.value
128+
if (input.type === 'checkbox') {
129+
const checkbox: HTMLInputElement = input as HTMLInputElement
130+
inputDef.value = checkbox.checked
131+
inputDef.checked = checkbox.checked
132+
} else {
133+
inputDef.value = input.value
134+
}
125135

126136
// now let's validate the field
127137
const formElements: HTMLFormControlsCollection = (input.form as HTMLFormElement).elements

src-ts/lib/form/form-groups/FormGroups.tsx

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ const FormGroups: (props: FormGroupsProps) => JSX.Element = (props: FormGroupsPr
2323

2424
const { formDef, onBlur, onChange }: FormGroupsProps = props
2525

26-
const getTabIndex: (input: FormInputModel, index: number) => number = (input, index) => {
26+
function getTabIndex(input: FormInputModel, index: number): number {
2727
const tabIndex: number = input.notTabbable ? -1 : index + 1 + (formDef.tabIndexStart || 0)
2828
return tabIndex
2929
}
3030

31-
const renderInputField: (input: FormInputModel, index: number) => JSX.Element | undefined = (input, index) => {
31+
function renderInputField(input: FormInputModel, index: number): JSX.Element | undefined {
32+
3233
const tabIndex: number = getTabIndex(input, index)
3334

3435
let inputElement: JSX.Element
@@ -40,23 +41,33 @@ const FormGroups: (props: FormGroupsProps) => JSX.Element = (props: FormGroupsPr
4041
{...input}
4142
onChange={onChange}
4243
tabIndex={tabIndex}
43-
value={input.value}
44+
value={input.value as number | undefined}
4445
/>
4546
)
4647
break
47-
4848
case 'textarea':
4949
inputElement = (
5050
<InputTextarea
5151
{...input}
5252
onBlur={onBlur}
5353
onChange={onChange}
5454
tabIndex={tabIndex}
55-
value={input.value}
55+
value={input.value as string | undefined}
5656
/>
5757
)
5858
break
5959
case 'checkbox':
60+
inputElement = (
61+
<InputText
62+
{...input}
63+
checked={!!input.value}
64+
onBlur={onBlur}
65+
onChange={onChange}
66+
tabIndex={tabIndex}
67+
type='checkbox'
68+
/>
69+
)
70+
break
6071
case 'radio':
6172
inputElement = (
6273
<FormRadio
@@ -83,7 +94,7 @@ const FormGroups: (props: FormGroupsProps) => JSX.Element = (props: FormGroupsPr
8394
onChange={onChange}
8495
tabIndex={tabIndex}
8596
type={input.type as InputTextTypes || 'text'}
86-
value={input.value}
97+
value={input.value as string | undefined}
8798
/>
8899
)
89100
break
@@ -100,9 +111,18 @@ const FormGroups: (props: FormGroupsProps) => JSX.Element = (props: FormGroupsPr
100111
)
101112
}
102113

103-
const formGroups: Array<JSX.Element | undefined> = formDef?.groups?.map((element: FormGroup, index: number) => {
104-
return <FormGroupItem key={`element-${index}`} group={element} renderFormInput={renderInputField} totalGroupCount={formDef.groups?.length || 0} />
105-
}) || []
114+
const formGroups: Array<JSX.Element | undefined> = formDef?.groups
115+
?.map((element: FormGroup, index: number) => {
116+
return (
117+
<FormGroupItem
118+
key={`element-${index}`}
119+
group={element}
120+
renderFormInput={renderInputField}
121+
totalGroupCount={formDef.groups?.length || 0}
122+
/>
123+
)
124+
})
125+
|| []
106126

107127
return (
108128
<div className={styles['form-groups']}>

0 commit comments

Comments
 (0)