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

feat(components/core): add SkyMediaQueryController to interact with breakpoints in tests #2802

Merged
merged 107 commits into from
Oct 24, 2024

Conversation

Blackbaud-SteveBrush
Copy link
Member

@Blackbaud-SteveBrush Blackbaud-SteveBrush commented Oct 4, 2024

AB#2195494

Overview of API

Testing

Consumers can add the following to their tests to interact with breakpoints:

import { provideSkyMediaQueryTesting } from '@skyux/core/testing';

TestBed.configureTestingModule({
  providers: [provideSkyMediaQueryTesting()]
});

const mediaQueryController = TestBed.inject(SkyMediaQueryTestingController);

mediaQueryController.setBreakpoint('xs');
await mediaQueryController.expectBreakpoint('xs');

Creating responsive hosts

Consumers can apply a container breakpoint observer to an element in their template like this:

<div #responsiveHost="skyResponsiveHost" skyResponsiveHost>
  <p>Breakpoint within container: {{ responsiveHost.breakpointChange | async }}</p>
</div>

Or on their component's host element:

@Component({
  hostDirectives: [SkyResponsiveHostDirective],
  standalone: true,
  styles: `
    :host {
      display: block;
    }
  `,
  template: ` <p>Breakpoint within container: {{ breakpoint() }}</p> `,
})
export class DemoComponent {
  protected breakpoint = toSignal(
    inject(SkyMediaQueryService).breakpointChange,
  );
}

For embedded views, the responsive host can pass its injector:

<div #responsiveHost="skyResponsiveHost" skyResponsiveHost>
  <ng-container
    [ngTemplateOutlet]="myTemplate"
    [ngTemplateOutletInjector]="responsiveHost.injector"
</div>

Copy link

nx-cloud bot commented Oct 4, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 30d040a. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

@Blackbaud-SteveBrush Blackbaud-SteveBrush added the risk level (author): 1 No additional bugs expected from this change label Oct 4, 2024
@Blackbaud-ErikaMcVey Blackbaud-ErikaMcVey marked this pull request as draft October 7, 2024 17:09
@Blackbaud-SteveBrush Blackbaud-SteveBrush merged commit fa54b87 into main Oct 24, 2024
113 checks passed
@Blackbaud-SteveBrush Blackbaud-SteveBrush deleted the media-query-testing-controller branch October 24, 2024 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
risk level (author): 4 This change has a high chance of introducing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants