(
openDialog: () => Promise<ComponentFixture<ComponentWithChildViewContainer>>,
)
| 1919 | }); |
| 1920 | |
| 1921 | function runContentElementTests( |
| 1922 | openDialog: () => Promise<ComponentFixture<ComponentWithChildViewContainer>>, |
| 1923 | ) { |
| 1924 | it('should close the dialog when clicking on the close button', async () => { |
| 1925 | const fixture = await openDialog(); |
| 1926 | expect(overlayContainerElement.querySelectorAll('.mat-mdc-dialog-container').length).toBe( |
| 1927 | 1, |
| 1928 | ); |
| 1929 | |
| 1930 | (overlayContainerElement.querySelector('button[mat-dialog-close]') as HTMLElement).click(); |
| 1931 | fixture.detectChanges(); |
| 1932 | await fixture.whenStable(); |
| 1933 | |
| 1934 | expect(overlayContainerElement.querySelectorAll('.mat-mdc-dialog-container').length).toBe( |
| 1935 | 0, |
| 1936 | ); |
| 1937 | }); |
| 1938 | |
| 1939 | it('should not close when clicking on an aria-disabled close button', async () => { |
| 1940 | const fixture = await openDialog(); |
| 1941 | expect(overlayContainerElement.querySelectorAll('.mat-mdc-dialog-container').length).toBe( |
| 1942 | 1, |
| 1943 | ); |
| 1944 | |
| 1945 | const closeButton = overlayContainerElement.querySelector( |
| 1946 | 'button[mat-dialog-close]', |
| 1947 | ) as HTMLElement; |
| 1948 | |
| 1949 | closeButton.setAttribute('aria-disabled', 'true'); |
| 1950 | closeButton.click(); |
| 1951 | fixture.detectChanges(); |
| 1952 | await fixture.whenStable(); |
| 1953 | |
| 1954 | expect(overlayContainerElement.querySelectorAll('.mat-mdc-dialog-container').length).toBe( |
| 1955 | 1, |
| 1956 | ); |
| 1957 | }); |
| 1958 | |
| 1959 | it('should not close if [mat-dialog-close] is applied on a non-button node', async () => { |
| 1960 | await openDialog(); |
| 1961 | expect(overlayContainerElement.querySelectorAll('.mat-mdc-dialog-container').length).toBe( |
| 1962 | 1, |
| 1963 | ); |
| 1964 | |
| 1965 | (overlayContainerElement.querySelector('div[mat-dialog-close]') as HTMLElement).click(); |
| 1966 | |
| 1967 | expect(overlayContainerElement.querySelectorAll('.mat-mdc-dialog-container').length).toBe( |
| 1968 | 1, |
| 1969 | ); |
| 1970 | }); |
| 1971 | |
| 1972 | it('should allow for a user-specified aria-label on the close button', async () => { |
| 1973 | await openDialog(); |
| 1974 | let button = overlayContainerElement.querySelector('.close-with-aria-label')!; |
| 1975 | expect(button.getAttribute('aria-label')).toBe('Best close button ever'); |
| 1976 | }); |
| 1977 | |
| 1978 | it('should set the "type" attribute of the close button if not set manually', async () => { |
no test coverage detected