Skip to content

Commit

Permalink
test(samples/headless-ssr): move existing components under app/ssr (#…
Browse files Browse the repository at this point in the history
…3114)

* Move existing cmps under app/ssr

https://coveord.atlassian.net/browse/KIT-2683

* add a empty page for / route

to fix ci error

https://coveord.atlassian.net/browse/KIT-2683

* rename ssr route to generic

https://coveord.atlassian.net/browse/KIT-2683
  • Loading branch information
mrrajamanickam-coveo authored Aug 17, 2023
1 parent 59964f9 commit 01a4681
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
15 changes: 8 additions & 7 deletions packages/samples/headless-ssr/cypress/e2e/ssr.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import 'cypress-web-vitals';
import {ConsoleAliases, spyOnConsole, waitForHydration} from './ssr-e2e-utils';

describe('headless ssr example', () => {
const route = '/generic';
const numResults = 10;
const numResultsMsg = `Rendered page with ${numResults} results`;
const msgSelector = '#hydrated-msg';
const timestampSelector = '#timestamp';
it('renders page in SSR as expected', () => {
cy.intercept('/', (req) => {
cy.intercept(route, (req) => {
req.continue((resp) => {
const dom = new DOMParser().parseFromString(resp.body, 'text/html');
expect(dom.querySelector(msgSelector)?.textContent).to.equal(
Expand All @@ -16,20 +17,20 @@ describe('headless ssr example', () => {
expect(dom.querySelectorAll('li').length).to.equal(numResults);
});
});
cy.visit('/');
cy.visit(route);
});

it('renders page in CSR as expected', () => {
cy.visit('/');
cy.visit(route);
cy.get(msgSelector).should('have.text', numResultsMsg);
cy.get('li').should('have.length', numResults);
});

it('renders result list in SSR and then in CSR', () => {
const interceptAlias = 'searchResults';
cy.intercept('/').as(interceptAlias);
cy.intercept(route).as(interceptAlias);

cy.visit('/');
cy.visit(route);
cy.wait(`@${interceptAlias}`).then((intercept) => {
const dom = new DOMParser().parseFromString(
intercept.response?.body,
Expand All @@ -52,13 +53,13 @@ describe('headless ssr example', () => {
const VITALS_THRESHOLD = {
thresholds: {fcp: 100, lcp: 100, cls: 0, ttfb: 20},
};
cy.visit('/');
cy.visit(route);
cy.vitals(VITALS_THRESHOLD);
});

it('should not log any error nor warning', () => {
spyOnConsole();
cy.visit('/');
cy.visit(route);
waitForHydration();
cy.wait(1000);
cy.get(ConsoleAliases.error).should('not.be.called');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
SearchSSRState,
SearchCSRState,
hydrateInitialState,
} from '@/src/common/engine';
} from '@/src/app/generic/common/engine';
import {useEffect, useState} from 'react';
import {HydrationMetadata} from './hydration-metadata';
import {ResultList} from './result-list';
Expand Down
8 changes: 8 additions & 0 deletions packages/samples/headless-ssr/src/app/generic/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {fetchInitialState} from '@/src/app/generic/common/engine';
import SearchPage from '@/src/app/generic/components/search-page';

// Entry point SSR function
export default async function Search() {
const ssrState = await fetchInitialState();
return <SearchPage ssrState={ssrState}></SearchPage>;
}
9 changes: 1 addition & 8 deletions packages/samples/headless-ssr/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
import {fetchInitialState} from '@/src/common/engine';
import SearchPage from '@/src/components/search-page';

// Entry point SSR function
export default async function Search() {
const ssrState = await fetchInitialState();
return <SearchPage ssrState={ssrState}></SearchPage>;
}
export default function Home() {}

0 comments on commit 01a4681

Please sign in to comment.