-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
204 additions
and
8 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,53 @@ | ||
import { buildButtons } from './buttons'; | ||
|
||
describe('buildButtons', () => { | ||
let root: ShadowRoot; | ||
let result: ReturnType<typeof buildButtons>; | ||
|
||
beforeEach(() => { | ||
const element = document.createElement('div'); | ||
root = element.attachShadow({ mode: 'open' }); | ||
result = buildButtons(root); | ||
}); | ||
|
||
test('raw button should bee defined buttons', () => { | ||
expect(result.rawButton).toBeDefined(); | ||
expect(result.rawButton.tagName).toBe('BUTTON'); | ||
}); | ||
|
||
test('formated button should bee defined buttons', () => { | ||
expect(result.formatButton).toBeDefined(); | ||
expect(result.rawButton.tagName).toBe('BUTTON'); | ||
}); | ||
|
||
test('formated should be active by default', () => { | ||
expect(result.formatButton.classList).toContain('active'); | ||
}); | ||
|
||
describe('clicking on raw button', () => { | ||
beforeEach(() => result.rawButton.click()); | ||
|
||
test('should make raw button active', () => { | ||
expect(result.rawButton.classList).toContain('active'); | ||
}); | ||
|
||
test('should make formatted button inactive', () => { | ||
expect(result.formatButton.classList).not.toContain('active'); | ||
}); | ||
}); | ||
|
||
describe('clicking on formated button should make it active', () => { | ||
beforeEach(() => { | ||
result.rawButton.click(); | ||
result.formatButton.click(); | ||
}); | ||
|
||
test('should make formatted button active', () => { | ||
expect(result.formatButton.classList).toContain('active'); | ||
}); | ||
|
||
test('should make raw button inactive', () => { | ||
expect(result.rawButton.classList).not.toContain('active'); | ||
}); | ||
}); | ||
}); |
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,32 @@ | ||
export const buildButtons = (root: ShadowRoot) => { | ||
const container = document.createElement('div'); | ||
container.className = 'button-container'; | ||
const formatButton = document.createElement('button'); | ||
formatButton.textContent = 'Formatted'; | ||
formatButton.classList.add('active'); | ||
|
||
const rawButton = document.createElement('button'); | ||
rawButton.textContent = 'Raw'; | ||
|
||
container.appendChild(formatButton); | ||
container.appendChild(rawButton); | ||
|
||
const buttons = [formatButton, rawButton]; | ||
|
||
container.addEventListener('click', (event) => { | ||
if (event.target instanceof HTMLButtonElement) { | ||
for (const button of buttons) { | ||
if (button === event.target) { | ||
button.classList.add('active'); | ||
continue; | ||
} | ||
|
||
button.classList.remove('active'); | ||
} | ||
} | ||
}); | ||
|
||
root.appendChild(container); | ||
|
||
return { formatButton, rawButton }; | ||
}; |
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,16 @@ | ||
export const buildContainers = (root: ShadowRoot) => { | ||
const rootContainer = document.createElement('div'); | ||
rootContainer.className = 'root-container'; | ||
|
||
const formatContainer = document.createElement('div'); | ||
formatContainer.className = 'formatted-json-container'; | ||
rootContainer.appendChild(formatContainer); | ||
|
||
const rawContainer = document.createElement('div'); | ||
rawContainer.className = 'raw-json-container'; | ||
rootContainer.appendChild(rawContainer); | ||
|
||
root.appendChild(rootContainer); | ||
|
||
return { rootContainer, formatContainer, rawContainer }; | ||
}; |