Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Merge requests
!1080
Fix front-end tests + refactoring
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Fix front-end tests + refactoring
TMSS-2516
into
master
Overview
14
Commits
30
Pipelines
0
Changes
15
All threads resolved!
Hide all comments
Merged
Fanna Lautenbach
requested to merge
TMSS-2516
into
master
1 year ago
Overview
14
Commits
30
Pipelines
0
Changes
2
All threads resolved!
Hide all comments
Expand
General:
remove unused test system docker-compose
update package.json with new test packages and updated react-tooltip
include new test packages in setupTests.js
update gitlab ci/cd pipeline
update readme
Test fixing:
update mocked template schemas with production versions
remove outdated test data mock + functionality to retrieve it
remove test console errors for react v17-v18 with mock spy in testHelper.js
create generic test helper functions
refactor create.test for Scheduling
fix found bugs in create for Scheduling via (unit tested) create.helper
format create for Scheduling
Edited
1 year ago
by
Fanna Lautenbach
0
0
Merge request reports
Compare
version 1
version 4
b56b616a
1 year ago
version 3
a3bd4e8d
1 year ago
version 2
610b1a4d
1 year ago
version 1
4a3a0c58
1 year ago
master (base)
and
version 2
latest version
0b39b4b6
30 commits,
1 year ago
version 4
b56b616a
27 commits,
1 year ago
version 3
a3bd4e8d
26 commits,
1 year ago
version 2
610b1a4d
24 commits,
1 year ago
version 1
4a3a0c58
23 commits,
1 year ago
Show latest version
2 files
+
0
−
418
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
SAS/TMSS/frontend/tmss_webapp/src/createTemplateSchemaMockFiles.test.js deleted
100644 → 0
+
0
−
174
Options
import
React
from
"
react
"
;
import
{
exportedForTesting
}
from
"
../createTemplateSchemaMockFiles
"
const
fs
=
require
(
'
fs
'
).
promises
;
const
path
=
require
(
'
path
'
);
let
replace
=
require
(
'
replace-in-file
'
);
describe
(
'
copyJsonFiles
'
,
()
=>
{
let
mockedCopyFile
;
const
sourceDir
=
'
/path/to/dir/
'
;
const
targetDir
=
'
/target/
'
;
const
fileOne
=
'
wolverine.json
'
;
const
fileTwo
=
'
cyclops.json
'
;
beforeEach
(()
=>
{
jest
.
clearAllMocks
();
mockedCopyFile
=
jest
.
fn
().
mockResolvedValue
();
fs
.
mkdir
=
jest
.
fn
();
fs
.
copyFile
=
mockedCopyFile
;
});
test
(
'
handle an empty directory
'
,
async
()
=>
{
const
mockedReaddir
=
jest
.
fn
().
mockResolvedValue
([]);
fs
.
readdir
=
mockedReaddir
;
fs
.
lstat
=
jest
.
fn
();
const
results
=
await
exportedForTesting
.
copyJsonFiles
(
sourceDir
,
targetDir
);
expect
(
mockedReaddir
).
toHaveBeenCalledTimes
(
1
);
expect
(
mockedReaddir
).
toHaveBeenCalledWith
(
sourceDir
);
expect
(
fs
.
lstat
).
not
.
toHaveBeenCalled
();
expect
(
mockedCopyFile
).
not
.
toHaveBeenCalled
();
expect
(
results
).
toEqual
([])
});
test
(
'
handle file paths only with .json extension
'
,
async
()
=>
{
let
files
=
[
fileOne
,
'
simba.txt
'
,
fileTwo
];
const
mockedReaddir
=
jest
.
fn
().
mockResolvedValue
(
files
);
const
mockedLstat
=
jest
.
fn
().
mockResolvedValue
({
isDirectory
:
()
=>
false
});
fs
.
readdir
=
mockedReaddir
;
fs
.
lstat
=
mockedLstat
;
const
results
=
await
exportedForTesting
.
copyJsonFiles
(
sourceDir
,
targetDir
);
expect
(
mockedReaddir
).
toHaveBeenCalledTimes
(
1
);
expect
(
mockedReaddir
).
toHaveBeenCalledWith
(
sourceDir
);
expect
(
mockedLstat
).
toHaveBeenCalledTimes
(
files
.
length
);
files
.
map
(
file
=>
sourceDir
+
file
).
forEach
(
filePath
=>
{
expect
(
mockedLstat
).
toHaveBeenCalledWith
(
filePath
);
});
expect
(
mockedCopyFile
).
toHaveBeenCalledTimes
(
2
);
const
targetFileOne
=
path
.
join
(
targetDir
,
files
[
0
]);
expect
(
mockedCopyFile
).
toHaveBeenCalledWith
(
path
.
join
(
sourceDir
,
files
[
0
]),
targetFileOne
);
const
targetFileTwo
=
path
.
join
(
targetDir
,
files
[
2
]);
expect
(
mockedCopyFile
).
toHaveBeenCalledWith
(
path
.
join
(
sourceDir
,
files
[
2
]),
targetFileTwo
);
expect
(
results
).
toEqual
([
targetFileOne
,
targetFileTwo
])
});
test
(
'
handles nested directories correctly
'
,
async
()
=>
{
const
subDir
=
'
x-men
'
;
const
mockedReaddir
=
jest
.
fn
()
.
mockResolvedValueOnce
([
fileOne
,
subDir
])
.
mockResolvedValueOnce
([
fileTwo
])
.
mockResolvedValueOnce
([]);
const
mockedLstat
=
jest
.
fn
()
.
mockResolvedValueOnce
({
isDirectory
:
()
=>
false
})
.
mockResolvedValueOnce
({
isDirectory
:
()
=>
true
})
.
mockResolvedValueOnce
({
isDirectory
:
()
=>
false
});
fs
.
readdir
=
mockedReaddir
;
fs
.
lstat
=
mockedLstat
;
const
results
=
await
exportedForTesting
.
copyJsonFiles
(
sourceDir
,
targetDir
);
expect
(
mockedReaddir
).
toHaveBeenCalledTimes
(
2
);
expect
(
mockedLstat
).
toHaveBeenCalledTimes
(
3
);
expect
(
mockedCopyFile
).
toHaveBeenCalledTimes
(
2
);
const
targetFileOne
=
path
.
join
(
targetDir
,
fileOne
);
const
targetFileTwo
=
path
.
join
(
targetDir
,
subDir
,
fileTwo
);
expect
(
mockedCopyFile
).
toHaveBeenCalledWith
(
path
.
join
(
sourceDir
,
fileOne
),
targetFileOne
);
expect
(
mockedCopyFile
).
toHaveBeenCalledWith
(
path
.
join
(
sourceDir
,
subDir
,
fileTwo
),
targetFileTwo
);
expect
(
results
).
toEqual
([
targetFileOne
,
targetFileTwo
])
});
});
describe
(
'
replaceInFile; not testing actual package, only wrapper method
'
,
()
=>
{
beforeAll
(()
=>
{
// Mock console.error to prevent actual log
jest
.
spyOn
(
console
,
'
error
'
).
mockImplementation
(()
=>
{
});
});
afterAll
(()
=>
{
console
.
error
.
mockRestore
();
});
test
(
'
successfully replaces text in files
'
,
async
()
=>
{
let
fileOneNested
=
'
/x-men/wolverine.json
'
;
let
fileTwo
=
'
cyclops.json
'
;
let
mockInput
=
[{
filePath
:
fileOneNested
,
hasChanged
:
true
},
{
filePath
:
fileTwo
,
hasChanged
:
true
}];
const
mockReplaceInFile
=
jest
.
fn
().
mockResolvedValueOnce
(
mockInput
);
replace
.
replaceInFile
=
mockReplaceInFile
const
files
=
[
fileOneNested
,
fileTwo
];
const
fromRegEx
=
/oldText/g
;
const
to
=
'
newText
'
;
const
result
=
await
exportedForTesting
.
replaceInFile
(
files
,
fromRegEx
,
to
);
expect
(
result
).
toEqual
(
mockInput
);
expect
(
mockReplaceInFile
).
toHaveBeenCalledTimes
(
1
);
expect
(
mockReplaceInFile
).
toHaveBeenCalledWith
({
files
:
files
,
from
:
fromRegEx
,
to
:
to
});
});
test
(
'
throws error and logs it if replace fails
'
,
async
()
=>
{
const
failMsg
=
'
X-men heroes failed
'
;
replace
.
replaceInFile
=
jest
.
fn
().
mockRejectedValueOnce
(
new
Error
(
failMsg
))
const
files
=
[
'
wolverine.json
'
,
'
cyclops.json
'
];
const
fromRegEx
=
/oldText/g
;
const
to
=
'
newText
'
;
let
result
=
exportedForTesting
.
replaceInFile
(
files
,
fromRegEx
,
to
);
await
expect
(
result
).
rejects
.
toThrow
(
failMsg
);
expect
(
console
.
error
).
toHaveBeenCalledWith
(
'
Error occurred:
'
,
expect
.
any
(
Error
));
});
});
describe
(
"
Add JSON elements to template schemas
"
,
()
=>
{
const
jsonString
=
'
{"name": "Wolverine", "age": 30, "type": "hero", "weapons": []}
'
;
test
(
"
adds non extracted data
"
,
()
=>
{
const
testJson
=
JSON
.
parse
(
jsonString
)
const
toAddOrUpdate
=
new
Map
([[
'
id
'
,
1
],
[
'
weapons
'
,
[
'
claws
'
,
'
guns
'
]]]);
const
resultJson
=
exportedForTesting
.
updateJSONSchema
(
testJson
,
toAddOrUpdate
)
const
expectedJson
=
JSON
.
parse
(
'
{"name": "Wolverine", "age": 30, "type": "hero", "id": 1, "weapons": ["claws", "guns"]}
'
)
expect
(
resultJson
).
toEqual
(
expectedJson
)
});
test
(
"
adds extracted data successfully
"
,
()
=>
{
const
testJson
=
JSON
.
parse
(
jsonString
)
const
toAddOrUpdate
=
new
Map
([[
'
weapons
'
,
'
weapons
'
]]);
const
testExtractionJson
=
JSON
.
parse
(
'
{"weapons": ["claws", "guns"]}
'
)
const
resultJson
=
exportedForTesting
.
updateJSONSchema
(
testJson
,
toAddOrUpdate
,
true
,
testExtractionJson
)
const
expectedJson
=
JSON
.
parse
(
'
{"name": "Wolverine", "age": 30, "type": "hero", "weapons": ["claws", "guns"]}
'
)
expect
(
resultJson
).
toEqual
(
expectedJson
)
});
test
(
"
adds nested extracted data successfully
"
,
()
=>
{
const
testJson
=
JSON
.
parse
(
jsonString
)
const
toAddOrUpdate
=
new
Map
([[
'
weapons
'
,
'
weapons
'
]]);
const
testExtractionJson
=
JSON
.
parse
(
'
{"weapons": {"natural" : ["claws"], "machines": ["guns", "bazooka"]}}
'
)
const
resultJson
=
exportedForTesting
.
updateJSONSchema
(
testJson
,
toAddOrUpdate
,
true
,
testExtractionJson
)
const
expectedJson
=
JSON
.
parse
(
'
{"name": "Wolverine", "age": 30, "type": "hero", "weapons": {"natural" : ["claws"], "machines": ["guns", "bazooka"]}}
'
)
expect
(
resultJson
).
toEqual
(
expectedJson
)
});
test
(
"
does not add extracted data when key is missing in extracted json
"
,
()
=>
{
const
testJson
=
JSON
.
parse
(
jsonString
)
const
toAddOrUpdate
=
new
Map
([[
'
weapons
'
,
'
does-not-exist
'
]]);
const
testExtractionJson
=
JSON
.
parse
(
'
{"weapons": ["claws", "guns"]}
'
)
const
resultJson
=
exportedForTesting
.
updateJSONSchema
(
testJson
,
toAddOrUpdate
,
true
,
testExtractionJson
)
expect
(
resultJson
).
toEqual
(
testJson
)
});
});
\ No newline at end of file
Loading