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

test: checkbox change propagation #6095

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Changes from 1 commit
Commits
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
60 changes: 60 additions & 0 deletions test/specs/issue_replications/checkbox-not-working.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import Editor from '../../../src/editor/model/Editor';
import ComponentWrapper from '../../../src/dom_components/model/ComponentWrapper';

describe('Checkbox Behaviour', () => {
let em: Editor;
let fixtures: HTMLElement;
let cmpRoot: ComponentWrapper;

beforeEach(() => {
em = new Editor({
mediaCondition: 'max-width',
avoidInlineStyle: true,
});
document.body.innerHTML = '<div id="fixtures"></div>';
const { Pages, Components } = em;
Pages.onLoad();
cmpRoot = Components.getWrapper()!;
const View = Components.getType('wrapper')!.view;
const wrapperEl = new View({
model: cmpRoot,
config: { ...cmpRoot.config, em },
});
wrapperEl.render();
fixtures = document.body.querySelector('#fixtures')!;
fixtures.appendChild(wrapperEl.el);
});

afterEach(() => {
em.destroy();
});

test('init checkbox to true then change value and assert changes', () => {
const cmp = cmpRoot.append({
type: 'checkbox',
tagName: 'input',
attributes: { type: 'checkbox', name: 'my-checkbox' },
traits: [
{
type: 'checkbox',
label: 'Checked',
name: 'checked',
value: 'true',
valueTrue: 'true',
valueFalse: 'false',
},
],
})[0];

const input = cmp.getEl() as HTMLInputElement;
expect(cmp.getAttributes().checked).toBe('true');
expect(input?.checked).toBe(true);
expect(input?.getAttribute('checked')).toBe('true');

input.checked = false;

expect(input?.checked).toBe(false);
expect(cmp.getAttributes().checked).toBe('false');
danstarns marked this conversation as resolved.
Show resolved Hide resolved
expect(input?.getAttribute('checked')).toBe('false');
});
});
Loading