Skip to content

Commit c75c75d

Browse files
committed
Add the setBadgeOffset private method
1 parent abc8320 commit c75c75d

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

src/wproofreader.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export default class WProofreader extends Plugin {
5858
this._userOptions = this._getUserOptions();
5959
this._setTheme();
6060
this._setAutoStartup();
61+
this._setBadgeOffset();
6162
this._setIsEnabled(this._userOptions.autoStartup, DISABLE_INSTANCES_ID);
6263

6364
this._loadWscbundle()
@@ -120,6 +121,26 @@ export default class WProofreader extends Plugin {
120121
}
121122
}
122123

124+
/**
125+
* Checks if the badgeOffsetX/badgeOffsetY and fullSizeBadge options exist otherwise sets values by default.
126+
* @private
127+
*/
128+
_setBadgeOffset() {
129+
const badgeOffset = 11;
130+
131+
if (this._userOptions.fullSizeBadge) {
132+
return;
133+
}
134+
135+
if (!this._userOptions.hasOwnProperty('badgeOffsetX')) {
136+
this._userOptions.badgeOffsetX = badgeOffset;
137+
}
138+
139+
if (!this._userOptions.hasOwnProperty('badgeOffsetY')) {
140+
this._userOptions.badgeOffsetY = badgeOffset;
141+
}
142+
}
143+
123144
/**
124145
* Configures the {@code isEnabled} state of the plugin.
125146
* @private

tests/wproofreader.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,55 @@ describe('WProofreader', () => {
154154
});
155155
})
156156

157+
describe('with badgeOffset options', () => {
158+
it('should set `11` pixels to the badgeOffset options', () => {
159+
return ClassicEditor
160+
.create(element, {
161+
plugins: [WProofreader],
162+
wproofreader: WPROOFREADER_CONFIG
163+
})
164+
.then((editor) => {
165+
const wproofreader = editor.plugins.get('WProofreader');
166+
167+
expect(wproofreader._userOptions.badgeOffsetX).to.be.equal(11);
168+
expect(wproofreader._userOptions.badgeOffsetY).to.be.equal(11);
169+
})
170+
});
171+
172+
it('should set user values to the badgeOffset options', () => {
173+
const badgeOffsetX = 12;
174+
const badgeOffsetY = 13;
175+
176+
return ClassicEditor
177+
.create(element, {
178+
plugins: [WProofreader],
179+
wproofreader: Object.assign({}, WPROOFREADER_CONFIG, { badgeOffsetX, badgeOffsetY })
180+
})
181+
.then((editor) => {
182+
const wproofreader = editor.plugins.get('WProofreader');
183+
184+
expect(wproofreader._userOptions.badgeOffsetX).to.be.equal(badgeOffsetX);
185+
expect(wproofreader._userOptions.badgeOffsetY).to.be.equal(badgeOffsetY);
186+
})
187+
});
188+
})
189+
190+
describe('with fullSizeBadge option', () => {
191+
it('should avoid setting default badgeOffset options', () => {
192+
return ClassicEditor
193+
.create(element, {
194+
plugins: [WProofreader],
195+
wproofreader: Object.assign({}, WPROOFREADER_CONFIG, { fullSizeBadge: true })
196+
})
197+
.then((editor) => {
198+
const wproofreader = editor.plugins.get('WProofreader');
199+
200+
expect(wproofreader._userOptions.badgeOffsetX).to.be.undefined;
201+
expect(wproofreader._userOptions.badgeOffsetY).to.be.undefined;
202+
})
203+
});
204+
})
205+
157206
describe('disable functionality', () => {
158207
it('should enable the plugin and instances because autoStartup option is enabled', () => {
159208
return ClassicEditor

0 commit comments

Comments
 (0)