Skip to content

Commit

Permalink
panelAddText/RemoveText properties are not reactive fix #7658 (#7665)
Browse files Browse the repository at this point in the history
* panelAddText/RemoveText/PrevText/NextText properties are not reactive fix #7658

* Add functional tests #7658

* Fix markup tests #7658

* FIx functional test #7658

* Fix knockout template #7658
  • Loading branch information
andrewtelnov authored Jan 15, 2024
1 parent f80747a commit 7ff111e
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<button type="button" *ngIf="question.canAddPanel" [class]="question.getAddButtonCss()" (click)="addPanelClick()">
<span [class]="question.cssClasses.buttonAddText">{{question.panelAddText}}</span>
<span [class]="question.cssClasses.buttonAddText"><sv-ng-string [model]="question.locPanelAddText"></sv-ng-string></span>
</button>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<button type="button" (click)="question.removePanelUI(panel)" [class]="question.getPanelRemoveButtonCss()">
<span [class]="question.cssClasses.buttonRemoveText">{{question.panelRemoveText}}</span>
<span [class]="question.cssClasses.buttonRemoveText"><sv-ng-string [model]="question.locPanelRemoveText"></sv-ng-string></span>
<span [class]="question.cssClasses.iconRemove"></span>
</button>
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
:class="question.getAddButtonCss()"
@click="addPanelClick"
>
<span :class="question.cssClasses.buttonAddText">
{{ question.panelAddText }}
</span>
<span :class="question.cssClasses.buttonAddText"
><survey-string :locString="question.locPanelAddText"
/></span>
</button>
</template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
:class="question.getPanelRemoveButtonCss()"
@click="removePanelClick(panel)"
>
<span :class="question.cssClasses.buttonRemoveText">{{
question.panelRemoveText
}}</span>
<span :class="question.cssClasses.buttonRemoveText"
><survey-string :locString="question.locPanelRemoveText"
/></span>
<span :class="question.cssClasses.iconRemove"></span>
</button>
</template>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- ko if: question.koCanAddPanel -->
<button type="button" data-bind="click: question.koAddPanelClick, css: question.koAddButtonCss, visible: question.koCanAddPanel">
<span data-bind="css: question.cssClasses.buttonAddText, text: question.panelAddText"></span>
<span data-bind="css: question.cssClasses.buttonAddText"><!-- ko template: { name: 'survey-string', data: question.locPanelAddText } --><!-- /ko --></span>
</button>
<!-- /ko -->
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<button type="button" data-bind="click: function() { question.koRemovePanelClick(panel); }, css: question.getPanelRemoveButtonCss()">
<span data-bind="css: question.cssClasses.buttonRemoveText, text: question.panelRemoveText"></span>
<span data-bind="css: question.cssClasses.buttonRemoveText"><!-- ko template: { name: 'survey-string', data: question.locPanelRemoveText } --><!-- /ko --></span>
<span data-bind="css: question.cssClasses.iconRemove"></span>
</button>
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ export class SurveyQuestionPanelDynamicAddButton extends SurveyQuestionPanelDyna
}
protected renderElement(): JSX.Element | null {
if (!this.question.canAddPanel) return null;
const btnText = this.renderLocString(this.question.locPanelAddText);
return (
<button type="button" className={this.question.getAddButtonCss()} onClick={this.handleClick} >
<span className={this.question.cssClasses.buttonAddText}>{this.question.panelAddText}</span>
<span className={this.question.cssClasses.buttonAddText}>{btnText}</span>
</button>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ export class SurveyQuestionPanelDynamicRemoveButton extends SurveyQuestionPanelD
this.question.removePanelUI(this.data.panel);
}
protected renderElement(): JSX.Element {
const btnText = this.renderLocString(this.question.locPanelRemoveText);
return (
<button
className={this.question.getPanelRemoveButtonCss()}
onClick={this.handleClick}
type="button">
<span
className={this.question.cssClasses.buttonRemoveText}
>{this.question.panelRemoveText}</span>
>{btnText}</span>
<span
className={this.question.cssClasses.iconRemove}
></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:class="question.getAddButtonCss()"
@click="addPanelClick"
>
<span :class="question.cssClasses.buttonAddText">{{question.panelAddText}}</span>
<span :class="question.cssClasses.buttonAddText"><survey-string :locString="question.locPanelAddText"></survey-string></span>
</button>
</template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
:class="question.getPanelRemoveButtonCss()"
@click="removePanelClick(panel)"
>
<span :class="question.cssClasses.buttonRemoveText">{{
question.panelRemoveText
}}</span>
<span :class="question.cssClasses.buttonRemoveText"><survey-string :locString="question.locPanelRemoveText"></survey-string></span>
<span :class="question.cssClasses.iconRemove"></span>
</button>
</template>
Expand Down
33 changes: 31 additions & 2 deletions testCafe/questions/paneldynamic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { applyTheme, frameworks, url, url_test, initSurvey, getSurveyResult, getQuestionJson,
getDynamicPanelRemoveButton, getListItemByText, completeButton, setData } from "../helper";
import { Selector } from "testcafe";
import { Selector, ClientFunction } from "testcafe";
const title = "paneldynamic";

const json = {
Expand Down Expand Up @@ -324,7 +324,7 @@ frameworks.forEach((framework) => {
);

test("templateVisibleIf", async (t) => {
const addNewSelector = Selector("span").withText("Add new");
const addNewSelector = Selector("button").withText("Add new");
await t
.expect(addNewSelector.count).eql(1)
.expect(Selector("span").withText("#1-2").visible).notOk()
Expand Down Expand Up @@ -436,4 +436,33 @@ frameworks.forEach((framework) => {
]
});
});
test("Reactive panelAddText/panelRemoveText - #7658", async (t) => {
const changeButtonsText = ClientFunction(
() => {
const q = window["survey"].getQuestionByName("panel1");
q.panelAddText = "#Add#";
q.panelRemoveText = "#Remove#";
}
);
await initSurvey(framework, {
elements: [
{
type: "paneldynamic",
name: "panel1",
panelCount: 2,
renderMode: "tab",
newPanelPosition: "next",
templateElements: [
{
type: "text",
name: "name"
},
],
}
]
});
await changeButtonsText();
await t.expect(Selector("button").withText("#Add#").exists).ok();
await t.expect(Selector("button").withText("#Remove#").exists).ok();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<div class="sv_p_wrapper">
</div>
<button class="sv-paneldynamic__add-btn sv-paneldynamic__add-btn--list-mode" type="button">
<span>Add new</span>
<span><span class="sv-string-viewer">Add new</span></span>
</button>
</div>
2 changes: 1 addition & 1 deletion tests/markup/snapshots/paneldynamic-list.snap.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<div class="sv-action" id="sv-pd-add-btn">
<div class="sv-action__content">
<button class="sd-action sd-paneldynamic__add-btn sd-paneldynamic__add-btn--list-mode sd-paneldynamic__btn" type="button">
<span>Add new</span>
<span><span class="sv-string-viewer">Add new</span></span>
</button>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/markup/snapshots/paneldynamic-no-footer-1.snap.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="sv-action">
<div class="sv-action__content">
<button class="sd-action sd-action--negative sd-paneldynamic__btn sd-paneldynamic__remove-btn" type="button">
<span>Remove</span>
<span><span class="sv-string-viewer">Remove</span></span>
<span class="sd-hidden">
</span>
</button>
Expand Down
2 changes: 1 addition & 1 deletion tests/markup/snapshots/paneldynamic-no-footer-2.snap.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="sv-action">
<div class="sv-action__content">
<button class="sd-action sd-action--negative sd-paneldynamic__btn sd-paneldynamic__remove-btn" type="button">
<span>Remove</span>
<span><span class="sv-string-viewer">Remove</span></span>
<span class="sd-hidden">
</span>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</div>
</div>
<button class="sv-paneldynamic__add-btn" type="button">
<span>Add new</span>
<span><span class="sv-string-viewer">Add new</span></span>
</button>
<div class="sv-paneldynamic__progress-text">1 of 2</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</div>
</div>
<button class="sv-paneldynamic__add-btn" type="button">
<span>Add new</span>
<span><span class="sv-string-viewer">Add new</span></span>
</button>
<div class="sv-paneldynamic__progress-text">1 of 2</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="sv-action" id="remove-panel-testid0panel0">
<div class="sv-action__content">
<button class="sd-action sd-action--negative sd-paneldynamic__btn sd-paneldynamic__remove-btn" type="button">
<span>Remove</span>
<span><span class="sv-string-viewer">Remove</span></span>
<span class="sd-hidden">
</span>
</button>
Expand Down Expand Up @@ -49,7 +49,7 @@
<div class="sv-action" id="sv-pd-add-btn">
<div class="sv-action__content">
<button class="sd-action sd-paneldynamic__add-btn sd-paneldynamic__add-btn--list-mode sd-paneldynamic__btn" type="button">
<span>Add new</span>
<span><span class="sv-string-viewer">Add new</span></span>
</button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div>
</div>
<button class="sd-action sd-action--negative sd-paneldynamic__btn sd-paneldynamic__remove-btn" type="button">
<span>Remove</span>
<span><span class="sv-string-viewer">Remove</span></span>
<span class="sd-hidden">
</span>
</button>
Expand All @@ -43,7 +43,7 @@
<div class="sv-action" id="sv-pd-add-btn">
<div class="sv-action__content">
<button class="sd-action sd-paneldynamic__add-btn sd-paneldynamic__add-btn--list-mode sd-paneldynamic__btn" type="button">
<span>Add new</span>
<span><span class="sv-string-viewer">Add new</span></span>
</button>
</div>
</div>
Expand Down

0 comments on commit 7ff111e

Please sign in to comment.