-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ConfigProvider) Allow duplicated classes in the body created by C…
…onfigProvider resolves: #5518 Для того чтобы независимые приложения не удаляли класс главного приложений из body при размонтировании мы позволяем каждому приложению на странице добавить свой класс в body с помощью `ConfigProvider`, даже если такой класс в body уже есть. Таким образом при размонтировании приложение будет удалять только свой класс, не нарушая работу остальных приложений. Работа с классами `body` ведётся с помощь `className` а не `classList` (который не допускает дубликатов).
- Loading branch information
Showing
4 changed files
with
155 additions
and
11 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
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,49 @@ | ||
import { addClassNameToElement, removeClassNameFromElement } from './utils'; | ||
|
||
describe('addClassNameToElement', () => { | ||
test('adds className to element', () => { | ||
const div = document.createElement('div'); | ||
addClassNameToElement(div, 'a-class'); | ||
|
||
expect(div.getAttribute('class')).toEqual('a-class'); | ||
|
||
// allows to add duplicated class name | ||
addClassNameToElement(div, 'a-class'); | ||
expect(div.getAttribute('class')).toEqual('a-class a-class'); | ||
|
||
addClassNameToElement(div, 'b-class'); | ||
expect(div.getAttribute('class')).toEqual('a-class a-class b-class'); | ||
}); | ||
}); | ||
|
||
describe('removeClassNameFromElement', () => { | ||
test('removes className from element', () => { | ||
const div = document.createElement('div'); | ||
div.setAttribute('class', 'a-class'); | ||
|
||
removeClassNameFromElement(div, 'a-class'); | ||
expect(div.getAttribute('class')).toEqual(''); | ||
|
||
// allows to remove duplicated class name | ||
div.setAttribute('class', 'a-class b-class a-class'); | ||
|
||
// remove not existing class | ||
removeClassNameFromElement(div, 'unknown-class'); | ||
expect(div.getAttribute('class')).toEqual('a-class b-class a-class'); | ||
|
||
removeClassNameFromElement(div, 'a-class'); | ||
expect(div.getAttribute('class')).toEqual('b-class a-class'); | ||
|
||
// allows to remove duplicated class name | ||
div.setAttribute('class', 'a-class b-class a-class'); | ||
|
||
removeClassNameFromElement(div, 'b-class'); | ||
expect(div.getAttribute('class')).toEqual('a-class a-class'); | ||
|
||
removeClassNameFromElement(div, 'a-class'); | ||
expect(div.getAttribute('class')).toEqual('a-class'); | ||
|
||
removeClassNameFromElement(div, 'a-class'); | ||
expect(div.getAttribute('class')).toEqual(''); | ||
}); | ||
}); |
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