i have situation where checknotificationObj="true" (i.e _this.noteValue="ture" ) as you can see below.
now how to make that _this.noteValue =false when it enters the if condtion in .ts . this same visiversa for else part
I am new to angular2 help me please
let checkNotifictionObj = _this.noteValue;
if(checkNotifictionObj){
notificationDetails={
notification:"flase"
};
_this.noteValue="false";
}
else{
notificationDetails={
notification:"true"
};
_this.noteValue="true";
}
i am not able to update checkNotifictionObj true to false and false to true
I think you want to do it as below :
let checkNotifictionObj:boolean = _this.noteValue; // _this.noteValue must be of boolean type
if(checkNotifictionObj){
notificationDetails={
notification : false
};
_this.noteValue = false;
} else {
notificationDetails={
notification : true
};
_this.noteValue = true;
}
I guess what you want to do is:
If _this.noteValue is true:
Set
notificationDetails = {
notification : false
}
Set _this.noteValue to false.
If _this.noteValue is false:
Set
notificationDetails = {
notification : true
}
Set _this.noteValue to true.
An easier way to do it would be just:
_this.noteValue = !_this.noteValue; // If _this.noteValue is equal to true, now it will be set to false. If it's false, it will be set to true.
notificationDetails = {
notification: _this.noteValue
};
That way you don't need an if/else.
Related
Created a PCF control, working fine in harnes tool. After integrating to D365 , updateview()not being called. Once I click the developertool then it is working. If am not opening developer tool OR REsize the browser window, then updateview is not being called even though data changed.
Onresetclick am calling notifychanged event , though it is not triggering the updateview
private onResetClick = (newValue: boolean, props: ToggleProps): void => {
if (newValue) {
//isReset true -> clicked set button, action to grey out toggle and change button name to set
if (!this.changeProps.isControlDisabledInForm) {
this._isChanged = true;
this.isReset = this.changeProps.isReset = newValue;
this.changeProps.buttonProperties.checkbox.disabled = true;
this.changeProps.buttonProperties.checkbox.checked = false;
this._selectedOptionID = null;
// this.theNotifyChanged();
}
} else {
if (!this.changeProps.isControlDisabledInForm) {
this._isChanged = true;
this.changeProps.buttonProperties.checkbox.disabled = false;
this.isReset = this.changeProps.isReset = newValue;
this._selectedOptionID
= this.changeProps.optionsetValues.nokey;
// this.theNotifyChanged();
}
}
if (this.theNotifyChanged) {
this.theNotifyChanged();
}
};
/**
* Called when any value in the property bag has changed. This includes field values, data-sets, global values such as container height and width, offline status, control metadata values such as label, visible, etc.
* #param context The entire property bag availabel to control via Context Object; It contains values as set up by the customizer mapped to names defined in the manifest, as well as utility functions
*/
public updateView(context: ComponentFramework.Context<IInputs>): void {
this._context = context;
this.changeProps.isControlDisabledInForm = context.mode.isControlDisabled;
this.changeProps.isVisible = context.mode.isVisible;
this._checkboxID = context.parameters.OptionSetAttribute.attributes?.LogicalName ?? uuidv4();
let selBoolean: boolean = false;
if (!this._isChanged) {
this._selectedOptionID = context.parameters.OptionSetAttribute.raw;
// this.SetButtonProperties(selBoolean);
}
else {
//if (this.changeProps.isReset) {
// // this.changeProps.buttonProperties.checkbox.disabled = true;
// // this.changeProps.buttonProperties.checkbox.checked = false;
//}
//else {
// // this.changeProps.buttonProperties.checkbox.disabled = false;
//}
selBoolean = this.isReset as boolean;//this.changeProps.buttonProperties.checkbox.checked;
}
if (this.optionSetArray) {
for (var i = 0; i < this.optionSetArray.length; i++) {
if (this.optionSetArray[i].Value == this._selectedOptionID) {
this.SelectedOptionSetLabel = this.optionSetArray[i].Label;
}
if (this.optionSetArray[i]?.Label.toUpperCase() === "YES") { //TODO : this needs to be generic not fixed with yes
this.changeProps.optionsetValues.yeskey = this.optionSetArray[i].Value;
} else {
this.changeProps.optionsetValues.nokey = this.optionSetArray[i].Value;
}
}
}
if (!this._isChanged) {
if (this.SelectedOptionSetLabel != null && this.SelectedOptionSetLabel != undefined) {
this.changeProps.buttonProperties.checkbox.checked = this.SelectedOptionSetLabel?.toUpperCase() === "YES" ? true as boolean : false as boolean;//TODO : this needs to be generic not fixed with yes
selBoolean = this.changeProps.isReset = this.isReset = true;
} else {
selBoolean = false;
this.changeProps.isReset = this.isReset = false;
}
}
this._messageContent = selBoolean ? this.changeProps.labels.trueLabel : this.changeProps.labels.falseLabel;
this.changeProps.buttonProperties = {
resetButton: { innerHTML: selBoolean ? "Reset" : "Set" },// when there is a value stored in attribute we need to show Reset
messageContent: this._messageContent,
checkbox: {
disabled: this.changeProps.isControlDisabledInForm ? true : (this.isReset ? false : true),
checked: this.changeProps.buttonProperties.checkbox.checked, checkboxID: this._checkboxID
}
};
console.log("inside ts");
ReactDOM.render(
React.createElement(ToggleButton, this.changeProps
), this.container);
}
Though the context got changed , scope goes to getOutput() method to check if there is any change in output then only PCF view get rerender. In my case, i didnot change the output value in getoutput() method so it was not working.
Here "_selectedOptionID" value should be changed then it started working.
public getOutputs(): IOutputs {
return {
OptionSetAttribute: this._selectedOptionID as number
};
}
How can I run this function, according to the value change of element with if-condition?
assertSwitch(){
cy.get('[data-test="form-switch"]').invoke('attr','value').then(($switchOnOff) =>{
if($switchOnOff == true){
cy.isContain('.item-undefined-switch[data-test="item-undefined-email"]', 'true')
}else{
cy.isContain('.item-undefined-switch[data-test="item-undefined-email"]', 'false')
}
})
}
You can do something like this:
cy.get('[data-test="form-switch"]').then(($ele) => {
if ($ele.attr('val') == 'true') {
cy.get('button[data-test="form-switch-input"]').should(
'have.attr',
'aria-checked',
'true'
)
//Add something here
} else {
cy.get('button[data-test="form-switch-input"]').should(
'have.attr',
'aria-checked',
'false'
)
//Add something here
}
})
The problem is both switches have the same data-test, so Cypress starts to get confused
cy.get('[data-test="form-switch"]')
.eq(0) // pick one
.invoke('attr','aria-checked') // this attr indicates checked state
.then(($switchOnOff) => {
if($switchOnOff === 'true') { // note adjustments here
cy.isContain('.item-undefined-switch[data-test="item-undefined-email"]', 'true')
} else {
cy.isContain('.item-undefined-switch[data-test="item-undefined-email"]', 'false')
}
})
Or all switches
cy.get('[data-test="form-switch"]')
.each(($switchOnOff) => {
const value = $switchOnOff.attr('aria-checked')
cy.isContain('.item-undefined-switch[data-test="item-undefined-email"]', value)
})
I'm trying to check whether the user has accepted the speech recognition or not. But for some reason the status is .authorized but the according variable won't be changed. What am I missing here? It's not about to display the message to the user, but just for some error handling use cases.
class ViewModel: ObservableObject {
#Published var requestAuth: Bool = false
init() {
SFSpeechRecognizer.requestAuthorization { (authState) in
DispatchQueue.main.async {
if authState == .authorized {
print("is authorized") // <---- is printed!
self.requestAuth = true
} else {
self.requestAuth = false
}
}
}
if self.requestAuth { // <--- will not be executed - why?
// do something...
}
}
The code inside the requestAuthorization braces ({}) is what's called a callback function. Often times, callback functions don't get executed immediately. In fact, the documentation for that function states:
This method executes asynchronously, returning shortly after you call it
That means that the code that follows will not happen immediately. Similarly, you're using DispatchQueue.main.async inside that callback function, which also acts the same way. The code in the braces will not be called right away, so you can't base anything later in your structure on it having happened.
The solution to this is to call any functions that you need that are based on the authorization status from inside those closures -- like where you have print("is authorized"):
init() {
SFSpeechRecognizer.requestAuthorization { (authState) in
DispatchQueue.main.async {
if authState == .authorized {
print("is authorized") // <---- is printed!
self.requestAuth = true
// do other things based on authorization status
} else {
self.requestAuth = false
}
}
}
//can't rely on having an updated value for self.requestAuth here
}
I wrote a method which returns true if there are folders left in the modal to be added and return false if there are no folders left in the modal to be added to the application
my method in angular/typesrcipt
ifAllFoldersHaveBeenAdded() {
let added = false;
let folderToExclude = find(this.bdDataModel.lenderDefinedFolders, {
name: 'Correspondence' });
let foldersToBeChecked = without(this.bdDataModel.lenderDefinedFolders, folderToExclude);
for (let i = 0; i < foldersToBeChecked.length; i++) {
let folderPresent = find(this.bdDataModel.folders, { name: foldersToBeChecked[i].name });
if (folderPresent) {
added = true;
} else {
added = false;
return added;
}
}
return added;
}
my test...
describe('ifAllFoldersHaveBeenAdded()', () => {
it('returns false if there are folders left in the modal to be added', () => {
let added = false;
$ctrl.bdDataModel.folders;
$ctrl.foldersToBeChecked = [{ name: 'FMS' }, { name: 'Other' }];
$ctrl.folderPresent = { name: 'FMS' };
$ctrl.ifAllFoldersHaveBeenAdded();
added = true;
expect(added).toEqual(true);
});
it('returns true is all folders have been added to the application', () => {
let added = false;
$ctrl.bdDataModel.folders;
$ctrl.foldersToBeChecked = [{ name: 'FMS' }, { name: 'Other' }];
$ctrl.folderPresent = { name: 'LMI' };
$ctrl.ifAllFoldersHaveBeenAdded();
expect(added).toEqual(false);
});
});
Both tests pass but icov coverage report is marking the following lines as uncovered...
find(this.bdDataModel.folders, { name: foldersToBeChecked[i].name });
if (folderPresent) {
added = true;
}
else {
added = false;
return added;
}
please tell what i should add in the test to have a 100% test coverage for this unit test.
thanks in advance
There is so much wrong with your test. First off, you need to get rid of the local added variables completely. Doing something like the following
added = true;
expect(added).toEqual(true);
Is essentially the same as doing expect(true).toBe(true)
Next, the folderPresent and foldersToBeChecked variables are local to the ifAllFoldersHaveBeenAdded function. They are not controller variables. You don't need to set $ctrl.folderPresent or $ctrl.foldersToBeChecked in your test.
You need to define these two variables $ctrl.bdDataModel.lenderDefinedFolders and $ctrl.bdDataModel.folders
Because lenderDefinedFolders is undefined the length of foldersToBeChecked in your function is going to be 0. So the for loop will never execute.
Your test should look something like this:
it('returns false if there are folders left in the modal to be added', () => {
$ctrl.bdDataModel.lenderDefinedFolders = [{ //add lender defined folders here }]
$ctrl.bdDataModel.folders = [{ //add some folders here}]
let added = $ctrl.ifAllFoldersHaveBeenAdded();
expect(added).toEqual(true);
});
The code below gives an error saying:
Uncaught TypeError: undefined is not a function
Can someone help me structure this properly so that I can default a value based on this expression?
,defaultPersonType: function defaultPersonType() {
console.log(this)
var people = this.get("store").all("person").content
,primaryFound = false
,spouseFound = false
,dependantFound = false
,defaultType = "CHILD"
for (var i = 0; i < people.length; i++) {
switch(people.get("personType")) {
case "PRIMARY":
primaryFound = true
break
case "SPOUSE":
spouseFound = true
break
case "UNMARRIED_PARTNER":
spouseFound = true
break
default:
dependantFound = true
break
}
if (!primaryFound) {
defaultType = "PRIMARY"
}
if (!!dependantFound) {
defaultType = "CHILD"
}
if (!spouseFound) {
defaultType = "SPOUSE"
}
}
return DS.attr('string', {defaultValue: function() {return defaultType}})
}
,personType: (function() {
return this.defaultPersonType()
}())
Well, your
this
is wrong in the anonymous function. So, do this:
function() { return this.defaultPersonType(); }.bind(this)())
I think the best place to implement this logic is in the route's model hook.