Skip to content

Commit

Permalink
Support for copy changes for no data (#583)
Browse files Browse the repository at this point in the history
* initial support for copy changes for no data

* Adding tests
  • Loading branch information
evmiguel authored May 18, 2023
1 parent 7ef74ef commit 330d76a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
23 changes: 21 additions & 2 deletions server/apps/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const queryReports = async () => {
const { data, errors } = await apolloServer.executeOperation({
query: gql`
query {
testPlanReports(statuses: [CANDIDATE, RECOMMENDED]) {
testPlanReports(statuses: [DRAFT, CANDIDATE, RECOMMENDED]) {
id
metrics
status
Expand Down Expand Up @@ -86,7 +86,10 @@ const getLatestReportsForPattern = ({ allTestPlanReports, pattern }) => {
let title;

const testPlanReports = allTestPlanReports.filter(report => {
if (report.testPlanVersion.testPlan.id === pattern) {
if (
report.testPlanVersion.testPlan.id === pattern &&
report.status !== 'DRAFT'
) {
title = report.testPlanVersion.title;
return true;
}
Expand Down Expand Up @@ -181,6 +184,19 @@ const getLatestReportsForPattern = ({ allTestPlanReports, pattern }) => {
};
};

const getAllAtBrowserCombinations = reports => {
const combinations = {};

reports.forEach(report => {
if (!(report.at.name in combinations)) {
combinations[report.at.name] = new Set();
}
combinations[report.at.name].add(report.browser.name);
});

return combinations;
};

const renderEmbed = ({
allTestPlanReports,
queryTitle,
Expand All @@ -196,9 +212,12 @@ const renderEmbed = ({
status,
reportsByAt
} = getLatestReportsForPattern({ pattern, allTestPlanReports });
const allAtBrowserCombinations =
getAllAtBrowserCombinations(allTestPlanReports);
return hbs.renderView(resolve(handlebarsPath, 'views/main.hbs'), {
layout: 'index',
dataEmpty: Object.keys(reportsByAt).length === 0,
allAtBrowserCombinations,
title: queryTitle || title || 'Pattern Not Found',
pattern,
status,
Expand Down
6 changes: 6 additions & 0 deletions server/handlebars/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ module.exports = {
getAtVersion: function (object, key) {
return object.allAtVersionsByAt[key].name;
},
combinationExists: function (object, atName, browserName) {
if (object.allAtBrowserCombinations[atName].has(browserName)) {
return true;
}
return false;
},
elementExists: function (parentObject, childObject, at, key, last) {
const atBrowsers = childObject.map(o => o.browser.name);

Expand Down
18 changes: 15 additions & 3 deletions server/handlebars/views/main.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@
{{else}}
{{#if (isInAllBrowsers "Chrome" @../../this) }}
{{#unless (elementExists @../../this @../this this.at.name "Chrome" @last)}}
<td><span class="no-data-cell">No Data</span></td>
{{#if (combinationExists @../../this this.at.name "Chrome")}}
<td><span class="no-data-cell">Data Not Yet Available</span></td>
{{else}}
<td><span class="no-data-cell">Not Applicable</span></td>
{{/if}}
{{/unless}}
{{/if}}
{{/if}}
Expand All @@ -75,7 +79,11 @@
{{else}}
{{#if (isInAllBrowsers "Firefox" @../../this) }}
{{#unless (elementExists @../../this @../this this.at.name "Firefox" @last)}}
<td><span class="no-data-cell">No Data</span></td>
{{#if (combinationExists @../../this this.at.name "Firefox")}}
<td><span class="no-data-cell">Data Not Yet Available</span></td>
{{else}}
<td><span class="no-data-cell">Not Applicable</span></td>
{{/if}}
{{/unless}}
{{/if}}
{{/if}}
Expand All @@ -91,7 +99,11 @@
{{else}}
{{#if (isInAllBrowsers "Safari" @../../this) }}
{{#unless (elementExists @../../this @../this this.at.name "Safari" @last)}}
<td><span class="no-data-cell">No Data</span></td>
{{#if (combinationExists @../../this this.at.name "Safari")}}
<td><span class="no-data-cell">Data Not Yet Available</span></td>
{{else}}
<td><span class="no-data-cell">Not Applicable</span></td>
{{/if}}
{{/unless}}
{{/if}}
{{/if}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ INSERT INTO "TestPlanReport" (id, "status", "testPlanVersionId", "createdAt", "a
INSERT INTO "TestPlanReport" (id, "status", "testPlanVersionId", "createdAt", "atId", "browserId", "candidateStatusReachedAt", "recommendedStatusReachedAt", "vendorReviewStatus") VALUES (4, 'CANDIDATE', get_test_plan_version_id(text 'Modal Dialog Example'), '2021-05-14 14:18:23.602-05', 2, 1, '2022-07-06', '2023-01-02', 'READY');
INSERT INTO "TestPlanReport" (id, "status", "testPlanVersionId", "createdAt", "atId", "browserId", "candidateStatusReachedAt", "recommendedStatusReachedAt", "vendorReviewStatus") VALUES (5, 'CANDIDATE', get_test_plan_version_id(text 'Modal Dialog Example'), '2021-05-14 14:18:23.602-05', 3, 3, '2022-07-06', '2023-01-02', 'READY');
INSERT INTO "TestPlanReport" (id, "status", "testPlanVersionId", "createdAt", "atId", "browserId", "candidateStatusReachedAt", "recommendedStatusReachedAt", "vendorReviewStatus") VALUES (6, 'CANDIDATE', get_test_plan_version_id(text 'Checkbox Example (Mixed-State)'), '2021-05-14 14:18:23.602-05', 3, 3, '2022-07-06', '2023-01-02', 'READY');
INSERT INTO "TestPlanReport" (id, "status", "testPlanVersionId", "createdAt", "atId", "browserId") VALUES (7, 'DRAFT', get_test_plan_version_id(text 'Alert Example'), '2021-05-14 14:18:23.602-05', 3, 1);

--
-- Data for Name: User; Type: TABLE DATA; Schema: public; Owner: atr
Expand Down
7 changes: 7 additions & 0 deletions server/tests/integration/embed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ describe('embed', () => {

const nonWarning = screen.queryByText('Recommended Report');
const warning = screen.queryByText('Warning! Unapproved Report');
const unsupportedAtBrowserCombination =
screen.getAllByText('Not Applicable');
const futureSupportedAtBrowserCombination = screen.getAllByText(
'Data Not Yet Available'
);
const nonWarningContents = screen.queryByText(
'The information in this report is generated from candidate tests',
{ exact: false }
Expand All @@ -65,6 +70,8 @@ describe('embed', () => {
expect(initialLoadTime / 10).toBeGreaterThan(cachedTime);
expect(nonWarning || warning).toBeTruthy();
expect(nonWarningContents || warningContents).toBeTruthy();
expect(unsupportedAtBrowserCombination).toBeTruthy();
expect(futureSupportedAtBrowserCombination).toBeTruthy();
expect(viewReportButton).toBeTruthy();
expect(viewReportButtonOnClick).toMatch(
// Onclick should be like the following:
Expand Down

0 comments on commit 330d76a

Please sign in to comment.