Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Verhoelen committed Jan 14, 2020
1 parent d331574 commit fbfa960
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 123 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
"prettier:write": "prettier --write {src,test,mocks}/**/*.{ts,tsx,js,jsx}",
"lint": "tslint '{src,test,mocks}/**/*.{ts,tsx,js,jsx}' --project ./tsconfig.json",
"lint:fix": "tslint '{src,test,mocks}/**/*.{ts,tsx}' --project ./tsconfig.json --fix",
"test": "jest '(\\/test\\/).*'",
"test:integration": "jest '(\\/test\\/integration/).*'",
"test": "npm run test:unit",
"test:unit": "jest --testRegex '\\.test\\.tsx?$'",
"test:unit:watch": "jest --testRegex '\\.test\\.tsx?$' --watch",
"test:integration": "jest --testRegex '\\.itest\\.ts$'",
"release:check": "npm run lint && npm test",
"release": "npm run release:check && npm run build && electron-builder --publish onTag",
"postinstall": "electron-builder install-app-deps"
Expand All @@ -27,7 +29,7 @@
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/test/.+\\.spec)\\.tsx?$",
"testRegex": "\\.?test\\.tsx?$",
"moduleFileExtensions": [
"ts",
"tsx",
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/explorer-app/ExplorerApplication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default class ExplorerApplication extends React.Component<{}, ExplorerApp
const { secretNames, tree: previousTree } = this.state

const filteredSecretNames = SecretsFilterService.filterBySearch(secretNames, searchValue)
const tree: Tree = SecretsDirectoryService.secretPathsToTree(filteredSecretNames, previousTree)
const tree: Tree = SecretsDirectoryService.secretPathsToTree(filteredSecretNames, previousTree, filteredSecretNames.length <= 15)
this.setState({ ...this.state, tree })
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Tree } from '../../components/tree/TreeComponent'

export default class SecretsDirectoryService {
public static secretPathsToTree(secretPaths: string[], previousTree: Tree): Tree {
public static secretPathsToTree(secretPaths: string[], previousTree: Tree, openAllEntries: boolean): Tree {
const directory = SecretsDirectoryService.secretPathsToDirectory(secretPaths)
return SecretsDirectoryService.directoryToTree(directory, previousTree, secretPaths.length)
return SecretsDirectoryService.directoryToTree(directory, previousTree, openAllEntries)
}

/**
Expand Down Expand Up @@ -48,8 +48,7 @@ export default class SecretsDirectoryService {
* from: "{ xyz: { service: { someServiceName: { db: { password: {} } } } } }"
* to Tree interface
*/
private static directoryToTree(directory: any, previousTree: Tree, totalEntries: number): Tree {
const openAllEntries = totalEntries <= 15
private static directoryToTree(directory: any, previousTree: Tree, openAllEntries: boolean): Tree {
const toggledPaths = SecretsDirectoryService.getToggledPathsFromTree(previousTree)
const children = SecretsDirectoryService.getChildren(directory, toggledPaths, true, openAllEntries)
const tree: Tree = {
Expand Down
95 changes: 0 additions & 95 deletions test/SecretsDirectoryService.spec.ts

This file was deleted.

55 changes: 55 additions & 0 deletions test/SecretsDirectoryService.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Tree } from '../src/renderer/components/tree/TreeComponent'
import SecretsDirectoryService from '../src/renderer/explorer-app/side-navigation/SecretsDirectoryService'

describe('SecretsDirectoryService', () => {
it('should transform a list of secret names into tree structure', () => {
const secretPaths = [
'codecentric/common/github/password',
'codecentric/common/github/username',
'codecentric/common/gitlab/password',
'codecentric/common/gitlab/username',
'codecentric/customers/some/notes'
]
const tree: Tree = SecretsDirectoryService.secretPathsToTree(secretPaths, { name: 'someName', path: '' }, false)
expect(tree).toMatchSnapshot()
})

it('should automatically toggle all nodes', () => {
const secretPaths = [
'codecentric/some-secret',
'codecentric/common/something',
'codecentric/common/another-thing',
'codecentric/db/user',
'codecentric/db/password'
]
const tree: Tree = SecretsDirectoryService.secretPathsToTree(secretPaths, { name: 'someName', path: '' }, true)
expect(tree).toMatchSnapshot()
})

it('should preserve previously toggled nodes when building a new tree', () => {
const secretPaths = [
'codecentric/some-secret',
'codecentric/common/something',
'codecentric/common/another-thing',
'codecentric/db/user',
'codecentric/db/password'
]
const tree: Tree = SecretsDirectoryService.secretPathsToTree(
secretPaths,
{
name: '',
path: '',
children: [
{
name: 'codecentric',
path: 'codecentric',
toggled: true,
children: [{ name: 'some-secret', path: 'codecentric/some-secret' }, { name: 'common', path: 'codecentric/common', toggled: true }]
}
]
},
false
)
expect(tree).toMatchSnapshot()
})
})
File renamed without changes.
Loading

0 comments on commit fbfa960

Please sign in to comment.