Fix display of private objects sometimes

This commit is contained in:
shamoon 2023-04-15 21:39:44 -07:00
parent 1771293fcf
commit 0f92523d28
2 changed files with 24 additions and 9 deletions
src-ui
cypress/e2e/settings
src/app/components/common/input/select

@ -56,8 +56,6 @@ describe('settings', () => {
'GET', 'GET',
'http://localhost:8000/api/mail_accounts/*', 'http://localhost:8000/api/mail_accounts/*',
(req) => { (req) => {
console.log(req, this.newMailAccounts)
let response = { ...mailAccountsJson } let response = { ...mailAccountsJson }
if (this.newMailAccounts.length) { if (this.newMailAccounts.length) {
response.results = response.results.concat(this.newMailAccounts) response.results = response.results.concat(this.newMailAccounts)
@ -142,7 +140,7 @@ describe('settings', () => {
cy.get('app-saved-view-widget').contains('Inbox').should('not.exist') cy.get('app-saved-view-widget').contains('Inbox').should('not.exist')
}) })
it('should show a list of mail accounts & rules & support creation', () => { it('should show a list of mail accounts & support creation', () => {
cy.contains('a', 'Mail').click() cy.contains('a', 'Mail').click()
cy.get('app-settings .tab-content ul li').its('length').should('eq', 5) // 2 headers, 2 accounts, 1 rule cy.get('app-settings .tab-content ul li').its('length').should('eq', 5) // 2 headers, 2 accounts, 1 rule
cy.contains('button', 'Add Account').click() cy.contains('button', 'Add Account').click()
@ -162,6 +160,13 @@ describe('settings', () => {
.wait('@getAccounts') .wait('@getAccounts')
cy.contains('Saved account') cy.contains('Saved account')
cy.get('app-settings .tab-content ul li').its('length').should('eq', 6)
})
it('should show a list of mail rules & support creation', () => {
cy.contains('a', 'Mail').click()
cy.get('app-settings .tab-content ul li').its('length').should('eq', 5) // 2 headers, 2 accounts, 1 rule
cy.wait(1000) cy.wait(1000)
cy.contains('button', 'Add Rule').click() cy.contains('button', 'Add Rule').click()
cy.contains('Create new mail rule') cy.contains('Create new mail rule')
@ -177,6 +182,6 @@ describe('settings', () => {
.wait('@getRules') .wait('@getRules')
cy.contains('Saved rule').wait(1000) cy.contains('Saved rule').wait(1000)
cy.get('app-settings .tab-content ul li').its('length').should('eq', 7) cy.get('app-settings .tab-content ul li').its('length').should('eq', 6)
}) })
}) })

@ -27,21 +27,31 @@ export class SelectComponent extends AbstractInputComponent<number> {
} }
_items: any[] _items: any[]
privateItems: any[] = []
@Input() @Input()
set items(items) { set items(items) {
if (this.value && items.find((i) => i.id === this.value) === undefined) { this._items = items
items.push({ if (this.value) this.checkForPrivateItem(this.value)
id: this.value, }
writeValue(newValue: any): void {
if (newValue && this._items) this.checkForPrivateItem(newValue)
super.writeValue(newValue)
}
checkForPrivateItem(value) {
if (this._items.find((i) => i.id === value) === undefined) {
this.privateItems.push({
id: value,
name: $localize`Private`, name: $localize`Private`,
private: true, private: true,
}) })
} }
this._items = items
} }
get items(): any[] { get items(): any[] {
return this._items return this._items?.concat(this.privateItems)
} }
@Input() @Input()