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

Add At and Browser Association #712

Merged
merged 3 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 30 additions & 65 deletions server/apps/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@ app.set('views', resolve(handlebarsPath, 'views'));
// stale data for however long it takes for the query to complete.
const millisecondsUntilStale = 5000;

// TODO: Provide through resolvers
const validAtBrowserCombinations = {
JAWS: new Set(['Firefox', 'Chrome']),
NVDA: new Set(['Firefox', 'Chrome']),
'VoiceOver for macOS': new Set(['Firefox', 'Chrome', 'Safari'])
};

const queryReports = async () => {
const { data, errors } = await apolloServer.executeOperation({
query: gql`
query {
testPlanReports(statuses: [DRAFT, CANDIDATE, RECOMMENDED]) {
ats {
id
name
browsers {
id
name
}
}
testPlanReports(statuses: [CANDIDATE, RECOMMENDED]) {
id
metrics
status
Expand Down Expand Up @@ -85,7 +86,11 @@ const queryReports = async () => {

const reportsHashed = hash(data.testPlanReports);

return { allTestPlanReports: data.testPlanReports, reportsHashed };
return {
allTestPlanReports: data.testPlanReports,
reportsHashed,
ats: data.ats
};
};

// As of now, a full query for the complete list of reports is needed to build
Expand All @@ -99,10 +104,7 @@ const getLatestReportsForPattern = ({ allTestPlanReports, pattern }) => {
let title;

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

// This function gets all the AT + Browser Combinations which have been added to the Test Queue at
// some point; this means if the combination has never been added, a valid combination will be
// marked as 'Not Applicable' rather than 'Data Not Yet Available'.
/*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;
};*/

// TODO: Provide through resolvers
// Check if the applicable ATs reported for the tests found for a report link to an already known
// reference of which ATs match against which browsers
const getAllAtBrowserCombinations = reports => {
const combinations = {};
const loggedAtIds = [];

const report = reports[0];
report.testPlanVersion.tests.forEach(test => {
const atIds = test.ats.map(at => at.id);

if (!loggedAtIds.includes(1) && atIds.includes('1')) {
combinations[Object.keys(validAtBrowserCombinations)[0]] =
Object.values(validAtBrowserCombinations)[0];
loggedAtIds.push(1);
}

if (!loggedAtIds.includes(2) && atIds.includes('2')) {
combinations[Object.keys(validAtBrowserCombinations)[1]] =
Object.values(validAtBrowserCombinations)[1];
loggedAtIds.push(2);
}

if (!loggedAtIds.includes(3) && atIds.includes('3')) {
combinations[Object.keys(validAtBrowserCombinations)[2]] =
Object.values(validAtBrowserCombinations)[2];
loggedAtIds.push(3);
}
});

return combinations;
};

const renderEmbed = ({
ats,
allTestPlanReports,
queryTitle,
pattern,
Expand All @@ -261,8 +215,17 @@ const renderEmbed = ({
status,
reportsByAt
} = getLatestReportsForPattern({ pattern, allTestPlanReports });
const allAtBrowserCombinations =
getAllAtBrowserCombinations(allTestPlanReports);
const allAtBrowserCombinations = Object.fromEntries(
ats.map(at => {
return [
at.name,
at.browsers.map(browser => {
return browser.name;
})
];
})
);

return hbs.renderView(resolve(handlebarsPath, 'views/main.hbs'), {
layout: 'index',
dataEmpty: Object.keys(reportsByAt).length === 0,
Expand Down Expand Up @@ -298,8 +261,10 @@ app.get('/reports/:pattern', async (req, res) => {
const protocol = /dev|vagrant/.test(process.env.ENVIRONMENT)
? 'http://'
: 'https://';
const { allTestPlanReports, reportsHashed } = await queryReportsCached();
const { allTestPlanReports, reportsHashed, ats } =
await queryReportsCached();
const embedRendered = await renderEmbedCached({
ats,
allTestPlanReports,
reportsHashed,
queryTitle,
Expand Down
8 changes: 8 additions & 0 deletions server/graphql-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ const graphqlSchema = gql`
A fully-qualified version like "99.0.4844.84"
"""
browserVersions: [BrowserVersion]!
"""
The Ats which can be run with the specific browser, for example, Jaws can be run with Chrome but not Safari, and Safari works with VoiceOver only.
"""
ats: [At]!
}

"""
Expand Down Expand Up @@ -145,6 +149,10 @@ const graphqlSchema = gql`
# """
# modes: [AtMode]!
atVersions: [AtVersion]!
"""
The browsers which can run the At, for example, Safari can run VoiceOver but not Jaws because Jaws is Windows only.
"""
browsers: [Browser]!
}

"""
Expand Down
2 changes: 1 addition & 1 deletion server/handlebars/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
return object.allAtVersionsByAt[key].name;
},
combinationExists: function (object, atName, browserName) {
if (object.allAtBrowserCombinations[atName].has(browserName)) {
if (object.allAtBrowserCombinations[atName].includes(browserName)) {
return true;
}
return false;
Expand Down
29 changes: 29 additions & 0 deletions server/migrations/20230724205435-addAtBrowser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('AtBrowsers', {
atId: {
type: Sequelize.DataTypes.INTEGER,
allowNull: false,
references: {
model: 'At',
key: 'id'
}
},
browserId: {
type: Sequelize.DataTypes.INTEGER,
allowNull: false,
references: {
model: 'Browser',
key: 'id'
}
}
});
},

down: async (queryInterface /* , Sequelize */) => {
await queryInterface.dropTable('AtBrowsers');
}
};
8 changes: 7 additions & 1 deletion server/models/At.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function (sequelize, DataTypes) {
);

Model.AT_VERSION_ASSOCIATION = { as: 'atVersions' };

Model.BROWSERS_ASSOCIATION = { through: 'AtBrowsers', as: 'browsers' };
Model.AT_MODE_ASSOCIATION = { as: 'modes' };

Model.associate = function (models) {
Expand All @@ -32,6 +32,12 @@ module.exports = function (sequelize, DataTypes) {
sourceKey: 'id'
});

Model.belongsToMany(models.Browser, {
...Model.BROWSERS_ASSOCIATION,
foreignKey: 'atId',
otherKey: 'browserId'
});

Model.hasMany(models.AtMode, {
...Model.AT_MODE_ASSOCIATION,
foreignKey: 'atId',
Expand Down
29 changes: 29 additions & 0 deletions server/models/AtBrowsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const MODEL_NAME = 'AtBrowsers';

module.exports = function (sequelize, DataTypes) {
return sequelize.define(
MODEL_NAME,
{
atId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'At',
key: 'id'
}
},
browserId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'Browser',
key: 'id'
}
}
},
{
timestamps: false,
tableName: MODEL_NAME
}
);
};
11 changes: 11 additions & 0 deletions server/models/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,23 @@ module.exports = function (sequelize, DataTypes) {

Model.BROWSER_VERSION_ASSOCIATION = { as: 'browserVersions' };

Model.ATS_ASSOCIATION = {
through: 'AtBrowsers',
as: 'ats'
};

Model.associate = function (models) {
Model.hasMany(models.BrowserVersion, {
...Model.BROWSER_VERSION_ASSOCIATION,
foreignKey: 'browserId',
sourceKey: 'id'
});

Model.belongsToMany(models.At, {
...Model.ATS_ASSOCIATION,
foreignKey: 'browserId',
otherKey: 'atId'
});
};

return Model;
Expand Down
Loading