@axinom/mosaic-ui 0.44.0-rc.0 → 0.44.0-rc.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axinom/mosaic-ui",
3
- "version": "0.44.0-rc.0",
3
+ "version": "0.44.0-rc.2",
4
4
  "description": "UI components for building Axinom Mosaic applications",
5
5
  "author": "Axinom",
6
6
  "license": "PROPRIETARY",
@@ -32,7 +32,7 @@
32
32
  "build-storybook": "storybook build"
33
33
  },
34
34
  "dependencies": {
35
- "@axinom/mosaic-core": "^0.4.17-rc.0",
35
+ "@axinom/mosaic-core": "^0.4.17-rc.2",
36
36
  "@faker-js/faker": "^7.4.0",
37
37
  "@popperjs/core": "^2.11.8",
38
38
  "clsx": "^1.1.0",
@@ -105,5 +105,5 @@
105
105
  "publishConfig": {
106
106
  "access": "public"
107
107
  },
108
- "gitHead": "c53cc8faf7c63180e79abff852c4eae456cd8da6"
108
+ "gitHead": "dcf763ea92712ac3e3c7056fbad9cfc603bf7246"
109
109
  }
@@ -1,8 +1,8 @@
1
1
  import { mount, shallow } from 'enzyme';
2
2
  import React from 'react';
3
3
  import { MessageBar } from '../MessageBar';
4
- import { StationError } from '../models';
5
4
  import { PageHeader } from '../PageHeader';
5
+ import { StationError } from '../models';
6
6
  import { EmptyStation, EmptyStationProps } from './EmptyStation';
7
7
 
8
8
  describe('EmptyStation', () => {
@@ -6,6 +6,8 @@ import { PageHeaderAction } from './PageHeaderAction/PageHeaderAction';
6
6
  import { PageHeaderActionProps } from './PageHeaderAction/PageHeaderAction.model';
7
7
  import { PageHeaderBulkActions } from './PageHeaderBulkActions/PageHeaderBulkActions';
8
8
 
9
+ jest.mock('../../hooks/useTabTitle/useTabTitle');
10
+
9
11
  const defaultbulkActions: PageHeaderActionProps[] = [
10
12
  {
11
13
  label: 'Bulk Action 1',
@@ -1,9 +1,12 @@
1
1
  import { mount } from 'enzyme';
2
2
  import React from 'react';
3
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
+ import { useHistory } from 'react-router-dom';
3
5
  import { setTitle } from '../../initialize';
4
6
  import { useTabTitle } from './useTabTitle';
5
7
 
6
8
  jest.mock('../../initialize');
9
+ jest.mock('react-router-dom');
7
10
 
8
11
  const TestWrapper: React.FC<{ title?: string; setTabTitle: boolean }> = ({
9
12
  title,
@@ -16,19 +19,32 @@ const TestWrapper: React.FC<{ title?: string; setTabTitle: boolean }> = ({
16
19
 
17
20
  describe('useTabTitle', () => {
18
21
  beforeEach(() => {
19
- jest.resetAllMocks();
22
+ jest.clearAllMocks();
23
+ (useHistory as jest.Mock) = jest.fn().mockReturnValue({
24
+ location: {
25
+ pathname: '/test',
26
+ },
27
+ });
20
28
  });
21
29
 
22
- it('should set the title when setTabTitle is true', () => {
23
- const title = 'Test Title';
30
+ it('should set the tab title when setTabTitle is true', () => {
31
+ const firstTitle = 'First Title';
32
+ const secondTitle = 'Second Title';
33
+
24
34
  const setTabTitle = true;
25
35
 
26
- mount(<TestWrapper title={title} setTabTitle={setTabTitle} />);
36
+ const wrapper = mount(
37
+ <TestWrapper title={firstTitle} setTabTitle={setTabTitle} />,
38
+ );
27
39
 
28
- expect(setTitle).toHaveBeenCalledWith('Test Title');
40
+ expect(setTitle).toHaveBeenCalledWith(firstTitle);
41
+
42
+ wrapper.setProps({ title: secondTitle });
43
+
44
+ expect(setTitle).toHaveBeenNthCalledWith(2, secondTitle);
29
45
  });
30
46
 
31
- it('should not set the title when setTabTitle is false', () => {
47
+ it('should not set the tab title when setTabTitle is false', () => {
32
48
  const title = 'Test Title';
33
49
  const setTabTitle = false;
34
50
 
@@ -36,4 +52,44 @@ describe('useTabTitle', () => {
36
52
 
37
53
  expect(setTitle).not.toHaveBeenCalled();
38
54
  });
55
+
56
+ it('should not set the tab title when the URL has changed', () => {
57
+ (useHistory as jest.Mock) = jest
58
+ .fn()
59
+ .mockReturnValueOnce({
60
+ location: {
61
+ pathname: '/test',
62
+ },
63
+ })
64
+ .mockReturnValueOnce({
65
+ location: {
66
+ pathname: '/test2',
67
+ },
68
+ });
69
+
70
+ const firstTitle = 'First Title';
71
+ const secondTitle = 'Second Title';
72
+ const setTabTitle = true;
73
+
74
+ const wrapper = mount(
75
+ <TestWrapper title={firstTitle} setTabTitle={setTabTitle} />,
76
+ );
77
+
78
+ expect(setTitle).toHaveBeenCalledWith(firstTitle);
79
+
80
+ wrapper.setProps({ title: secondTitle });
81
+
82
+ expect(setTitle).toHaveBeenCalledTimes(1);
83
+ });
84
+
85
+ it('should set the tab title outside a react router context', () => {
86
+ (useHistory as jest.Mock) = jest.fn().mockReturnValue(undefined);
87
+
88
+ const title = 'Test Title';
89
+ const setTabTitle = true;
90
+
91
+ mount(<TestWrapper title={title} setTabTitle={setTabTitle} />);
92
+
93
+ expect(setTitle).toHaveBeenCalled();
94
+ });
39
95
  });
@@ -1,13 +1,16 @@
1
- import { useEffect } from 'react';
1
+ import { useState } from 'react';
2
+ import { useHistory } from 'react-router-dom';
2
3
  import { setTitle } from '../../initialize';
3
4
 
4
5
  export const useTabTitle = (
5
6
  title: string | undefined,
6
7
  setTabTitle: boolean | undefined,
7
8
  ): void => {
8
- useEffect(() => {
9
- if (setTabTitle) {
10
- setTitle(title);
11
- }
12
- }, [setTabTitle, title]);
9
+ // useTabTitle should work outside a react router context
10
+ const { location } = useHistory() ?? {};
11
+ const [initialLocation] = useState(location);
12
+
13
+ if (setTabTitle && location?.pathname === initialLocation?.pathname) {
14
+ setTitle(title);
15
+ }
13
16
  };