Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement base components #12

Open
wants to merge 57 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
f1f4024
feat: implement tab component (#5)
chessurisme Jun 17, 2024
615bf56
feat : implement button component (#3)
chessurisme Jun 17, 2024
8554ef9
feat: implement snackbar component (#6)
chessurisme Jun 17, 2024
28477e7
feat: implement checkbox component (#9)
chessurisme Jun 17, 2024
08b4ecb
feat: implement modal component (#10)
chessurisme Jun 18, 2024
5bc1237
feat: implement textarea component (#7)
chessurisme Jun 18, 2024
1f519ae
feat: implement page component (#8)
chessurisme Jun 18, 2024
e3489a6
style: expand print width to 100 characters
chessurisme Jun 18, 2024
a1e3a4e
fix: change class_name to class when setting attribute
chessurisme Jun 20, 2024
365b6b0
fix: assign class and class_name correctly
chessurisme Jun 25, 2024
dd71c1a
refactor: simplify header creation logic in page component
chessurisme Jul 1, 2024
a6a6c79
feat: implement container component (#13)
chessurisme Jul 1, 2024
0877d1f
feat: enhance Container component with new features
chessurisme Jul 23, 2024
4b41ad0
test: update Container tests to cover new features
chessurisme Jul 23, 2024
0576395
feat: add 'hidden' attribute to textarea and checkbox components
chessurisme Jul 25, 2024
830a879
fix: explicitly handle hidden attribute
chessurisme Jul 25, 2024
99ac101
fix: remove redundant 'use strict'
chessurisme Jul 29, 2024
753336a
fix: reduce redundancy in mocking console.log
chessurisme Jul 29, 2024
f7fb2af
fix: remove unnecessary .trim()
chessurisme Jul 29, 2024
685d4b5
refactor: remove assignments within expressions
chessurisme Jul 29, 2024
ffbb1be
fix: change TEXTAREA to node
chessurisme Jul 29, 2024
1be23a0
refactor: complete localStorage management test case
chessurisme Jul 29, 2024
59a0b76
fix: remove redundant 'use strict'
chessurisme Jul 29, 2024
b55c98c
refactor: consolidate configuration verification
chessurisme Jul 31, 2024
a5b273d
test: add ConfigVerifier class
chessurisme Jul 31, 2024
18d6f7f
feat: add function to remove event listener
chessurisme Jul 31, 2024
18be26f
test: add remove event listener function
chessurisme Jul 31, 2024
587270b
fix: remove remove-event-listener
chessurisme Jul 31, 2024
2926ba3
refactor: update remove-event-listeners with batch support
chessurisme Jul 31, 2024
d752b54
test: expand test suite for removeEventListeners
chessurisme Jul 31, 2024
60547c8
chore: correct grammatical error
chessurisme Jul 31, 2024
b836f04
refactor: replace hasOwnProperty to Object.hasOwn
chessurisme Jul 31, 2024
c08d9b9
refactor: improve sanitizeValue function for readability
chessurisme Jul 31, 2024
91c6461
refactor: add example in jsdoc
chessurisme Jul 31, 2024
c647804
refactor: enhance function documentation
chessurisme Jul 31, 2024
33a6ef3
refactor: update conditionList for readability
chessurisme Jul 31, 2024
a387b89
test: add more examples in validation pass
chessurisme Jul 31, 2024
77b4832
fix: remove sanitize-value function
chessurisme Jul 31, 2024
c89c1ee
fix: check grammatical errors
chessurisme Aug 1, 2024
8dcdbfb
refactor: separate comprehensive errors
chessurisme Aug 1, 2024
71e766b
feat: implement add-event-listeners
chessurisme Aug 1, 2024
23baef6
test: add add-event-listeners
chessurisme Aug 1, 2024
54856a8
refactor: improve error message
chessurisme Aug 1, 2024
9ea78b8
test: add more edge cases for remove-event-listeners
chessurisme Aug 1, 2024
b137648
refactor: improve error message
chessurisme Aug 1, 2024
0e65af6
feat: add BaseComponent class for utility methods
chessurisme Aug 22, 2024
98bd553
refactor: overhaul Button component
chessurisme Aug 22, 2024
4aec29f
refactor: overhaul Checkbox component
chessurisme Aug 22, 2024
cbac10c
refactor: overhaul Tab component
chessurisme Aug 22, 2024
d0620b6
refactor: overhaul Snackbar component
chessurisme Aug 22, 2024
ff854f5
refactor: overhaul Textarea component
chessurisme Aug 22, 2024
82ec484
refactor: overhaul Modal component
chessurisme Aug 22, 2024
706cc8f
refactor: overhaul Page component
chessurisme Aug 22, 2024
8b18b53
docs: update components JSDoc
chessurisme Aug 22, 2024
8070f18
fix(textarea): add missing type for value sanitization
chessurisme Aug 23, 2024
70c3d2d
fix(textarea): correct tagName to 'textarea' and make text value opti…
chessurisme Aug 23, 2024
37cc401
docs(textarea): update typedef for config
chessurisme Aug 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
290 changes: 290 additions & 0 deletions src/components/__tests__/button.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
import { JSDOM } from 'jsdom'
import { Button } from '@components/button'

const dom = new JSDOM('<!DOCTYPE html>')
global.window = dom.window
global.document = window.document
global.HTMLElement = window.HTMLElement
global.MouseEvent = window.MouseEvent

describe('Button', () => {
beforeEach(() => {
document.body.innerHTML = null
})

describe('Button', () => {
beforeEach(() => {
document.body.innerHTML = null
jest.spyOn(console, 'log').mockImplementation(() => {})
})

describe('create()', () => {
describe('should create a button with a valid configuration', () => {
it('should create a rounded-square type button', () => {
const config = {
icon: 'plus',
id: 'add-quiz',
class_name: 'maker-button',
type: 'rounded-square',
events: [
{
event_name: 'click',
func: () => {
console.log('It worked!')
}
}
]
}

const button = new Button(config)
const button_node = button.create()
document.body.appendChild(button_node)

const element = document.getElementById('button-add-quiz')
element.click()

expect(document.body.innerHTML).not.toHaveLength(0)
expect(button).toBeDefined()
expect(mock_log).toHaveBeenCalledWith('It worked!')
expect(element.id).toBe('button-add-quiz')
expect(element.className).toBe('maker-button button rounded-square-button')
expect(element.querySelector('[data-lucide="plus"]')).not.toBeNull()
})
chessurisme marked this conversation as resolved.
Show resolved Hide resolved

describe('should create a slab type button', () => {
it('should create a button with icon and text', () => {
const mock_log = jest.spyOn(console, 'log').mockImplementation(() => {})

const config = {
icon: 'attachment',
text: 'Import File',
id: 'import-file',
class_name: 'maker-button',
type: 'slab',
events: [
{
event_name: 'click',
func: () => {
console.log('It worked!')
}
}
]
}

const button = new Button(config)
const button_node = button.create()
document.body.appendChild(button_node)

const element = document.getElementById('button-import-file')
element.click()

expect(document.body.innerHTML).not.toHaveLength(0)
expect(button).toBeDefined()
expect(mock_log).toHaveBeenCalledWith('It worked!')
expect(element.id).toBe('button-import-file')
expect(element.className).toBe('maker-button button slab-button')
expect(element.querySelector('[data-lucide="attachment"]')).not.toBeNull()
})

it('should create a button with text only', () => {
const mock_log = jest.spyOn(console, 'log').mockImplementation(() => {})

const config = {
text: 'Import File',
id: 'import-file',
class_name: 'maker-button',
type: 'slab',
events: [
{
event_name: 'click',
func: () => {
console.log('It worked!')
}
}
]
}

const button = new Button(config)
const button_node = button.create()
document.body.appendChild(button_node)

const element = document.getElementById('button-import-file')
element.click()

expect(document.body.innerHTML).not.toHaveLength(0)
expect(button).toBeDefined()
expect(mock_log).toHaveBeenCalledWith('It worked!')
expect(element.id).toBe('button-import-file')
expect(element.className).toBe('maker-button button slab-button')
})

it('should not create a button without icon and text', () => {
const mock_log = jest.spyOn(console, 'log').mockImplementation(() => {})

const config = {
id: 'import-file',
class_name: 'maker-button',
type: 'slab',
events: [
{
event_name: 'click',
func: () => {
console.log('It worked!')
}
}
]
}

const button = new Button(config)
const button_node = button.create()

expect(button_node).toBeFalsy()
})
})

describe('should create a default type button', () => {
it('should create a button with icon and text', () => {
const mock_log = jest.spyOn(console, 'log').mockImplementation(() => {})

const config = {
icon: 'attachment',
text: 'Import File',
id: 'import-file',
class_name: 'maker-button',
events: [
{
event_name: 'click',
func: () => {
console.log('It worked!')
}
}
]
}

const button = new Button(config)
const button_node = button.create()
document.body.appendChild(button_node)

const element = document.getElementById('button-import-file')
element.click()

expect(document.body.innerHTML).not.toHaveLength(0)
expect(button).toBeDefined()
expect(mock_log).toHaveBeenCalledWith('It worked!')
expect(element.id).toBe('button-import-file')
expect(element.className).toBe('maker-button button transparent-button')
expect(element.querySelector('[data-lucide="attachment"]')).not.toBeNull()
})

it('should create a button with text only', () => {
const mock_log = jest.spyOn(console, 'log').mockImplementation(() => {})

const config = {
text: 'Import File',
id: 'import-file',
class_name: 'maker-button',
events: [
{
event_name: 'click',
func: () => {
console.log('It worked!')
}
}
]
}

const button = new Button(config)
const button_node = button.create()
document.body.appendChild(button_node)

const element = document.getElementById('button-import-file')
element.click()

expect(document.body.innerHTML).not.toHaveLength(0)
expect(button).toBeDefined()
expect(mock_log).toHaveBeenCalledWith('It worked!')
expect(element.id).toBe('button-import-file')
expect(element.className).toBe('maker-button button transparent-button')
})

it('should not create a button without icon and text', () => {
const mock_log = jest.spyOn(console, 'log').mockImplementation(() => {})

const config = {
id: 'import-file',
class_name: 'maker-button',
events: [
{
event_name: 'click',
func: () => {
console.log('It worked!')
}
}
]
}

const button = new Button(config)
const button_node = button.create()

expect(button_node).toBeFalsy()
})
})
})
})

describe('remove()', () => {
it('should remove a button with a valid configuration', () => {
const mock_log = jest.spyOn(console, 'log').mockImplementation(() => {})

const config = {
icon: 'plus',
id: 'add-quiz',
class_name: 'maker-button',
type: 'rounded-square',
events: [
{
event_name: 'click',
func: () => {
console.log('It worked!')
}
}
]
}

let button = new Button(config)
document.body.appendChild(button.create())

const element = document.getElementById('button-add-quiz')
element.click()

expect(document.body.innerHTML).not.toHaveLength(0)
expect(button).toBeDefined()
expect(mock_log).toHaveBeenCalledWith('It worked!')
expect(element.id).toBe('button-add-quiz')
expect(element.className).toBe('maker-button button rounded-square-button')
expect(element.querySelector('[data-lucide="plus"]')).not.toBeNull()

button.remove()
button = null

expect(document.body.innerHTML).toHaveLength(0)
expect(button).toBeNull()
})

it('should return gracefully when id is not in configuration', () => {
const config = {}
const button = new Button(config).remove()

expect(button).toBeFalsy()
})

it('should return gracefully when id is not found in the DOM', () => {
const config = {
id: 'add-quiz'
}
const button = new Button(config).remove()

expect(button).toBeFalsy()
})
})
})
Loading