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

Stablization #412

Merged
merged 6 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions Backend/jest-int.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".int-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"moduleNameMapper": {
"src/(.*)": "<rootDir>/src/$1"
}
}
1 change: 1 addition & 0 deletions Backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"test:int": "jest -i --no-cache --watch --config jest-int.json",
"coveralls": "cat coverage/lcov.info | coveralls"
},
"dependencies": {
Expand Down
83 changes: 83 additions & 0 deletions Backend/src/search/test/integration/seach.sevice.int-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { Test, TestingModule } from '@nestjs/testing';
import { SearchService } from '../../services/search.service'; // adjust path as necessary
import { SearchController } from '../../controller/search.controller'; // adjust path as necessary
import { HttpService } from '@nestjs/axios';
import { of } from 'rxjs';
import * as request from 'supertest';
import { INestApplication } from '@nestjs/common';

describe('SearchController Integration Test', () => {
let app: INestApplication;
let service: SearchService;

const mockApiResponse = {
data: {
data: [
{
id: 1,
title: 'Test Song',
album: {
title: 'testName',
cover_big: 'eh'
},
artist: {
name: 'eh'
}
}
]
}
};

const mockHttpService = {
get: jest.fn(),
};

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [SearchController],
providers: [
SearchService, // Include the actual service here
{
provide: HttpService,
useValue: mockHttpService,
},
],
}).compile();

app = module.createNestApplication();
await app.init();

service = module.get<SearchService>(SearchService);
});

afterEach(async () => {
jest.clearAllMocks(); // Clear mocks after each test
await app.close(); // Close the application after each test
});

it('should return songs when searchByTitle is called', async () => {
const title = 'Test Title';

// Mock the HTTP service response
mockHttpService.get.mockReturnValue(of(mockApiResponse));

// Call the controller endpoint
const response = await request(app.getHttpServer())
.post(`/search/search`) // Adjust the URL based on your route setup
.send({ title }); // Assuming you're using query parameters

let expectedServiceResponse = [{
"albumImageUrl": "eh",
"albumName": "testName",
"artistName": "eh",
"name": "Test Song"
}];

// Expect the result to match the mock response
expect(response.status).toBe(201);
expect(response.body).toEqual(expectedServiceResponse);

// Optional: Check that the HTTP service's get method was called with the correct URL
expect(mockHttpService.get).toHaveBeenCalledWith(`${service['deezerApiUrl']}/search?q=${title}`);
});
});
111 changes: 101 additions & 10 deletions Frontend/src/app/components/organisms/navbar/navbar.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { NavbarComponent } from './navbar.component';
import { Router } from '@angular/router';
import { NavigationEnd, Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { ScreenSizeService } from '../../../services/screen-size-service.service';
import { of } from 'rxjs';

describe('NavbarComponent', () => {
let component: NavbarComponent;
let fixture: ComponentFixture<NavbarComponent>;
let router: Router;
let screenSizeService: ScreenSizeService;
let router: any;
let screenSizeService: any;


beforeEach(async () => {
screenSizeService = {
screenSize$: of('large')
};
router = {
events: of(new NavigationEnd(1, '/previousUrl', '/currentUrl')),
navigate: jest.fn()
};

await TestBed.configureTestingModule({
imports: [RouterTestingModule,NavbarComponent],
providers: [ScreenSizeService],
providers: [
{provide: ScreenSizeService, useValue: screenSizeService},
{provide: Router, useValue: router }],
}).compileComponents();

fixture = TestBed.createComponent(NavbarComponent);
component = fixture.componentInstance;
router = TestBed.inject(Router);
screenSizeService = TestBed.inject(ScreenSizeService);
jest.spyOn(component, 'updateSelectedIcon');
fixture.detectChanges();
});

Expand All @@ -31,6 +41,26 @@ describe('NavbarComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

describe('ngOnInit', () => {
it('should subscribe to screenSizeService and set screenSize', fakeAsync(() => {
fixture.detectChanges(); // Triggers ngOnInit

tick();

expect(component.screenSize).toBe('large');
}));

it('should subscribe to router events and call updateSelectedIcon on NavigationEnd', fakeAsync(() => {
jest.spyOn(component, 'updateSelectedIcon');

fixture.detectChanges(); // Triggers ngOnInit

tick();

expect(component.updateSelectedIcon).toHaveBeenCalledWith('/currentUrl');
}));
});
/*
it('should navigate to "/home" when homeSvg is selected', fakeAsync(() => {
jest.spyOn(router, 'navigate').mockImplementation();
Expand All @@ -39,9 +69,70 @@ describe('NavbarComponent', () => {
expect(router.navigate).toHaveBeenCalledWith(['/home']);
}));
*/
it('should emit "Home" when homeSvg is selected', () => {
jest.spyOn(component.selectedNavChange, 'emit').mockImplementation();
component.select(component.homeSvg);
expect(component.selectedNavChange.emit).toHaveBeenCalledWith('Home');
describe('select', () => {
it('should emit "Home" when homeSvg is selected', () => {
jest.spyOn(component.selectedNavChange, 'emit').mockImplementation();
component.select(component.homeSvg);
expect(component.selectedNavChange.emit).toHaveBeenCalledWith('Home');
});
it('should emit "Insight" when insightSvg is selected', () => {
jest.spyOn(component.selectedNavChange, 'emit').mockImplementation();
component.select(component.insightSvg);
expect(component.selectedNavChange.emit).toHaveBeenCalledWith('Insight');
});
it('should emit "Library" when otherSvg2 is selected', () => {
jest.spyOn(component.selectedNavChange, 'emit').mockImplementation();
component.select(component.otherSvg2);
expect(component.selectedNavChange.emit).toHaveBeenCalledWith('Library');
});
});

describe('updateSelectedIcon', () => {
it('should set the svg to home', () => {
let url = "fakeurl/home";

component.updateSelectedIcon(url);

expect(component.selectedSvg).toEqual(component.homeSvg)
});
it('should set the svg to insights', () => {
let url = "fakeurl/insights";

component.updateSelectedIcon(url);

expect(component.selectedSvg).toEqual(component.insightSvg)
});
it('should set the svg to library', () => {
let url = "fakeurl/library";

component.updateSelectedIcon(url);

expect(component.selectedSvg).toEqual(component.otherSvg2)
});
it('should set the svg to default', () => {
let url = "fakeurl/somthingAwesome";

component.updateSelectedIcon(url);

expect(component.selectedSvg).toEqual('');
});
});

describe('getCurrentButtonClass', () => {
it('should return "bg-pink" when the option is selected', () => {
component.currentSelection = 'option1';

const result = component.getCurrentButtonClass('option1');

expect(result).toBe('bg-pink');
});

it('should return "bg-gray-component" when the option is not selected', () => {
component.currentSelection = 'option2';

const result = component.getCurrentButtonClass('option1');

expect(result).toBe('bg-gray-component');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,12 @@ describe('SideBarComponent', () => {
stopPropagation: jest.fn()
};
const mockEchoTracks: TrackInfo[] = [
{ id: '1', imageUrl: 'url1', text: 'Track 1', secondaryText: 'Artist 1', explicit: false, albumName: "name", previewUrl: "url", spotifyUrl: "url" },
{ id: '2', imageUrl: 'url2', text: 'Track 2', secondaryText: 'Artist 2', explicit: true, albumName: "name", previewUrl: "url", spotifyUrl: "url" }
{ id: '1', imageUrl: 'url1', text: 'Track 1',
secondaryText: 'Artist 1', explicit: false,
albumName: "name", previewUrl: "url", spotifyUrl: "url" },
{ id: '2', imageUrl: 'url2', text: 'Track 2',
secondaryText: 'Artist 2', explicit: true,
albumName: "name", previewUrl: "url", spotifyUrl: "url" }
];
mockSearchService.echo.mockResolvedValue(mockEchoTracks);

Expand Down
Loading
Loading