@mozaic-ds/angular 0.22.0 → 0.23.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +5 -3
  3. package/angular.json +2 -9
  4. package/jest.config.js +6 -0
  5. package/package.json +30 -19
  6. package/projects/kit/components/datatable/components/caption/moz-datatable-caption.component.html +13 -0
  7. package/projects/kit/components/datatable/components/caption/moz-datatable-caption.component.ts +31 -0
  8. package/projects/kit/components/datatable/components/content/moz-datatable-content-cell.component.html +1 -0
  9. package/projects/kit/components/datatable/components/content/moz-datatable-content-cell.component.ts +17 -0
  10. package/projects/kit/components/datatable/components/footer/moz-datatable-footer.component.html +34 -0
  11. package/projects/kit/components/datatable/components/footer/moz-datatable-footer.component.ts +46 -0
  12. package/projects/kit/components/datatable/components/header/moz-datatable-header-cell.component.html +1 -0
  13. package/projects/kit/components/datatable/components/header/moz-datatable-header-cell.component.ts +17 -0
  14. package/projects/kit/components/datatable/index.ts +6 -0
  15. package/projects/kit/components/datatable/model/column-def.ts +5 -0
  16. package/projects/kit/components/datatable/model/datatable-settings.ts +11 -0
  17. package/projects/kit/components/datatable/model/footer-settings.ts +14 -0
  18. package/projects/kit/components/datatable/model/row-data.ts +3 -0
  19. package/projects/kit/components/datatable/moz-datatable.component.html +75 -0
  20. package/projects/kit/components/datatable/moz-datatable.component.scss +13 -0
  21. package/projects/kit/components/datatable/moz-datatable.component.spec.ts +123 -0
  22. package/projects/kit/components/datatable/moz-datatable.component.ts +97 -0
  23. package/projects/kit/components/datatable/moz-datatable.module.ts +44 -0
  24. package/projects/kit/components/datatable/moz-datatable.stories.ts +376 -0
  25. package/projects/kit/components/datatable/public-api.ts +6 -0
  26. package/projects/kit/components/icon/icon.component.spec.ts +4 -0
  27. package/projects/kit/components/pagination/pagination.component.html +2 -0
  28. package/projects/kit/components/pagination/pagination.component.ts +2 -1
  29. package/projects/kit/components/public-api.ts +1 -0
  30. package/projects/kit/components/tabs/tabs.component.ts +4 -2
  31. package/projects/kit/package.json +16 -3
  32. package/projects/kit/setup-jest.ts +1 -0
  33. package/projects/kit/tsconfig.spec.json +1 -1
  34. package/tsconfig.json +1 -0
  35. package/projects/kit/components/dialog/dialog.component.spec.ts +0 -24
  36. package/projects/kit/karma.conf.js +0 -41
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
 
2
2
 
3
+ # [0.23.0-beta.0](https://github.com/adeo/mozaic-angular/compare/0.22.0...0.23.0-beta.0) (2023-08-02)
4
+
5
+
6
+ ### Features
7
+
8
+ * **datatable:** WIP datatable ([5547619](https://github.com/adeo/mozaic-angular/commit/5547619d16eb96e28ed321549d40307cf4350869))
9
+
3
10
  # 0.22.0 (2023-06-28)
4
11
 
5
12
 
package/README.md CHANGED
@@ -58,9 +58,11 @@ This repository contains the following elements:
58
58
  To run the documentation locally, you can do the following:
59
59
 
60
60
  1. Clone this repository
61
- 2. Run `npm install` to install the **Node.js** dependencies, including Storybook
62
- 3. Run `npm run storybook` to launch **Storybook** and activate hot-reloads for development
63
- 4. Open [http://localhost:6006/](http://localhost:6006/) in your browser and start explore! :rocket:
61
+ 2. install node v16.x.x
62
+ 3. Run `npm install` to install the **Node.js** dependencies, including Storybook
63
+ 4. Run `npm run build` to build the application
64
+ 5. Run `npm run storybook` to launch **Storybook** and activate hot-reloads for development
65
+ 6. Open [http://localhost:6006/](http://localhost:6006/) in your browser and start explore! :rocket:
64
66
 
65
67
  ### Bugs and feature requests
66
68
 
package/angular.json CHANGED
@@ -60,14 +60,6 @@
60
60
  },
61
61
  "defaultConfiguration": "production"
62
62
  },
63
- "test": {
64
- "builder": "@angular-devkit/build-angular:karma",
65
- "options": {
66
- "main": "projects/kit/src/test.ts",
67
- "tsConfig": "projects/kit/tsconfig.spec.json",
68
- "karmaConfig": "projects/kit/karma.conf.js"
69
- }
70
- },
71
63
  "lint": {
72
64
  "builder": "@angular-eslint/builder:lint",
73
65
  "options": {
@@ -108,6 +100,7 @@
108
100
  },
109
101
  "defaultProject": "kit",
110
102
  "cli": {
111
- "defaultCollection": "@angular-eslint/schematics"
103
+ "defaultCollection": "@angular-eslint/schematics",
104
+ "analytics": false
112
105
  }
113
106
  }
package/jest.config.js ADDED
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ preset: 'jest-preset-angular',
3
+ rootDir: 'projects/kit',
4
+ setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
5
+ reporters: ['default'],
6
+ };
package/package.json CHANGED
@@ -1,8 +1,21 @@
1
1
  {
2
2
  "name": "@mozaic-ds/angular",
3
- "version": "0.22.0",
3
+ "version": "0.23.0-beta.0",
4
4
  "description": "Mozaic-angular is the AngularJS Mozaic DS implementation",
5
5
  "license": "MIT",
6
+ "exports": {
7
+ ".": {
8
+ "sass": "./_index.scss"
9
+ },
10
+ "./adeo": {
11
+ "types": "./adeo/index.d.ts",
12
+ "esm2020": "./adeo/esm2020/mozaic-ds-angular.mjs",
13
+ "es2020": "./adeo/fesm2020/mozaic-ds-angular.mjs",
14
+ "es2015": "./adeo/fesm2015/mozaic-ds-angular.mjs",
15
+ "node": "./adeo/fesm2015/mozaic-ds-angular.mjs",
16
+ "default": "./adeo/fesm2020/mozaic-ds-angular.mjs"
17
+ }
18
+ },
6
19
  "repository": {
7
20
  "type": "git",
8
21
  "url": "https://github.com/adeo/mozaic-angular.git"
@@ -10,13 +23,13 @@
10
23
  "scripts": {
11
24
  "ng": "ng",
12
25
  "start": "ng run kit:storybook",
13
- "build": "MOZAIC_PRESET='' npm run copy-icons && ng build && npm run remove-icons",
14
- "build:adeo": "MOZAIC_PRESET=adeo ng run kit:build-adeo",
15
- "create-icons-folder": "mkdir -p projects/kit/assets/moz-icons",
16
- "copy-icons": "npm run create-icons-folder && cp node_modules/@mozaic-ds/icons/svg/** projects/kit/assets/moz-icons && cp node_modules/@mozaic-ds/icons/svg-color/** projects/kit/assets/moz-icons",
17
- "remove-icons": "rm -rf projects/kit/assets/moz-icons",
26
+ "build": "cross-env MOZAIC_PRESET='' npm run copy-icons && ng build && npm run remove-icons",
27
+ "build:adeo": "cross-env MOZAIC_PRESET=adeo ng run kit:build-adeo",
28
+ "copy-icons": "npm run create-icons-folder && shx cp -R node_modules/@mozaic-ds/icons/svg/** projects/kit/assets/moz-icons && shx cp -R node_modules/@mozaic-ds/icons/svg-color/** projects/kit/assets/moz-icons",
29
+ "remove-icons": "shx rm -rf projects/kit/assets/moz-icons",
30
+ "create-icons-folder": "shx mkdir -p projects/kit/assets/moz-icons",
18
31
  "watch": "ng build --watch --configuration development",
19
- "test": "ng test",
32
+ "test": "jest",
20
33
  "prepare": "husky install",
21
34
  "pre-commit": "lint-staged",
22
35
  "lint": "ng lint",
@@ -25,7 +38,6 @@
25
38
  "build:storybook": "ng run kit:build-storybook",
26
39
  "release": "release-it",
27
40
  "release:beta": "release-it --preRelease=beta",
28
- "prepublishOnly": "npm run build && npm run build:adeo ",
29
41
  "npm:publish": "npm publish --access public",
30
42
  "npm:publishBeta": "npm publish --tag beta --access public",
31
43
  "tokens:build": "mozaic-tokens-build"
@@ -48,7 +60,7 @@
48
60
  "@mozaic-ds/web-fonts": "^1.22.0",
49
61
  "rxjs": "~7.8.0",
50
62
  "tslib": "^2.5.0",
51
- "zone.js": "~0.11.8"
63
+ "zone.js": "^0.13.1"
52
64
  },
53
65
  "devDependencies": {
54
66
  "@angular-eslint/builder": "15.2.0",
@@ -56,25 +68,26 @@
56
68
  "@angular-eslint/eslint-plugin-template": "15.2.0",
57
69
  "@angular-eslint/schematics": "15.2.0",
58
70
  "@angular-eslint/template-parser": "15.2.0",
59
- "@angular/cli": "~15.1.4",
71
+ "@angular/cli": "^15.2.9",
60
72
  "@angular/compiler-cli": "~15.2.9",
61
73
  "@angular/elements": "^15.2.9",
62
74
  "@babel/core": "^7.20.12",
63
75
  "@compodoc/compodoc": "^1.1.19",
64
- "@release-it/conventional-changelog": "^5.1.1",
76
+ "@release-it/conventional-changelog": "^7.0.0",
65
77
  "@storybook/addon-actions": "^7.0.18",
66
78
  "@storybook/addon-essentials": "^7.0.18",
67
79
  "@storybook/addon-links": "^7.0.18",
68
80
  "@storybook/addon-styling": "^1.3.0",
69
81
  "@storybook/angular": "^7.0.18",
70
82
  "@storybook/cli": "7.1.0-alpha.32",
71
- "@types/jasmine": "~4.3.1",
83
+ "@types/jest": "^29.5.2",
72
84
  "@types/node": "^18.13.0",
73
85
  "@typescript-eslint/eslint-plugin": "5.51.0",
74
86
  "@typescript-eslint/parser": "5.51.0",
75
87
  "@webcomponents/custom-elements": "^1.5.1",
76
88
  "babel-loader": "^9.1.2",
77
89
  "copyfiles": "^2.4.1",
90
+ "cross-env": "^7.0.3",
78
91
  "css-loader": "^6.8.1",
79
92
  "eslint": "^8.33.0",
80
93
  "eslint-config-airbnb-base": "^15.0.0",
@@ -84,12 +97,8 @@
84
97
  "eslint-plugin-rxjs": "^5.0.2",
85
98
  "eslint-plugin-storybook": "^0.6.12",
86
99
  "husky": "^8.0.3",
87
- "jasmine-core": "~4.5.0",
88
- "karma": "~6.4.1",
89
- "karma-chrome-launcher": "~3.1.1",
90
- "karma-coverage": "~2.2.0",
91
- "karma-jasmine": "~5.1.0",
92
- "karma-jasmine-html-reporter": "~2.0.0",
100
+ "jest": "^29.6.0",
101
+ "jest-preset-angular": "^13.1.1",
93
102
  "lint-staged": "^13.1.1",
94
103
  "ng-packagr": "^15.1.1",
95
104
  "postcss": "^8.3.6",
@@ -98,10 +107,12 @@
98
107
  "prettier": "^2.8.3",
99
108
  "react": "^18.2.0",
100
109
  "react-dom": "^18.2.0",
101
- "release-it": "^15.11.0",
110
+ "release-it": "^16.1.3",
102
111
  "sass": "^1.63.4",
103
112
  "sass-loader": "^13.3.2",
113
+ "shx": "^0.3.4",
104
114
  "storybook": "^7.0.18",
115
+ "ts-jest": "^29.1.1",
105
116
  "typescript": "~4.9.5"
106
117
  }
107
118
  }
@@ -0,0 +1,13 @@
1
+ <div class="mc-datatable__header">
2
+ <div class="mc-datatable__topbar">
3
+ <div class="mc-datatable__topbar-edition">
4
+ <ng-content select="[edition]"></ng-content>
5
+ </div>
6
+ <div class="mc-datatable__topbar-actions">
7
+ <ng-content select="[actions]"></ng-content>
8
+ </div>
9
+ </div>
10
+ <div class="mc-datatable__filters" #parentRef *ngIf="showParent">
11
+ <ng-content select="[filters]"></ng-content>
12
+ </div>
13
+ </div>
@@ -0,0 +1,31 @@
1
+ import {
2
+ AfterViewInit,
3
+ ChangeDetectionStrategy,
4
+ ChangeDetectorRef,
5
+ Component,
6
+ ElementRef,
7
+ ViewChild,
8
+ } from '@angular/core';
9
+
10
+ @Component({
11
+ selector: 'moz-datatable-caption',
12
+ templateUrl: './moz-datatable-caption.component.html',
13
+ changeDetection: ChangeDetectionStrategy.OnPush,
14
+ })
15
+ export class MozDatatableCaptionComponent implements AfterViewInit {
16
+ @ViewChild('parentRef') parentRef?: ElementRef;
17
+
18
+ showParent: boolean = true;
19
+
20
+ constructor(private cdRef: ChangeDetectorRef) {}
21
+
22
+ ngAfterViewInit() {
23
+ if (
24
+ this.parentRef?.nativeElement.children &&
25
+ this.parentRef?.nativeElement.children.length === 0
26
+ ) {
27
+ this.showParent = false;
28
+ }
29
+ this.cdRef.detectChanges();
30
+ }
31
+ }
@@ -0,0 +1,17 @@
1
+ import {
2
+ ChangeDetectionStrategy,
3
+ Component,
4
+ ContentChild,
5
+ Input,
6
+ TemplateRef,
7
+ } from '@angular/core';
8
+
9
+ @Component({
10
+ selector: 'moz-datatable-content-cell',
11
+ templateUrl: './moz-datatable-content-cell.component.html',
12
+ changeDetection: ChangeDetectionStrategy.OnPush,
13
+ })
14
+ export class MozDatatableContentCellComponent {
15
+ @Input() public field?: string;
16
+ @ContentChild(TemplateRef) public templateRef!: TemplateRef<unknown>;
17
+ }
@@ -0,0 +1,34 @@
1
+ <div class="mc-datatable__footer">
2
+ <div class="mc-datatable__select">
3
+ <label for="selectRows" class="mc-datatable__select-label">{{
4
+ footerSettings?.labels?.rowPerPage || 'Rows per page'
5
+ }}</label>
6
+ <select
7
+ moz-select
8
+ [(ngModel)]="selectedRowPerPage"
9
+ (change)="rowPerPageChangeEmitter.emit(selectedRowPerPage)"
10
+ >
11
+ <option
12
+ *ngFor="let value of footerSettings?.pagination?.rowPerPage?.options"
13
+ [ngValue]="value"
14
+ >
15
+ {{ value }}
16
+ </option>
17
+ </select>
18
+ </div>
19
+ <div class="mc-datatable__count">
20
+ <strong>{{ calculateCountStart() }}-{{ calculateCountEnd() }}</strong> /
21
+ <strong
22
+ >{{ footerSettings?.pagination?.totalItems }}
23
+ {{ footerSettings?.labels?.items || 'Items' }}</strong
24
+ >
25
+ </div>
26
+ <div class="mc-datatable__pagination">
27
+ <moz-pagination
28
+ [numberOfPages]="calculateNumberOfPage()"
29
+ [(ngModel)]="currentPage"
30
+ (ngModelChange)="pageChangeEmitter.emit(currentPage)"
31
+ >
32
+ </moz-pagination>
33
+ </div>
34
+ </div>
@@ -0,0 +1,46 @@
1
+ import {
2
+ ChangeDetectionStrategy,
3
+ Component,
4
+ EventEmitter,
5
+ Input,
6
+ OnInit,
7
+ Output,
8
+ } from '@angular/core';
9
+ import { FooterSettings } from '../../model/footer-settings';
10
+
11
+ @Component({
12
+ selector: 'moz-datatable-footer',
13
+ templateUrl: './moz-datatable-footer.component.html',
14
+ changeDetection: ChangeDetectionStrategy.OnPush,
15
+ })
16
+ export class MozDatatableFooterComponent implements OnInit {
17
+ @Input() public footerSettings?: FooterSettings;
18
+ @Output() public rowPerPageChangeEmitter = new EventEmitter<number>();
19
+ @Output() public pageChangeEmitter = new EventEmitter<number>();
20
+
21
+ public selectedRowPerPage?: number;
22
+ public currentPage?: number;
23
+
24
+ ngOnInit(): void {
25
+ this.selectedRowPerPage = this.footerSettings?.pagination.rowPerPage.selected;
26
+ this.currentPage = this.footerSettings?.pagination.currentPage;
27
+ }
28
+
29
+ public calculateNumberOfPage(): number {
30
+ return Math.round(
31
+ (this.footerSettings?.pagination?.totalItems || 0) / (this.selectedRowPerPage || 0)
32
+ );
33
+ }
34
+
35
+ public calculateCountEnd(): number {
36
+ const count = (this.selectedRowPerPage || 0) * (this.currentPage || 0);
37
+ if (count > (this.footerSettings?.pagination.totalItems || 0)) {
38
+ return this.footerSettings?.pagination.totalItems || 0;
39
+ }
40
+ return count;
41
+ }
42
+
43
+ public calculateCountStart(): number {
44
+ return this.calculateCountEnd() - ((this.selectedRowPerPage || 0) - 1);
45
+ }
46
+ }
@@ -0,0 +1,17 @@
1
+ import {
2
+ ChangeDetectionStrategy,
3
+ Component,
4
+ ContentChild,
5
+ Input,
6
+ TemplateRef,
7
+ } from '@angular/core';
8
+
9
+ @Component({
10
+ selector: 'moz-datatable-header-cell',
11
+ templateUrl: './moz-datatable-header-cell.component.html',
12
+ changeDetection: ChangeDetectionStrategy.OnPush,
13
+ })
14
+ export class MozDatatableHeaderCellComponent {
15
+ @Input() public field?: string;
16
+ @ContentChild(TemplateRef) public templateRef!: TemplateRef<unknown>;
17
+ }
@@ -0,0 +1,6 @@
1
+ export * from './moz-datatable.component';
2
+ export * from './components/header/moz-datatable-header-cell.component';
3
+ export * from './components/footer/moz-datatable-footer.component';
4
+ export * from './components/content/moz-datatable-content-cell.component';
5
+ export * from './components/caption/moz-datatable-caption.component';
6
+ export * from './moz-datatable.module';
@@ -0,0 +1,5 @@
1
+ export interface ColumnDef {
2
+ field: string;
3
+ headerName: string;
4
+ sort?: string;
5
+ }
@@ -0,0 +1,11 @@
1
+ import { ColumnDef } from './column-def';
2
+ import { RowData } from './row-data';
3
+
4
+ export interface DatatableSettings {
5
+ activatePagination?: boolean;
6
+ activateCaption?: boolean;
7
+ columnDefs: ColumnDef[];
8
+ rowData: RowData[];
9
+ fixHeaderRow?: boolean;
10
+ datatableMaxHeight?: string;
11
+ }
@@ -0,0 +1,14 @@
1
+ export interface FooterSettings {
2
+ pagination: {
3
+ totalItems: number;
4
+ itemsPerPage: number;
5
+ currentPage: number;
6
+ rowPerPage: { options: number[]; selected: number };
7
+ };
8
+ labels: {
9
+ rowPerPage?: string;
10
+ items?: string;
11
+ page?: string;
12
+ of?: string;
13
+ };
14
+ }
@@ -0,0 +1,3 @@
1
+ export interface RowData {
2
+ [key: string]: Object;
3
+ }
@@ -0,0 +1,75 @@
1
+ <div class="mc-datatable">
2
+ <ng-content select="moz-datatable-caption"></ng-content>
3
+
4
+ <div class="mc-datatable__container">
5
+ <div
6
+ class="mc-datatable__main"
7
+ [ngStyle]="{
8
+ 'max-height': datatableSettings?.fixHeaderRow && datatableSettings?.datatableMaxHeight
9
+ }"
10
+ >
11
+ <table class="mc-datatable__table">
12
+ <thead [ngClass]="{ 'fix-header-row': datatableSettings?.fixHeaderRow }">
13
+ <tr>
14
+ <th *ngFor="let columnDef of datatableSettings?.columnDefs" class="moz-datatable__th">
15
+ <ng-container
16
+ *ngIf="getCustomHeader(columnDef.field) as customHeader; else defaultHeaderCell"
17
+ >
18
+ <ng-container
19
+ *ngTemplateOutlet="
20
+ customHeader;
21
+ context: {
22
+ $implicit: {
23
+ content: columnDef
24
+ }
25
+ }
26
+ "
27
+ ></ng-container>
28
+ </ng-container>
29
+ <ng-template #defaultHeaderCell>
30
+ {{ columnDef.headerName | uppercase }}
31
+ </ng-template>
32
+ </th>
33
+ </tr>
34
+ </thead>
35
+ <tbody>
36
+ <tr
37
+ *ngFor="let row of datatableSettings?.rowData; index as i"
38
+ class="mc-datatable__row-parent"
39
+ (click)="rowClickEvent(row)"
40
+ >
41
+ <td *ngFor="let columnDef of datatableSettings?.columnDefs">
42
+ <ng-container
43
+ *ngIf="getCustomContent(columnDef.field) as customContent; else defaultContentCell"
44
+ >
45
+ <ng-container
46
+ *ngTemplateOutlet="
47
+ customContent;
48
+ context: {
49
+ $implicit: {
50
+ row: row,
51
+ index: i,
52
+ columnDefs: datatableSettings?.columnDefs,
53
+ content: row[columnDef.field]
54
+ }
55
+ }
56
+ "
57
+ ></ng-container>
58
+ </ng-container>
59
+ <ng-template #defaultContentCell>
60
+ {{ row[columnDef.field] }}
61
+ </ng-template>
62
+ </td>
63
+ </tr>
64
+ </tbody>
65
+ </table>
66
+ </div>
67
+ </div>
68
+
69
+ <moz-datatable-footer
70
+ *ngIf="datatableSettings?.activatePagination"
71
+ [footerSettings]="footerSettings"
72
+ (rowPerPageChangeEmitter)="rowPerPageChangeEvent($event)"
73
+ (pageChangeEmitter)="pageChangeEvent($event)"
74
+ ></moz-datatable-footer>
75
+ </div>
@@ -0,0 +1,13 @@
1
+ @import 'settings-tools/all-settings';
2
+ @import '_c.datatable'; // mandatory
3
+ @import '_c.datatable-tools'; // mandatory
4
+ @import '_c.datatable-header'; // optional - import when using the DataTable with a header
5
+ @import '_c.datatable-footer'; // optional - import when using the DataTable with a footer
6
+ @import '_c.datatable-subtable'; // optional - import when using the Expanded DataTable
7
+
8
+ .fix-header-row {
9
+ position: sticky;
10
+ top: 0;
11
+ z-index: 3;
12
+ box-shadow: 0px 1px 5px 0px rgba(34, 32, 32, 0.2);
13
+ }
@@ -0,0 +1,123 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+ import { MozDatatableComponent } from './moz-datatable.component';
3
+ import { MozDatatableContentCellComponent } from './components/content/moz-datatable-content-cell.component';
4
+ import { MozDatatableFooterComponent } from './components/footer/moz-datatable-footer.component';
5
+ import { MozDatatableCaptionComponent } from './components/caption/moz-datatable-caption.component';
6
+ import { MozDatatableHeaderCellComponent } from './components/header/moz-datatable-header-cell.component';
7
+ import { QueryList, TemplateRef } from '@angular/core';
8
+
9
+ describe('MozDatatableComponent', () => {
10
+ let component: MozDatatableComponent;
11
+ let fixture: ComponentFixture<MozDatatableComponent>;
12
+
13
+ beforeEach(async () => {
14
+ await TestBed.configureTestingModule({
15
+ declarations: [
16
+ MozDatatableComponent,
17
+ MozDatatableContentCellComponent,
18
+ MozDatatableFooterComponent,
19
+ MozDatatableCaptionComponent,
20
+ MozDatatableHeaderCellComponent,
21
+ ],
22
+ }).compileComponents();
23
+ });
24
+
25
+ beforeEach(() => {
26
+ fixture = TestBed.createComponent(MozDatatableComponent);
27
+ component = fixture.componentInstance;
28
+ fixture.detectChanges();
29
+ });
30
+
31
+ it('should create the MozDatatableComponent', () => {
32
+ expect(component).toBeTruthy();
33
+ });
34
+
35
+ it('should build custom header cells map on ngAfterContentInit', () => {
36
+ const headerCell1 = new MozDatatableHeaderCellComponent();
37
+ headerCell1.field = 'field1';
38
+ headerCell1.templateRef = {} as TemplateRef<any>;
39
+ const headerCell2 = new MozDatatableHeaderCellComponent();
40
+ headerCell2.field = 'field2';
41
+ headerCell2.templateRef = {} as TemplateRef<any>;
42
+
43
+ component.headerCellComponents = new QueryList<MozDatatableHeaderCellComponent>();
44
+ component.headerCellComponents.reset([headerCell1, headerCell2]);
45
+
46
+ component.ngAfterContentInit();
47
+
48
+ expect(component.customHeaderCellsMap.get('field1')).toBe(headerCell1.templateRef);
49
+ expect(component.customHeaderCellsMap.get('field2')).toBe(headerCell2.templateRef);
50
+ });
51
+
52
+ it('should build custom content cells map on ngAfterContentInit', () => {
53
+ const contentCell1 = new MozDatatableContentCellComponent();
54
+ contentCell1.field = 'field1';
55
+ contentCell1.templateRef = {} as TemplateRef<any>;
56
+ const contentCell2 = new MozDatatableContentCellComponent();
57
+ contentCell2.field = 'field2';
58
+ contentCell2.templateRef = {} as TemplateRef<any>;
59
+
60
+ component.contentCellComponents = new QueryList<MozDatatableContentCellComponent>();
61
+ component.contentCellComponents.reset([contentCell1, contentCell2]);
62
+
63
+ component.ngAfterContentInit();
64
+
65
+ expect(component.customContentCellsMap.get('field1')).toBe(contentCell1.templateRef);
66
+ expect(component.customContentCellsMap.get('field2')).toBe(contentCell2.templateRef);
67
+ });
68
+
69
+ it('should return custom header templateRef', () => {
70
+ const headerCell = new MozDatatableHeaderCellComponent();
71
+ headerCell.field = 'field1';
72
+ headerCell.templateRef = {} as TemplateRef<any>;
73
+ component.customHeaderCellsMap.set('field1', headerCell.templateRef);
74
+
75
+ const result = component.getCustomHeader('field1');
76
+
77
+ expect(result).toBe(headerCell.templateRef);
78
+ });
79
+
80
+ it('should return custom content templateRef', () => {
81
+ const contentCell = new MozDatatableContentCellComponent();
82
+ contentCell.field = 'field1';
83
+ contentCell.templateRef = {} as TemplateRef<any>;
84
+ component.customContentCellsMap.set('field1', contentCell.templateRef);
85
+
86
+ const result = component.getCustomContent('field1');
87
+
88
+ expect(result).toBe(contentCell.templateRef);
89
+ });
90
+
91
+ it('should emit rowClicked event onRowClick', () => {
92
+ const rowData = [
93
+ {
94
+ productName: 'Perceuse-visseuse à Percussion',
95
+ productId: '#123456789',
96
+ discount: 0,
97
+ status: { label: 'Waiting for approval', type: 'warning' },
98
+ productLink: { label: 'Page link', link: '#' },
99
+ },
100
+ ];
101
+ jest.spyOn(component.rowClicked, 'emit');
102
+ component.rowClickEvent(rowData[0]);
103
+ expect(component.rowClicked.emit).toHaveBeenCalledWith(rowData[0]);
104
+ });
105
+
106
+ it('should build custom header cells map', () => {
107
+ const headerCell1 = new MozDatatableHeaderCellComponent();
108
+ headerCell1.field = 'field1';
109
+ headerCell1.templateRef = {} as TemplateRef<any>;
110
+ const headerCell2 = new MozDatatableHeaderCellComponent();
111
+ headerCell2.field = 'field2';
112
+ headerCell2.templateRef = {} as TemplateRef<any>;
113
+
114
+ component.headerCellComponents = new QueryList<MozDatatableHeaderCellComponent>();
115
+ component.headerCellComponents.reset([headerCell1, headerCell2]);
116
+
117
+ component.buildCustomHeaderMap();
118
+
119
+ expect(component.customHeaderCellsMap.size).toBe(2);
120
+ expect(component.customHeaderCellsMap.get('field1')).toBe(headerCell1.templateRef);
121
+ expect(component.customHeaderCellsMap.get('field2')).toBe(headerCell2.templateRef);
122
+ });
123
+ });