Skip to content

Commit

Permalink
feat(search.js): add maintenance activated matcher
Browse files Browse the repository at this point in the history
It allows you to filter the applications in the AppSection to display only those that are not under maintenance
  • Loading branch information
cballevre committed Dec 5, 2022
1 parent f1274dd commit 633c7b2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
7 changes: 6 additions & 1 deletion react/AppSections/search.js
Expand Up @@ -27,12 +27,17 @@ const doctypeMatcher = doctype => app => {
}
const pendingUpdateMatcher = () => app => !!app.availableVersion

const underMaintenanceMatcher = isUnderMaintenance => app => {
return (app.maintenance !== undefined) === isUnderMaintenance
}

const searchAttrToMatcher = {
type: typeMatcher,
category: categoryMatcher,
tag: tagMatcher,
doctype: doctypeMatcher,
pendingUpdate: pendingUpdateMatcher
pendingUpdate: pendingUpdateMatcher,
underMaintenance: underMaintenanceMatcher
}

/**
Expand Down
37 changes: 37 additions & 0 deletions react/AppSections/search.spec.js
Expand Up @@ -5,6 +5,20 @@
import { makeMatcherFromSearch } from './search'
import mockApps from '../mocks/apps'

const mockMaintenanceApps = [
{ slug: 'collect' },
{ slug: 'drive' },
{
slug: 'konnectorInMaintenance',
maintenance: {
flag_infra_maintenance: true,
flag_short_maintenance: true,
flag_disallow_manual_exec: true,
messages: []
}
}
]

describe('makeMatcherFromSearch', () => {
it('should filter correctly on type', () => {
const matcher = makeMatcherFromSearch({ type: 'webapp' })
Expand All @@ -31,6 +45,29 @@ describe('makeMatcherFromSearch', () => {
expect(mockApps.filter(matcher)).toMatchSnapshot()
})

it('should filter correctly when under maintenance is false', () => {
const matcher = makeMatcherFromSearch({ underMaintenance: false })
expect(mockMaintenanceApps.filter(matcher)).toStrictEqual([
{ slug: 'collect' },
{ slug: 'drive' }
])
})

it('should filter correctly when under maintenance is true', () => {
const matcher = makeMatcherFromSearch({ underMaintenance: true })
expect(mockMaintenanceApps.filter(matcher)).toStrictEqual([
{
maintenance: {
flag_disallow_manual_exec: true,
flag_infra_maintenance: true,
flag_short_maintenance: true,
messages: []
},
slug: 'konnectorInMaintenance'
}
])
})

it('should handle correctly multi filters', () => {
const matcher = makeMatcherFromSearch({
type: 'konnector',
Expand Down

0 comments on commit 633c7b2

Please sign in to comment.