-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add missing conditional classes on app-wrapper and application contai…
…ners
- Loading branch information
1 parent
aeebedf
commit b487fe5
Showing
5 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { BehaviorSubject } from 'rxjs'; | ||
import { act } from 'react-dom/test-utils'; | ||
import { mount } from 'enzyme'; | ||
import React from 'react'; | ||
|
||
import { AppWrapper, AppContainer } from './app_containers'; | ||
|
||
describe('AppWrapper', () => { | ||
it('toggles the `hidden-chrome` class depending on the chrome visibility state', () => { | ||
const chromeVisible$ = new BehaviorSubject<boolean>(true); | ||
|
||
const component = mount(<AppWrapper chromeVisible$={chromeVisible$}>app-content</AppWrapper>); | ||
expect(component.html()).toMatchInlineSnapshot( | ||
`"<div class=\\"app-wrapper\\">app-content</div>"` | ||
); | ||
|
||
act(() => chromeVisible$.next(false)); | ||
component.update(); | ||
expect(component.html()).toMatchInlineSnapshot( | ||
`"<div class=\\"app-wrapper hidden-chrome\\">app-content</div>"` | ||
); | ||
|
||
act(() => chromeVisible$.next(true)); | ||
component.update(); | ||
expect(component.html()).toMatchInlineSnapshot( | ||
`"<div class=\\"app-wrapper\\">app-content</div>"` | ||
); | ||
}); | ||
}); | ||
|
||
describe('AppContainer', () => { | ||
it('adds classes supplied by chrome', () => { | ||
const appClasses$ = new BehaviorSubject<string[]>([]); | ||
|
||
const component = mount(<AppContainer classes$={appClasses$}>app-content</AppContainer>); | ||
expect(component.html()).toMatchInlineSnapshot( | ||
`"<div class=\\"application\\">app-content</div>"` | ||
); | ||
|
||
act(() => appClasses$.next(['classA', 'classB'])); | ||
component.update(); | ||
expect(component.html()).toMatchInlineSnapshot( | ||
`"<div class=\\"application classA classB\\">app-content</div>"` | ||
); | ||
|
||
act(() => appClasses$.next(['classC'])); | ||
component.update(); | ||
expect(component.html()).toMatchInlineSnapshot( | ||
`"<div class=\\"application classC\\">app-content</div>"` | ||
); | ||
|
||
act(() => appClasses$.next([])); | ||
component.update(); | ||
expect(component.html()).toMatchInlineSnapshot( | ||
`"<div class=\\"application\\">app-content</div>"` | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { Observable } from 'rxjs'; | ||
import useObservable from 'react-use/lib/useObservable'; | ||
import cn from 'classnames'; | ||
|
||
export const AppWrapper: React.FunctionComponent<{ | ||
chromeVisible$: Observable<boolean>; | ||
}> = ({ chromeVisible$, children }) => { | ||
const visible = useObservable(chromeVisible$); | ||
return <div className={cn('app-wrapper', { 'hidden-chrome': !visible })}>{children}</div>; | ||
}; | ||
|
||
export const AppContainer: React.FunctionComponent<{ | ||
classes$: Observable<string[]>; | ||
}> = ({ classes$, children }) => { | ||
const classes = useObservable(classes$); | ||
return <div className={cn('application', classes)}>{children}</div>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters