Skip to content

Instantly share code, notes, and snippets.

Avatar

Rainer Hahnekamp rainerhahnekamp

View GitHub Profile
View data.guard.ts
@Injectable({
providedIn: 'root',
})
export class DataGuard implements CanActivate {
constructor(private store: Store<CustomerAppState>) {}
canActivate(): Observable<boolean> {
this.store.dispatch(CustomerActions.get());
return this.store
.select(fromCustomer.isLoaded)
View reducer.ts
export interface State {
customers: Customer[];
}
const initialState = {
customers: []
}
View reducer.ts
export interface State {
loadStatus: 'NOT_LOADED' | 'LOADING' | 'LOADED';
customers: Customer[];
}
const initialState = {
loadStatus: 'NOT_LOADED',
customers: []
}
View customer.effects.ts
@Injectable()
export class CustomerEffects {
private baseUrl = 'https://local.eternal.com/api/customer';
constructor(
private actions$: Actions,
private http: HttpClient,
private router: Router
) {}
loadCustomers$ = createEffect(() =>
View customer.reducer.ts
export const customerFeatureKey = 'Customer';
export interface State {customers: Customer[]}
export interface CustomerAppState {
[customerFeatureKey]: State;
}
export const initialState: State = {customers: []};
View customer.ts
export interface Customer {
id: number;
firstname: string;
name: string;
country: string;
birthdate: string;
}
View message.spec.ts
it('should fail', () => {
let isSuccessful = false;
cy.visit('');
cy.get('button').click();
cy.get('div.message').then(() => {
isSuccessful = true;
});
if (!isSuccessful) {
throw new Error('something is not working');
View customers.spec.ts
it('should click on add customers', () => {
cy.visit('')
.then(() => cy.get('[data-test=btn-customers]'))
.then((button) => button.click())
.then(() => cy.get('[data-test=btn-customers-add]'))
.then((button) => button.click());
});
it('should click on add customers', async () => {
await cy.visit('');
View customers.spec.ts
it("should click on add customers", () => {
cy.visit("");
cy.get("[data-test=btn-customers]").click();
cy.get("[data-test=btn-customers-add]").click();
})
View sidemenu.html
<a data-test="btn-customers" mat-raised-button routerLink="/customer">Customers</a>
<a [routerLink]="['.', 'new']" color="primary" data-test="btn-customers-add" mat-raised-button>Add Customer</a>