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

Revamp Copy Pull Command #21155

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
</div>
</clr-main-container>
<account-settings-modal></account-settings-modal>
<preference-settings></preference-settings>
<password-setting></password-setting>
<global-confirmation-dialog></global-confirmation-dialog>
<about-dialog></about-dialog>
140 changes: 82 additions & 58 deletions src/portal/src/app/base/harbor-shell/harbor-shell.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,77 +18,88 @@ import { SkinableConfig } from '../../services/skinable-config.service';
import { AppConfigService } from '../../services/app-config.service';
import { ErrorHandler } from '../../shared/units/error-handler';
import { AccountSettingsModalComponent } from '../account-settings/account-settings-modal.component';
import { PreferenceSettingsComponent } from '../preference-settings/preference-settings.component';
import { InlineAlertComponent } from '../../shared/components/inline-alert/inline-alert.component';
import { ScannerService } from '../../../../ng-swagger-gen/services/scanner.service';
import { UserService } from '../../../../ng-swagger-gen/services/user.service';

// Mocks
const fakeSessionService = {
getCurrentUser: function () {
return { has_admin_role: true };
},
};

const fakeSearchTriggerService = {
searchTriggerChan$: of('null'),
searchCloseChan$: of(null),
};

const mockMessageHandlerService = null;

const mockPasswordSettingService = null;

const mockSkinableConfig = {
getSkinConfig: function () {
return {
headerBgColor: {
darkMode: '',
lightMode: '',
},
loginBgImg: '',
loginTitle: '',
product: {
name: '',
logo: '',
introduction: '',
},
};
},
};

const fakeAppConfigService = {
isLdapMode: function () {
return true;
},
isHttpAuthMode: function () {
return false;
},
isOidcMode: function () {
return false;
},
getConfig: function () {
return {
with_trivy: true,
};
},
};

const fakedUserService = {
getCurrentUserInfo() {
return of({});
},
setCliSecret() {
return of(null);
},
};

describe('HarborShellComponent', () => {
let component: HarborShellComponent;
let fixture: ComponentFixture<HarborShellComponent>;
let fakeSessionService = {
getCurrentUser: function () {
return { has_admin_role: true };
},
};
let fakeSearchTriggerService = {
searchTriggerChan$: of('null'),
searchCloseChan$: of(null),
};
let mockMessageHandlerService = null;
let mockPasswordSettingService = null;
let mockSkinableConfig = {
getSkinConfig: function () {
return {
headerBgColor: {
darkMode: '',
lightMode: '',
},
loginBgImg: '',
loginTitle: '',
product: {
name: '',
logo: '',
introduction: '',
},
};
},
};
let fakeAppConfigService = {
isLdapMode: function () {
return true;
},
isHttpAuthMode: function () {
return false;
},
isOidcMode: function () {
return false;
},
getConfig: function () {
return {
with_trivy: true,
};
},
};
const fakedUserService = {
getCurrentUserInfo() {
return of({});
},
setCliSecret() {
return of(null);
},
};

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
RouterTestingModule,
TranslateModule.forRoot(),
TranslateModule.forRoot(), // Ensure TranslateModule is imported
ClarityModule,
BrowserAnimationsModule,
FormsModule,
],
declarations: [
HarborShellComponent,
AccountSettingsModalComponent,
PreferenceSettingsComponent,
PasswordSettingComponent,
AboutDialogComponent,
InlineAlertComponent,
Expand All @@ -105,10 +116,7 @@ describe('HarborShellComponent', () => {
provide: MessageHandlerService,
useValue: mockMessageHandlerService,
},
{
provide: UserService,
useValue: fakedUserService,
},
{ provide: UserService, useValue: fakedUserService },
{
provide: PasswordSettingService,
useValue: mockPasswordSettingService,
Expand All @@ -128,6 +136,9 @@ describe('HarborShellComponent', () => {
).componentInstance;
component.accountSettingsModal.inlineAlert =
TestBed.createComponent(InlineAlertComponent).componentInstance;
component.prefSetting = TestBed.createComponent(
PreferenceSettingsComponent
).componentInstance;
component.pwdSetting = TestBed.createComponent(
PasswordSettingComponent
).componentInstance;
Expand All @@ -139,6 +150,7 @@ describe('HarborShellComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

it('should open users profile', async () => {
component.openModal({
modalName: modalEvents.USER_PROFILE,
Expand All @@ -149,7 +161,18 @@ describe('HarborShellComponent', () => {
fixture.nativeElement.querySelector('#account_settings_username');
expect(accountSettingsUsernameInput).toBeTruthy();
});
it('should open users changPwd', async () => {

it('should open users preferences', async () => {
component.openModal({
modalName: modalEvents.PREFERENCES,
modalFlag: false,
});
await fixture.whenStable();
const dropdowns = fixture.nativeElement.querySelector('.dropdowns');
expect(dropdowns).toBeTruthy();
});

it('should open users changePwd', async () => {
component.openModal({
modalName: modalEvents.CHANGE_PWD,
modalFlag: false,
Expand All @@ -159,6 +182,7 @@ describe('HarborShellComponent', () => {
fixture.nativeElement.querySelector('#oldPassword');
expect(oldPasswordInput).toBeTruthy();
});

it('should open users about-dialog', async () => {
component.openModal({ modalName: modalEvents.ABOUT, modalFlag: false });
await fixture.whenStable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { THEME_ARRAY, ThemeInterface } from '../../services/theme';
import { clone } from '../../shared/units/utils';
import { ThemeService } from '../../services/theme.service';
import { AccountSettingsModalComponent } from '../account-settings/account-settings-modal.component';
import { PreferenceSettingsComponent } from '../preference-settings/preference-settings.component';
import {
EventService,
HarborEvent,
Expand All @@ -53,6 +54,9 @@ export class HarborShellComponent implements OnInit, OnDestroy {
@ViewChild(AccountSettingsModalComponent)
accountSettingsModal: AccountSettingsModalComponent;

@ViewChild(PreferenceSettingsComponent)
prefSetting: PreferenceSettingsComponent;

@ViewChild(PasswordSettingComponent)
pwdSetting: PasswordSettingComponent;

Expand Down Expand Up @@ -176,6 +180,9 @@ export class HarborShellComponent implements OnInit, OnDestroy {
case modalEvents.USER_PROFILE:
this.accountSettingsModal.open();
break;
case modalEvents.PREFERENCES:
this.prefSetting.open();
break;
case modalEvents.CHANGE_PWD:
this.pwdSetting.open();
break;
Expand Down
1 change: 1 addition & 0 deletions src/portal/src/app/base/modal-events.const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.
export const modalEvents = {
USER_PROFILE: 'USER_PROFILE',
PREFERENCES: 'PREFERENCES',
CHANGE_PWD: 'CHANGE_PWD',
ABOUT: 'ABOUT',
};
Loading
Loading